Comparison of Java and Android API

This article compares the application programming interfaces (APIs) and virtual machines (VMs) of the programming language Java and operating system Android.

While most Android applications are written in Java-like language, there are some differences between the Java API and the Android API, and Android does not run Java bytecode by a traditional Java virtual machine (JVM), but instead by a Dalvik virtual machine in older versions of Android, and an Android Runtime (ART) in newer versions, that compile the same code that Dalvik runs to Executable and Linkable Format (ELF) executables containing machine code.

Java bytecode in Java Archive (JAR) files is not executed by Android devices. Instead, Java classes are compiled into a proprietary bytecode format and run on Dalvik (or compiled version thereof with newer ART), a specialized virtual machine (VM) designed for Android. Unlike Java VMs, which are stack machines (stack-based architecture), the Dalvik VM is a register machine (register-based architecture).

Dalvik has some traits that differentiate it from other standard VMs:
 * The VM was designed to use less space.
 * The constant pool has been modified to use only 32-bit indexes to simplify the interpreter.
 * Standard Java bytecode executes 8-bit stack instructions. Local variables must be copied to or from the operand stack by separate instructions.  Dalvik instead uses its own 16-bit instruction set that works directly on local variables.  The local variable is commonly picked by a 4-bit virtual register field.

Because the bytecode loaded by the Dalvik virtual machine is not Java bytecode and due to the way Dalvik loads classes, it is impossible to load library packages as jar files. A different procedure must be used to load Android libraries, in which the content of the underlying  file must be copied in the application private internal storage area before it is loaded.

System properties
As is the case for the Java SE class, the Android class allows retrieving system properties. However, some mandatory properties defined with the Java virtual machine have no meaning or a different meaning on Android. For example:
 * property returns 0 because it is not used on Android.
 * invariably returns 0.9 independently of the version of Android used.
 * invariably returns 50 independently of the version of Android used.
 * has a different meaning on Android.
 * and  properties do not exist on Android.

Class library
Current versions of Android use the latest Java language and its libraries (but not full graphical user interface (GUI) frameworks), not the Apache Harmony Java implementation, that older versions used. Java 8 source code that works in latest version of Android, can be made to work in older versions of Android.

java.lang package
By default, the default output stream and  do not output anything, and developers are encouraged to use the  class, which logs Strings on the LogCat tool. This has changed at least from HoneyComb, and they now output to the log console also.

Graphics and widget library
Android does not use the Abstract Window Toolkit nor the Swing library. User interfaces are built using View objects. Android uses a framework similar to Swing, based on s rather than s. However, Android widgets are not JavaBeans: the Android application must be provided to the widget at creation.

Look and feel
Android widget library does not support a pluggable look and feel architecture. The look and feel of Android widgets must be embedded in the widgets. However, a limited ability exists to set styles and themes for an application.

Layout manager
Contrary to Swing where layout managers can be applied to any container widget, Android layout behavior is encoded in the containers.

java.beans package
Android includes only a small subset of the  package ( and related classes).