Invoking Javascript Functions from Java Without Parameters in Java 8


print('Demo 1');
package pmk.learnjava8withrealapps.nashorn;

import java.io.FileReader;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class Demo {

	public static void main(String[] args) {

		try {
			ScriptEngine se = new ScriptEngineManager()
					.getEngineByName("nashorn");

			se.eval("print('Hello JS');");

			se.eval(new FileReader("src\\pmk\\learnjava8withrealapps\\nashorn\\demo1.js"));

		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

	}

}




Hello JS
Demo 1