Java tutorial
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class Main { public static void main(String[] args) { // Create a script engine manager ScriptEngineManager manager = new ScriptEngineManager(); // Obtain a script engine from the manager ScriptEngine engine = manager.getEngineByName("JavaScript"); // Store the script in a String String script = "print('hi from java2s.com!')"; try { // Execute the script engine.eval(script); } catch (ScriptException e) { e.printStackTrace(); } } }