Melding the worlds of Java and JavaScript, JavaPoly.js extends native Java Virtual Machine support to browsers via a library serving as a polyfill.

JavaPoly.js enables developers to import existing Java code and invoke it from JavaScript. "It finally allows Java to become a first-class citizen by running directly in the browser's script tags (and interacting directly with the DOM), instead of being confined to an applet sandbox," according to the project's Web page. The user does not need to have Java installed on their computer.

Doppio, providing a JVM written in TypeScript, serves as the default JVM for JavaPoly.js. "JavaPoly can interface with several JVM implementations, including a system JVM, but it always falls back to Doppio if no other JVM implementations can be found," Sproch said. "Doppio is the underlying technology that allows JavaPoly to run on any system, even if the user doesn't have Java installed."

In theory, JavaPoly.js would enable a host of JVM languages to be supported in the browser, including Groovy and Scala, project developer Jim Sproch said. "Any language [that] runs in the JVM should be able to run using JavaPoly," he said. "In fact, you could even run Python using Jython. This project will likely spawn several other projects to support all the various languages." Sproch further acknowledged that the project is largely about enabling Web development in Java.

JavaPoly.js developers currently are building native JVM plugins for Chrome and Firefox. "Our hope is to standardize the API in an official standards body, but those discussions are still very early-stage," said Sproch. "To be clear, JavaPoly will run in any modern browser even without support from the browser vendors. Any browser with native Java support will obviously be an order of magnitude faster than a browser without native support, so it's in the browser maker's best interest to add native support."

Better integration with browsers is critical for JavaPoly.js. "Allowing code to run within a native JVM instead of the JavaScript virtual machine allows us to achieve a level of performance that is not possible within the browser's JSVM," Sproch said. "One day, we hope that browsers will support all JVM opcodes within the JSVM."

In pursuing native JVM support for browsers, proponents seek to overcome what they see as limitations of JavaScript dating due to its quick development. "The language is now being standardized by [the ECMA TC39 committee), but the JavaScript language is still tied down by the early lack-of-design decisions, which are difficult to undo due to widespread usage," said Sproch.

Java, however, "was designed much more holistically, with native support for threads, shared memory, locking primitives, 64-bit integers, etc." It also has built-in type-checking and a much more mature software development infrastructure. "The language was much better designed by a whole team of engineers, and is therefore more suitable for larger scale applications."

JavaPoly's developers have had to deal with JavaScript's slow runtime performance and lack of true parallelism as they build out the library, said Sproch. "When available on the client machine, we can call into a native JVM, which allows us to take full advantage of the computer's hardware by bypassing JavaScript entirely."

Currently in an early beta stage of development, JavaPoly.js will be available as a general release whenever its developers believe the API has stabilized. User feedback will be collected in the meantime.