Java can now talk to JavaScript with the new np plugin!

Wow.. been a while since my last update. I’ve been toiling away writing gobs of new code for the new NP plugin. With the initial framework now in place, I am finally seeing results.

Java can now set members on JavaScript side! It may sound like a simple thing, but there is a lot of work needed to make it happen. String exchanges, object creation via jni-like reference handles and reflection, multi-threaded  handling, etc. And that is also why I consider this an important milestone. A lot of the aforementioned items comprise the base framework. The fact that JS members can now be controlled, proves the stability of that framework.

I have uploaded a small clip here that shows this in action (this is applet used). When the mouse moves over the applet, a listener uses liveconnect to modify the value of the “Desired Altitude” element on the right. Similarly, moving the slider updates the “Maximum Cost” element.

Click here to see the clip

Updates to the field seem a tad slow in the clip, but that is just due to recording limitations. Updates are synchronous on the end machine. All of the code needed to do the above is now in the upstream mercurial repository.

Next on my list is to do something similar for JS->Java calls, implement a few basic functions and such.


About dbhole

I have been a member of the Java Group at Red Hat since mid-2008. I started off as an engineer and in late 2012, I switched to the dark side, a.k.a management :) I now manage all the members in the Java Group and some members from the QE team dedicated to JDK/component related QE.
This entry was posted in IcedTea. Bookmark the permalink.

2 Responses to Java can now talk to JavaScript with the new np plugin!

  1. Micah J says:

    Stupid question but is there any reason the Java VM couldn’t be used to run the JavaScript directly and connect to the Applet more directly? I’ve been wondering now that the Java VM is open source why it couldn’t be used as the basis for a unified cross browser scripting VM.

    • dbhole says:

      Java and JavaScript are very different. LiveConnect plugins only serve as a bridge from the Java engine (VM) to the JavaScript engine (which is part of the browser, and browser specific). Running JavaScript in a Java VM while possible via external engines like Rhino, would offer no significant advantage over running it in the browser engine. In fact, it will probably incur as a higher penalty as a vm would have to keep running even if the page has no applets.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s