Arun Kumar
Arun Kumar

Reputation: 333

Nashorn vs Javascript vs ECMAScript

Java8 provides Next-Generation JavaScript Engine as nashorn. We can get this engine with following code:

ScriptEngineManager engineManager = new ScriptEngineManager(); 
ScriptEngine engine = engineManager.getEngineByName("nashorn");

But i found that javascript and ECMAScript are also valid parameters for getEngineByName()

ScriptEngine engine = engineManager.getEngineByName("javascript");
ScriptEngine engine = engineManager.getEngineByName("ECMAScript");

My queries are:

Upvotes: 3

Views: 2799

Answers (1)

Piotrek
Piotrek

Reputation: 79

Javascript and ECMAScript are aliases for default JavaScript engine bundled with JVM. Java 8+ includes Nashorn engine, previous versions were using Rhino engine ("rhino"). Nashorn is much faster than Rhino, because it is compiling JavaScript into bytecode, instead of running in interpreter mode.

The fastest solution I know of to run JavaScript within JVM is J2V8 (https://github.com/eclipsesource/J2V8). JavaScript code runs within the V8 engine, the same one as is used by Node.js and Chrome. In our tests, it's about 2-3 times faster than Nashorn.

Upvotes: 3

Related Questions