Java tutorial
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; public class Main { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); String script = "var year = 2015"; engine.eval(script); Object year = engine.get("year"); System.out.println("year's class:" + year.getClass().getName()); System.out.println("year's value:" + year); } }