Set and Retrieve a Script Engine's State
A script engine has state that can be set by a Java program, accessed and manipulated by a script, and retrieved by the Java program. The program sets this state by invoking ScriptEngine's public void put(String key, Object value) method, where key typically identifies a scripting language variable and value provides the variable's value. Similarly, a Java program invokes ScriptEngine's public Object get(String key) method to retrieve the state value. Listing 3 describes an application that demonstrates these methods.
Listing 3: ScriptDemo3.java
ScriptDemo3 creates the following output:
ageAmount = 6000.0