Fully Transparent Java Objects in Nashorn

Nashorn's JSAdapter is a powerful tool for handling Java objects in JavaScript with full transparency. It can be used to wrap Java objects and add new properties and behaviour. For example: var Date = Java.type('java.time.LocalDate') function wrapDate(d) {     return new JSAdapter() {         __get__: function(name) {             if (name === 'yesterday') {                 return d.minusDays(1)             }             return d[name]         }     } } var now = wrapDate(Date.now()) When...

Thursday, November 5, 2015 | Read More

Flexible JSON with Nashorn Parser API (JDK9)

[Posted by Sundar]  I recently came across Hjson - "the Human JSON - A configuration file format that caters to humans and helps reduce the errors they make". See also: http://hjson.org. I wanted to see if I can use Nashorn Parser API (jdk9) to support similar flexible JSON extension with Nashorn. In the following FlexiJSON.parse implementation, Nashorn Parser API is used to validate that the extendable flexi JSON is "data only" (That is, no executable code) andthen 'eval'uated...

Monday, April 20, 2015 | Personal | Read More

JavaScript Stored Procedures and Node.js Applications with Oracle Database 12c

This is a reposting of an article written by Kuassi Mensah JavaScript Stored Procedures and Node.js Applications with Oracle Database 12c Introduction Node.js and server-side JavaScript are hot and trendy; per the latest “RedMonk Programming Languages Rankings”[1], JavaScript and Java are the top two programming languages. For most developers building modern Web, mobile, and cloud based applications, the ability to use the same language across all tiers (client, middle, and...

Tuesday, February 10, 2015 | Personal | Read More

Using Nashorn with IntelliJ

Hi!  The Nashorn repository already contains a Netbeans project, so that you can seamlessly work with Netbeans as your IDE when using Nashorn. There are some tricks, for example, the IDE needs to build and access the pre-generated Nasgen classes that represent the builtin JavaScript objects: Array, Date, Number, String etc. These are part of the build step, and are generated if you just execute "ant clean jar" from the command line. Nashorn, furthermore, is now a jimage in Java...

Friday, January 9, 2015 | Personal | Read More

Nashorn Architecture and Performance Improvements in the Upcoming JDK 8u40 Release

Hello everyone! We've been bad at blogging here for a while. Apologies for that. I thought it would be prudent to talk a little bit about OpenJDK 8u40 which is now code frozen, and what enhancements we have made for Nashorn. 8u40 includes a total rewrite of the Nashorn code generator, which now contains the optimistic type system. JavaScript, or any dynamic language for that matter, doesn't provide enough compile time information to easily generate performant code. This is why,...

Friday, December 12, 2014 | Personal | Read More

Porting from the Browser to Nashorn/JavaFX (Part I)

During the JavaOne Nashorn: JavaScript for the JVM session, I showed a couple examples of converting JavaScript browser examples to use Nashorn and JavaFX. The first example was using CKEditor, a rich text/HTML editor. This editor is written entirely in JavaScript using the browser DOM interface. In this case, it did not really make sense to convert all the DOM code over to FX. Instead, I used the JavaFX WebView which supports all the DOM needed. So let's start with a simple...

Friday, October 24, 2014 | Personal | Read More

Popularity of Nashorn

I know it's unseemly to toot one's own horn, but after the release I did a Topsy to see how we were faring. I did some deeper analysis of the tweets and determined that about a quarter of the Nashorn tweets were about zoos and tanks.  The exceptions were when Nashorn crossed above JDK8/Java8.  The first peak was when people started tweeting about the Nashorn release video.  The second was when Benjamin Winterberg announced his tutorial (40.7K hits to date.) I've also been...

Thursday, May 8, 2014 | Personal | Read More

Documents and Articles on Nashorn

I've decided to move this entry to the main Nashorn wiki site to allow for "living document" additions.  Nashorn: Articles, Documents, Slides and Videos

Tuesday, May 6, 2014 | Personal | Read More

Latest news from the Nashorn team

Things have been busy on the Nashorn front, getting ready for the JDK 8 rollout and all.  March 18 is the magic day (EclipseCon.)  I see that JetBrains has added Nashorn debugging to IntelliJ. This rounds out the debugging story with support in NetBeans and Eclipse.  The Nashorn team has been working hard on performance improvements for the next round.  The first set involves caching of compiled scripts.  This will make a huge difference for reoccurring scripts (think...

Monday, March 17, 2014 | Personal | Read More

setInterval and setTimeout JavaScript Functions

With people porting HTML to Nashorn + JavaFX more frequently, I often get asked the question "how do you port functions like setInterval and setTimeout" (setInterval is used to have a function repeated at regular intervals, where setTimeout is used to have a function delayed.) The following code duplicates the functionality of the each of the setInterval family of functions, when used in a JavaFX application. var Platform = Java.type("javafx.application.Platform");var Timer ...

Thursday, September 26, 2013 | Personal | Read More

Nashorn + FX 350fps vs. Chrome 120fps

I was reading an article written by Felix Bembrick where he took a Chrome canvas example and ported it to Nashorn with JavaFX.  I ran the two tests myself and was surprised to see that Nashorn + FX ran at 350fps where Chrome ran at 120fps (iMac, 3.4 GHz Intel Core i7, AMD Radeon HD 6970M 2048M.)  Much of the credit for that is JavaFX's rendering engine, but Nashorn allowed Felix to leverage that.  The original article is at JavaFX with Nashorn Canvas example

Monday, September 9, 2013 | Personal | Read More

JavaOne: JavaScript Sessions

These are the sessions I found related to JavaScript.  There are likely others.  If you spot others, send a comment and I'll update this entry.  The session on the list is mine and the second is Attila's. Teaching the Java Platform with Nashorn is done with Ben Evans of the London JUG.  Come to the Script Bowl and vote for the only first time entry (Nashorn.) Nashorn: JavaScript on the JVM [CON7835] Monday, Sep 23, 11:30 AM - 12:30 PM - Hilton - Yosemite B/C Nashorn: Java and...

Wednesday, September 4, 2013 | Personal | Read More

JavaOne: What a Difference a Year Makes

I haven't been blogging for a while.  JavaOne examples and slides are taking up all my time.  Marcus and Attila leaked out that I was doing a demo of the Nashorn Debugger prototype, but I still have some surprises up my sleeve.  I was reviewing examples from last year and felt that they needed some updating.  The FX Fireworks example had all kinds of Java code to support applications, timers and callbacks.  This year's Fireworks version is pure Nashorn.  I posted source...

Wednesday, September 4, 2013 | Personal | Read More

Repost: A simple Real-time Web App built with Nashorn Scripting

Peter Hausel posted a new blog entry on Nashorn.  Cool example.  A simple Real-time Web App built with Nashorn Scripting

Thursday, August 8, 2013 | Personal | Read More

Nashorn Multithreading and MT-safety

Tobias Schlotte asked the question (via twitter @tobsch), "Where is thread-safety on your agenda for Nashorn?"  The quick answer is that multithreading is very high on the list, but MT-safety is a very complicated issue. I'll attempt to explain our plan of action. As Attila responded http://mail.openjdk.java.net/pipermail/nashorn-dev/2013-July/001567.html "ECMAScript 5.1 language specification doesn't define multithreading semantics for programs written in the language;...

Tuesday, July 9, 2013 | Personal | Read More

Nashorn and Lambda, What the Hey!

Yesterday, Brian Goetz (Lambda architect) suggested that I produce an example of Lambda being used from Nashorn.  Since, I've been heads down in Nashorn, I really haven't played with Lambda that much.  After looking at some examples from Stuart Marks,  I figured, what the hey, it doesn't look that hard.  Details of the Lambda APIs are available at JDK 8 b92 API . Many constructs are familiar to JavaScript developers.  The main things to note; where you can use a Lambda you can...

Wednesday, June 19, 2013 | Personal | Read More

Repost: Taming the Nashorn (first impressions)...

[This is a repost of an article written by our friend @hansolo_ with his permission.  The original article is at  Taming the Nashorn (first impressions)...] Hi there, JavaScript is everywhere these days and so it is also part of JDK8 dev. prev. with Project Nashorn which is a lightweight high-performance JavaScript runtime engine. Because I never used Rhino (which is in principle the same just older and slower) I had no  idea how to use it and for what reason. After I met Marcus...

Wednesday, May 29, 2013 | Personal | Read More

jjs -fx

So after some playing around and working with the JavaFX folks, I think we have a proposal for jjs that works with JavaFX.  The -fx flag on jjs will bootstrap scripts using a javafx.application.Application.  Thus, writing JavaFX scripts in Nashorn is very easy. The basic command line is; jjs -fx fxscript.js You can mix and match other jjs options like -scripting and -- ; jjs -fx -scripting fxscript.js -- my script args The content of the script follows some of the examples...

Tuesday, May 7, 2013 | Personal | Read More

Playing ITunes from Nashorn

If you are on Mac OS X, it's possible to use Apple Script from Nashorn.  For example if you want to play a song in iTunes, the following script will do it; #!/usr/bin/jjs -scripting#var song = "Bring It On Home";$EXEC("/usr/bin/osascript", <<<EOD);tell application "iTunes"activateplay track "${song}" in playlist 1end tellEOD

Tuesday, May 7, 2013 | Personal | Read More

HTTP Server Written In Nashorn

This is just a little "thinking outside the box" example. Node.js is hot and anyone who has used it knows there is a ton of applications possible. Some of Node.js features remind me of a tool kit I had, when I worked for another server company prior to Oracle. All my development was remote and had to run on remote servers. I hate typing and ssh/console was my only way in. So, I decided that I would create a little HTTP server on the remote end, to proxy all my routine...

Tuesday, May 7, 2013 | Personal | Read More

Keynoting at JAX2013

I have the honor to be keynoting JAX 2013 on April 25. The Keynote is called "Project Nashorn - and why dynamic languages on the JVM really matter". Exciting enough, surely, but it's not just "dynamic languages on the JVM", as it says in the title, that are becoming more and more important - I will show that it's really "languages on the JVM" that matters too, the JVM has its future as a polyglot runtime regardless of paradigm. Also, we are going to look at Project Nashorn as...

Monday, April 8, 2013 | Personal | Read More

To Shell Or Not To Shell

I find myself facing a dilemma today. How should I use Java FX from Nashorn? So far, I have two approaches I could use, but each comes with some issues. Some background first. Java FX, even though ships with the JDK, is on a different build cycle and has dependencies on elements of the JDK. This arraignment limits Nashorn, which is part of the JDK, from actually having dependencies into Java FX. But, there is a dependency requirement to implement a Java FX application. Java FX...

Saturday, April 6, 2013 | Personal | Read More

Nashorn Events Coming Up

The team will be going to several events in the next few weeks. Attila will be at Devoxx UK next week,  starting with a JUG Hackday on Sunday March 24, 2013 and presentation titled "Project Nashorn In Java 8 - JavaScript As A First Class Language On The JVM" on Wednesday March 27, 2012. Jim (me) will be at EclipseCon 2013 for the Thursday March 28, 2013 keynote.

Wednesday, March 20, 2013 | Personal | Read More

ClojureScript REPL - If you build it, they will come!

Together with Attila Szegedi, also from the Java language team, I attended the very successful JFokus conference in Stockholm last week. I gave a talk about Nashorn and on implementing dynamic languages on the JVM in general. It seemed well received by the audience. We also bumped into Bodil Stokke, of Catnip fame, there. Normally, as a Clojure open source developer, you just don't walk into the Oracle office, but we invited her over anyway and told the infrastructure orcs to...

Tuesday, February 12, 2013 | Personal | Read More

CSI: Nashorn - Shell Scripting in JavaScript, WAT?

I was reading the article in The Register with the heading GNOME project picks JavaScript as sole app dev language, when I remembered that we haven't said much about shell scripting using Nashorn. This may seem sacrilegious to both JavaScripters and shell scripters, but think about it. The features that make JavaScript good for browser support are similar to what is needed for shell scripting. Plus you have access to all those Java libraries, and JavaFX, wink, wink, nudge,...

Friday, February 8, 2013 | Personal | Read More

Implementing Dynamic Languages on the JVM

java.lang.invoke.* and the invokedynamic bytecode have given us a powerful new toolbox with which to implement dynamic languages on the JVM. At Devoxx in Antwerp last November, I gave a talk about how to build dynamic languages in Java7+, using the JVM as the runtime. While the talk is not necessarily implementation specific, a large part of the talk covered the Nashorn project.  The fine folks at Devoxx now released my talk for free to the public, so if you are interested in...

Wednesday, January 16, 2013 | Personal | Read More

Open For Business

After a lot of blood, sweat and tears, we finally got Nashorn into OpenJDK. hg fclone http://hg.openjdk.java.net/nashorn/jdk8 nashorn~jdk8 or for just Nashorn hg clone http://hg.openjdk.java.net/nashorn/jdk8/nashorn nashorn  More details about the tools you'll need and using OpenJDK are at  http://openjdk.java.net/guide/index.html This is just the first drop and needs some larger integration work, but you can browse the source, build and play.  Be sure to read the README and...

Friday, December 21, 2012 | Personal | Read More

The Vote Is In

Just got the following e-mail.  Gonna be busy next week. Voting on the Nashorn Project with initial Lead Jim Laskey [1] is closed. Yes:  20 Veto:  0 Abstain:  0 According to the Bylaws definition of Lazy Consensus, this is sufficient to approve the new Project and its initial Lead. -John Coomes [1] http://mail.openjdk.java.net/pipermail/announce/2012-November/000139.html

Saturday, December 8, 2012 | Personal | Read More

Nashorn in the Twitterverse, Continued

After doing the Twitter example, it seemed reasonable to try graphing the result with JavaFX.  At this time the Nashorn project doesn't have a JavaFX shell, so we have to go through some hoops to create an JavaFX application.  I thought showing you some of those hoops might give you some idea about what you can do mixing Nashorn and Java (we'll add a JavaFX shell to the todo list.) First, let's look at the meat of the application.  Here is the repackaged version of the...

Saturday, December 1, 2012 | Personal | Read More

Nashorn in the Twitterverse

I have been following how often Nashorn has been showing up on the net.  Nashorn got a burst of tweets when we announced Project Nashorn and I was curious how Nashorn was trending per day, maybe graph the result.  Counting tweets manually seemed mindless, so why not write a program to do the same. This is where Nashorn + Java came shining through.  There is a very nice Java library out there called Twitter4J https://github.com/yusuke/twitter4j that handles all things Twitter.  ...

Thursday, November 29, 2012 | Personal | Read More

Request for Project Nashorn (Open Source)

The request went out to the OpenJDK community last Thursday (November 22, 2012) for Project Nashorn.  http://mail.openjdk.java.net/pipermail/announce/2012-November/000139.html The deadline for voting is midnight December 6, 2012 UTC. If all goes well, we hope to have all the bits in the OpenJDK in time for all to play with during the holiday period. Fingers crossed.

Monday, November 26, 2012 | Personal | Read More

Welcome To The Nashorn Blog

Welcome to all.  Time to break the ice and instantiate The Nashorn Blog.  I hope to contribute routinely, but we are very busy, at this point, preparing for the next development milestone and, of course, getting ready for open source. So, if there are long gaps between postings please forgive. We're just coming back from JavaOne and are stoked by the positive response to all the Nashorn sessions. It was great for the team to have the front and centre slide from Georges Saab...

Wednesday, October 10, 2012 | Personal | Read More