Nashorn
Learn about the Nashorn JavaScript engine.
Nashorn replaces Rhino as the default JavaScript engine for the Oracle JVM. Nashorn is much faster
since it uses the invokedynamic
feature of the JVM. It also includes a command line tool (jjs
).
jjs
JDK 8 includes the command line tool jjs for running JavaScript.
We can run JavaScript files from the command line (assuming we have Java 8’s bin in our PATH
) in the following manner:
$ jjs script.js
Try running jjs
in the terminal below:
This can be useful for running scripts. For example, let’s say we wanted to quickly find the sum of some numbers.
var data = [1, 3, 5, 7, 11]
var sum = data.reduce(function(x, y) {return x + y}, 0)
print(sum)
Try running the code above. Our first command in the terminal should be jjs
, followed by the code given. It should print out “27”.
var data = [1, 3, 5, 7, 11] var sum = data.reduce(function(x, y) {return x + y}, 0) print(sum)
Type exit()
to move out of the jjs command window. ...