SimpleScriptContext getAttribute() method in Java with Examples Last Updated : 29 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The getAttribute() method of a SimpleScriptContext class is used to return the value of the attribute with the given name as a parameter to the method.The searching the value via the attribute name is in the scope occurring earliest in the search order. Syntax: public Object getAttribute(String name) Parameters: This method accepts a single parameter name which is the name of the attribute to retrieve. Return value: This method returns the value of the attribute in the lowest scope for which an attribute with the given name is defined and returns null if no attribute with the name exists in any scope. Exceptions: This method throws following Exceptions: NullPointerException: if the name is null. IllegalArgumentException: if the name is empty. Below programs illustrate the SimpleScriptContext.getAttribute() method: Program 1: Java // Java program to demonstrate // SimpleScriptContext.getAttribute() method import javax.script.ScriptContext; import javax.script.SimpleScriptContext; public class GFG { public static void main(String[] args) { // create SimpleScriptContext object SimpleScriptContext simple = new SimpleScriptContext(); // add some attribute simple.setAttribute( "name", "Value", ScriptContext.ENGINE_SCOPE); // get value using getAttribute() Object value = simple.getAttribute("name"); // print System.out.println(value); } } Output: Value Program 2: Java // Java program to demonstrate // SimpleScriptContext.getAttribute() method import javax.script.ScriptContext; import javax.script.SimpleScriptContext; public class GFG { public static void main(String[] args) { // create SimpleScriptContext object SimpleScriptContext simple = new SimpleScriptContext(); // add some attribute simple.setAttribute( "Team1", "India", ScriptContext.ENGINE_SCOPE); simple.setAttribute( "Team2", "Japan", ScriptContext.ENGINE_SCOPE); simple.setAttribute( "Team3", "Nepal", ScriptContext.ENGINE_SCOPE); // get value using getAttribute() Object value1 = simple.getAttribute("Team1"); Object value2 = simple.getAttribute("Team2"); Object value3 = simple.getAttribute("Team3"); // print System.out.println(value1); System.out.println(value2); System.out.println(value3); } } Output: India Japan Nepal References: https://docs.oracle.com/javase/10/docs/api/javax/script/SimpleScriptContext.html#getAttribute(java.lang.String) Comment More infoAdvertise with us Next Article SimpleScriptContext getAttributesScope() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions javax.script package Java-SimpleScriptContext Practice Tags : Java Similar Reads SimpleScriptContext getAttributesScope() method in Java with Examples The getAttributesScope() method of a SimpleScriptContext class is used to return the scope in which an attribute is defined and the name of attribute is passed as parameter. Syntax: public int getAttributesScope(String name) Parameters: This method accepts a single parameter name which is the Name o 2 min read SimpleScriptContext getBindings() method in Java with Examples The getBindings() method of a SimpleScriptContext class is used to return the bindings associated with the given scope in this ScriptContext where scope is passed as parameter. Syntax: Bindings getBindings(int scope) Parameters: This method accepts a single parameter scope which is the scope in this 2 min read SimpleScriptContext setAttribute() method in Java with Examples 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_SCOP 2 min read SimpleScriptContext setBindings() method in Java with Examples The setBindings() method of a SimpleScriptContext class is used to set a Bindings of attributes for the given scope where Bindings and scope are passed as parameters to the method. If the scope is ENGINE_SCOPE the given Bindings replaces the engineScope field. If the scope is GLOBAL_SCOPE the given 2 min read SimpleScriptContext removeAttribute() method in Java with Examples The removeAttribute() method of a SimpleScriptContext class is used to remove an attribute in a given scope and the name of attribute and scope are passed as parameters. Syntax: public Object removeAttribute(String name, int scope) Parameters: This method accepts two parameters: name which is the Na 2 min read Package getAnnotationsByType() method in Java with Examples The getAnnotationsByType() method of java.lang.Package class is used to get the annotations of the specified annotation type present in this class. The method returns an array of annotations for the specified annotation type. Syntax: public A[] getAnnotationsByType(Class<T> annotationClass) Pa 2 min read Like