Why Java programs running on Android systems do not use the standard Java API and virtual machine?

Computer ProgrammingJava

The standard Java API and virtual machine are mainly designed for desktop as well as server systems. They are not that compatible with mobile devices. Because of this, Google has created a different API and virtual machine for mobile devices. This is known as the Dalvik virtual machine.

The Dalvik virtual machine is a key component of the Android runtime and is a part of JVM (Java Virtual Machine) developed specially for Android. The Dalvik virtual machine uses features that are quite important in Java such as memory management, multi-threading etc. The programs in Java are first converted into JVM and this is then interpreted into the DVM bytecode.

Details about both the JVM and the DVM are given as follows −

Java Virtual Machine

The Java Virtual Machine is an application that provides the run-time environment to execute the Java bytecode. It converts the bytecode into machine code. The Java Virtual Machine can perform multiple operations like loading the code, verifying the code, executing the code, providing run-time environment etc.

A diagram that illustrates the working of the Java Virtual Machine is given as follows −

Java Virtual Machine

Dalvik Virtual Machine

The Dalvik Virtual Machine is a version of the Java Virtual Machine that is optimized for low power handheld devices i.e. mobile devices. The DVM optimizes the mobile system for battery life, memory and performance in general.

Programs intended for Android are first written in Java and later compiled to bytecode for the JVM. After that, this bytecode is translated to Dalvik bytecode and stored in .dex and .odex files. These are Dalvik executable and Optimized Dalvik executable files respectively.

A figure that illustrates the working of the Dalvik Virtual Machine is given as follows −

Dalvik

raja
Updated on 22-Jun-2020 15:09:37

Advertisements