SimpleScriptContext getAttribute() method in Java with Examples Last Updated : 29 Jan, 2020 Comments Improve Suggest changes 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) Create Quiz Comment A AmanSingh2210 Follow 0 Improve A AmanSingh2210 Follow 0 Improve Article Tags : Java Java-Functions javax.script package Java-SimpleScriptContext Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like