Badass JavaScript

A showcase of awesome JavaScript that pushes the boundaries of what's possible on the web, by @devongovett.

Doppio: A Java Virtual Machine, Compiler and Disassembler in JavaScript

October 3rd 2012

There is no shortage of impressive things that have been done in JavaScript, and we’ve seen JVM implementations in JavaScript before as well.  However, Doppio appears to be the most complete and actively worked on project of the bunch.

Basically, Doppio is a project to get Java running in the browser without plugins.  It includes an implementation of the Java Virtual Machine (VM), as well as an in browser compiler and bytecode disassembler.  It is still a work in progress and performance obviously needs improvement before it is ready to be used in production, but so far it supports:

  • All 200 opcodes
  • Exact emulation of Java’s primitive types, include the 64-bit long
  • Generics
  • Most of the Reflection API
  • File and Standard I/O
  • Major JDK libraries such as String, Pattern, and HashMap.

In my experience, the demo works best in Chrome, but it should work in any browser supporting local storage and typed arrays.

Why Java?

You might be thinking “why would I want to write Java in the browser?” Having a JVM in the browser is about a lot more than Java as there are many other languages that compile to JVM bytecode than just Java, including implementations of existing languages like Ruby (JRuby), Python (Jython), and JavaScript (Rhino) as well as new languages such as Scala, Clojure, and many more.

The point is that a JVM in the browser could be used to run a multitude of languages and existing programs in the browser without manual translation.  However, before this can happen, a lot of work on performance needs to occur.  Currently Doppio interprets the bytecode on the fly, but the authors mention that they want to transition into more of a compiled solution.  Just as Emscripten does by compiling LLVM bytecode into JavaScript, Doppio wants to do for JVM bytecode, and having these tools could be very powerful indeed.

You can find out more information about the Doppio project here, check out the Docco annotated source code or the Github project, and of course try out the demo.

Reminder: Please update your RSS subscription URL to rss.badassjs.com instead of the old FeedBurner URL. More information here.