Java tutorial
import javax.script.ScriptEngine; import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class Main { public static void main(String[] args) { // Get the script engine factory for Nashorn ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); ScriptEngineFactory factory = engine.getFactory(); // Get the script String script = factory.getOutputStatement("\"java2s\""); System.out.println("Syntax: " + script); // Evaluate the script try { engine.eval(script); } catch (ScriptException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }