The setAttribute() method of a SimpleScriptContext class is used to set the value of an attribute in a given scope where the name of the attribute, the value of attribute and scope of the attribute is passed as parameters. If the scope is GLOBAL_SCOPE and there are no Bindings is set for GLOBAL_SCOPE, then setAttribute call is a no-op.
public void setAttribute(String name, Object value, int scope)
Parameters: This method accepts three-parameters:
- name which is the Name of the attribute to set,
- value which is the value of the attribute and
- scope which is the scope in which to set the attribute.
Return value: This method returns nothing.
Exceptions: This method throws following Exceptions:
- NullPointerException: if the name is null.
- IllegalArgumentException: if the name is empty or if the scope is invalid.
Below programs illustrate the SimpleScriptContext.setAttribute() method:
Team1:India Team2:Japan Team3:Nepal
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.