Javascript - Nashorn Engine


Nashorn is the JDK’s built-in JavaScript engine. Rhino was its predecessor.

Background: The development of Nashorn started in late 2010 to experiment with the invokedynamic (JSR 292) byte-code instruction.

Because JavaScript would likely grow to dominate client-side development, integrating it with Java would be a critical element in a client/server equation.

In November 2012, JDK Enhancement Proposal (JEP) 174, “Nashorn JavaScript Engine,” was approved for a full-featured implementation of ECMAScript-262 Edition 5.1 (ES5) to run on the Java platform.


Inside java

ScriptEngine engine = new ScriptEngineManager().
engine.eval("print('Hello World');");

Jjs Shell

See Javascript - jjs


Initially, Nashorn found a home in a wide variety of applications, such as:

  • app servers,
  • JavaFX applications,
  • utilities,
  • shell scripts,
  • embedded systems,
  • and so on.

Nashorn continues to have broad usage, but its use appears to have settled into three main areas:

  • The development of JavaScript applications that can be run on both the client and the server. In the JavaScript world, this is known as isomorphic development. The advantages are huge for smaller shops that want to build front ends for both desktop and mobile services—a single programming language with a common codebase and rapid delivery. Isomorphic development also scales well for larger systems.
  • Runtime adaptive or dynamic coding. The term I like to use is soft coding, where portions of an application can be modiied after the application/server is deployed. This capability is used for everything from stored procedures in databases to application coniguration management.
  • Shell scripting. This consists of using JavaScript in areas where bash or Python would traditionally be used.

Nashorn vs V8

Nashorn’s performance on the JVM compared to native JavaScript performance on platforms such as Google’s V8.

Nashorn starts out slower because it translates the JavaScript to bytecode. After that, Nashorn is at the mercy of HotSpot to deliver native code.

This approach works well for long-running server applications but not as well for small and run-once scripts. The main reason Nashorn was developed in the first place was to run JavaScript and Java together seamlessly. Most Nashorn applications do a great job of orchestrating JavaScript and Java, something that V8 was not designed to do.

Used by

Documentation / Reference

Discover More
Java Conceptuel Diagram
Java - Scripting

AspectJ BeanShell Ceylon Clojure Duby Fantom Groovy Ioke Jaskell JRuby Jython Noop Scala XTend Groovy en Scala are in Java 7 supported. Javascript: Rhino, ...
Javascript - (Interpreter|Engine|Runtime)

Javascript Interpreter (JavaScript_engineJavaScript engine) is a software which interprets and executes JavaScript code. Javascript can run in two different environment: within a browser or without...
Javascript - Asynchronous Module Definition (AMD)

The AMD specifies a mechanism for defining modules such that: the module and its dependencies can be specified and loaded asynchronously. ie Both the module and dependencies can be asynchronously...
Javascript - jjs

Shell for the nashorn engine Install Java Call it Play ...
Card Puncher Data Processing
WeBlog - Dynamic Java Code Execution

Running java code stored in a string variable created dynamically inside a java application (ie at runtime) isnot straightforward in Java. This article: discuss a business case. explains why it's...

Share this page:
Follow us:
Task Runner