Java Reference
In-Depth Information
jjs > print ( obj );
jdk . nashorn . javaadapters . java . util . concurrent . Callable @ 290 dbf45
This means that the actual type of the JavaScript object implementing Callable is . This class is not
shipped with Nashorn, of course. Instead, Nashorn spins up dynamic bytecode to
implement whatever interface is required and just maintains the original name as
part of the package structure for readability.
Remember that dynamic code generation is an essential part
of Nashorn, and that all JavaScript code is compiled by Nas‐
horn in Java bytecode and never interpreted.
One final note is that Nashorn's insistence on 100% compliance with the spec does
sometimes restrict the capabilities of the implementation. For example, consider
printing out an object, like this:
jjs > var obj = { foo: "bar" , cat: 2 };
jjs > print ( obj );
[ object Object ]
The ECMAScript specification requires the output to be [object Object] —con‐
formant implementations are not allowed to give more useful detail (such as a com‐
plete list of the properties and values contained in obj ).
In this chapter, we've met Nashorn, the JavaScript implementation on top of the
JVM that ships with Oracle's Java 8. We've seen how to use it to execute scripts and
even replace bash and Perl scripts with enhanced JavaScript scripts that can leverage
the full power of Java and the JVM. We've met the JavaScript engine API and seen
how the bridge between Java and scripting languages is implemented.
We've seen the tight integration between JavaScript and Java that Nashorn provides,
and some of the small language syntax extensions that Nashorn provides to make
programming a little bit easier. Finally, we've had a brief peek under the hood at
how Nashorn implements all of this functionality. To conclude, let's take a quick
look into the future and meet Project Avatar, which could be the future of Java/Java‐
Script web applications.
Project Avatar
One of the most successful movements in the JavaScript community in recent years
has been Node.js. This is a simple server-side JavaScript implementation developed
by Ryan Dahl and now curated by Joyent. Node.js provides a programming model
that is heavily asynchronous—designed around callbacks, nonblocking I/O, and a
simple, single-threaded event loop model.
Search WWH ::

Custom Search