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.

 

javaandscript

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.

 

javaandscript

More Information

Surf the Edge (Artur Ventura's blog)

BicaVM

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.

 

Banner


OpenAI Library For .NET Exits Beta
19/11/2024

A few months ago the OpenAI .NET library was released as a beta. It has now reached version 2.0.0 and the time has come to leave beta and, with a few amendments enter production readiness.



The Art Of Computer Programming - A Great Present
15/12/2024

If you are looking for a programmer present this holiday season, there is one book, or set of books, that should be top of any list... Donald Knuth's The Art of Computer Programming.


More News

Last Updated ( Sunday, 20 November 2011 )