JavaScript JVM runs Java
Written by Mike James   
Sunday, 20 November 2011

The world of software is made slightly crazy because of the huge flexibility within any computer language. Once you have absorbed the idea of a compiler written in the language it compiles what else is there left to gawp at? But... a Java Virtual Machine JVM written in JavaScript seems like another level of insanity.

In fact it is a quite reasonable idea which is only made mad by the usual positions that Java, the top dog, and JavaScript the underling, usually occupy. Java is compiled not to machine code but to a special byte code which is then run on a virtual machine which is usually implemented in native machine code. There is, however nothing stopping an intrepid programmer from implementing it in any language you can name. The only real problem is that you need the implementation to be fast so that the byte code runs at an acceptable speed.



Until recently implementing a JVM in JavaScript would have been difficult because of efficiency problems but there have been huge speed increases in JavaScript engines. So much so that a lone coder, Artur Ventura, has implemented a large part of the standard JVM using JavaScript and you can check the code out on Github.

The motivation for this effort is put very well in Artur's blog. He argues that rather than build JavaScript into web browsers they should have a virtual machine so that any language can be used. As well as this advantage, he also points out that with a JVM type approach you get automatic sandboxing and simply sending the JVM to the server provides browser independent persistence.

It really does make much more sense to have a JVM build into the browser but failing that why not simply emulate the JVM in JavaScript which is built into every browser. This is just another aspect of the steady conversion of features provided by plugins to JavaScript implementations - codecs, pdf, zipping and so on.

After 6 months of work the result is BicaVM which, it is claimed, runs 60% of byte code. It hasn't been optimized as yet, but it does run on the iPad/iPhone and it supports a JNI interface to the DOM.

Will this result in anything practical?

Probably not. It is a proof of concept and the idea that the browser should be treated as a virtual machine in its own right isn't at all crazy. It is a little strange however to think of JavaScript actually running Java programs. Perhaps it is the assembler of the internet age.



More Information

Surf the Edge (Artur Ventura's blog)


Related News

JavaScript H.264 decoder


To be informed about new articles on I Programmer, subscribe to the RSS feed, follow us on Google+, Twitter or Facebook or sign up for our weekly newsletter.



AWS Lambda Adopts Python 3.10

AWS Lambda functions can now use all the new and useful language features of Python 3.10 as well as take advantage of the performance improvements this version introduces, in both managed runtime [ ... ]

A Gentle Introduction To React, Visualized

React quickly became a popular JavaScript framework. Here's a very useful interactive website by that showcases React's
capabilities and how it has helped in changing the face of the Web.

More News

Last Updated ( Sunday, 20 November 2011 )