Google Android, Now 100% Java-Free!

Lets be clear about one thing: the Android platform is not Java. It is an entirely new platform which, at best, has a compatibility layer for Java code.

Android uses the Dalvik virtual machine, which is a register-based VM whereas the Java VM is stack-based. Neither a specification nor the source code for Dalvik are available yet, but it’s clear that the bytecodes are quite different from Java bytecodes. There is a translation tool from JVM bytecode (.class files) to Dalvik bytecode (.dex files) but it is a build-time tool only. JVM bytecodes are never loaded onto an Android device.

Despite this, Java is used to develop Android applications, with the help of the Eclipse-based SDK. The key to this apparent contradiction is that somewhere on their way to deployment, the applications cease to be Java. The build pipeline uses a standard Java compiler to produce .class files but then Android’s “dx” tool transforms and repackages them into .dex files. In addition, a subset of the standard JRE libraries are available, although these have been similarly transformed. Because of this compatibility layer, it is possible to compile “most” standard Java source code to run on Android, so long as one avoids the parts of the standard library that have been omitted. Incidentally, I believe that Google have used the class library from Apache Harmony to achieve this. If they had taken the class library from OpenJDK, then they would have been required to adopt the GPL license.

Why use a custom VM instead of the JVM? Dalvik is apparently optimized to allow multiple instances of the VM to run simultaneously, even on devices with meagre memory. Each Android application runs in a separate Linux process, which is how the overall runtime achieves dynamic installation, activation and deactivation of applications. However this could have been achieved with a single JVM process using OSGi. Specifically, the Application Admin Service specification from the OSGi Mobile Expert Group addresses exactly this requirement.

It’s my suspicion that Google are only temporarily leveraging the Java language in order to gain developer mindshare and make use of existing tools such as Eclipse JDT, and they may well be planning to launch an efficient, Dalvik-specific language at some point in the future.

8 Comments

  1. Doug Schaefer:

    Why would they go through the effort of creating a new language. Java does what they need. The have the tools in place. They’re ready to go.

    I wondered about OSGi in this environment but it would need to be customized to support loading dex fles. Not sure how feasable that would be. But maybe that’s the work around.

  2. Radoslav Gerganov:

    They use similar approach for GWT - converting java byte code into javascript, it seems that this method works well. I don’t think using App Admin for running multiple apps in a single JVM is quite better since if you use some native APIs there is always a chance to crash the JVM and all applications die.

  3. Carl Rosenberger:

    Yes, Android indeed uses the Harmony class libraries.

    Google has hired away all the best Java developers from Sun. Why would they do something different now, what’s the benefit?

    From my first experience trying out the SDK, it’s done with love, it’s done good. This is here to stay.

    That doesn’t at all mean that OSGi wouldn’t make sense on Android. On a phone you do want pluggable services and you do want components to be shared and reused. You do want components to be shut down when they are no in use.

    Noone stops anyone from porting OSGi onto Android, the platform is open.

  4. Vesa Kaihlavirta:

    Could Rob Pike and Inferno have something to do with this?

  5. Brian:

    Google uses three official languages: Java, Python and C++. They’re not going to invent their own — I suspect the only reason you threw that in there is because of some unfounded bias you have against Java.

  6. Neil:

    Brian, I have been a professional Java developer for around 8 years. You can be assured that, if I do have any biases against Java, they are entirely founded ones.

  7. Marcel Offermans:

    We just ported the Apache Felix OSGi implementation to Google Android. Click on my name for a link to the blog entry explaining how. We also have published the sourcecode, a binary and some extra instructions here:

    https://opensource.luminis.net/confluence/display/SITE/OSGi+Android

  8. Google Android in the Java Community | the fabulous freak:

    [...] Google Android, Now 100% Java-Free! [Neil’s point-free blog] [...]

Leave a comment