When Sun Microsystems first launched Java, it was done with considerable media fanfare. Sun advertisements of the time heralded Java as a revolutionary technology that would be everywhere and change life as we know it (I write this with no exaggeration whatsoever).
Of course, we cannot really dismiss the ubiquity and usefulness that Java has grown into in its many forms. However, the early claims of its promise were based on the fact that the handheld computing market was expected to explode (as it did) and Java’s virtual machine would be the portable software engine that powered all of those devices.
It is doubtful that anyone predicted that the future's most prolific handheld platform, which would turn out to be Android, would technically operate Java programs but not run a single instruction of Java byte code.
The dust has long settled from the patent dispute between Google and Oracle over the Android virtual machine, Dalvik. With Google victorious, the Java development world will continue to see fragmentation between the mobile space and the server/desktop. It is then useful to know what we are actually dealing with when we create Java code for Google’s alternative virtual machine.
At the most basic levels, code compiled for the JVM and for Dalvik will not exhibit many differences. However, there is a complete architectural difference between the two. Dalvik is actually much more like most physical processors in that it is register-based. It has 218 opcodes which operate directly upon 216 registers. JVM bytecode, on the other hand, is stack based. Dalvik does not run conventional .class files, but rather uses the dx compiler to take .class files that have been output by the conventional java compiler and then aggregates them into the .dex format, the bytcode upon which it runs.
It is possible to write countless equivalent applications for both virtual machines in which these differences make no impact, but industrial-grade code will almost invariably involve the Java’s reflection API or ClassLoader at some point. Both allow flexible and dynamic manipulation of classes, but as we have covered above, classes fit into Dalvik’s architecture in a completely different way. It is then crucial for developers that are coming over from core or enterprise Java to learn how to translate some of Java’s more flexible features to the Android platform.