Java tutorial
import static javax.script.ScriptContext.ENGINE_SCOPE; import static javax.script.ScriptContext.GLOBAL_SCOPE; import java.util.List; import javax.script.Bindings; import javax.script.ScriptContext; import javax.script.SimpleBindings; import javax.script.SimpleScriptContext; public class Main { public static void main(String[] args) { ScriptContext ctx = new SimpleScriptContext(); List<Integer> scopes = ctx.getScopes(); System.out.println("Supported Scopes: " + scopes); ctx.setAttribute("year", 2015, ENGINE_SCOPE); Bindings globalBindings = new SimpleBindings(); ctx.setBindings(globalBindings, GLOBAL_SCOPE); ctx.setAttribute("year", 2014, GLOBAL_SCOPE); ctx.setAttribute("name", "Jack", GLOBAL_SCOPE); String nameValue = (String) ctx.getAttribute("name"); System.out.println("nameValue = " + nameValue); int engineScopeYear = (Integer) ctx.getAttribute("year", ENGINE_SCOPE); int globalScopeYear = (Integer) ctx.getAttribute("year", GLOBAL_SCOPE); System.out.println("engineScopeYear = " + engineScopeYear); System.out.println("globalScopeYear = " + globalScopeYear); } }