Android Dalvik Virtual Machine

In this article, we would be discussing Android Dalvik Virtual Machine. Android Dalvik Machine is quite important for any android developer to understand how their build projects run on the devices. Nowadays, these devices are mobile phones and include android televisions, smartwatches, tablets, etc.

This article aims to make you familiar with the process using which your apps execute on Android devices.

About Android Dalvik Virtual Machine

Android Dalvik Virtual Machine got its name after the name of Dalvik, which is the name of a place in Iceland. Dan Bornstein developed it. Android Dalvik Virtual Machine is very similar to Java Virtual Machine(JVM).

JVM itself is widely used and provides quite a high performance and better memory management. However, JVM is not compatible with working optimally with low-powered handheld devices like smartphones, tablets, smartwatches, etc.

Due to this reason, the Android Dalvik Virtual Machine came into existence. A virtual machine is a software representation of an actual physical device. It implies that you don’t have a physical device but have a model in your system. The representation works quite similarly to how an actual physical device would work.

Dalvik Virtual Machine is configured to work on low-powered devices optimally. Dalvik Virtual Machine provides high-performance features, better memory management, and battery life for low-powered handheld devices. It was developed exclusively for android devices and allowed several apps to execute on the virtual machine.

Role of Android Dalvik Virtual Machine

There are several roles which a Dalvik Virtual Machine has to play on an android device.

  • Providing better performance and memory management
  • Working optimally with any low-powered devices and also optimizing the battery life.
  • Converting java class files to .dex file through Dex Compiler which can inturn execute in the Dalvik Virtual Machines
  • Allowing multiple instances of the applications to run at the same time
  • Allowing each application to have their instances
  • Providing faster execution without affecting the battery life

Working of Dex Compiler

Working of Dex Compiler

Dex Compiler is a part of the Dalvik Virtual Machine and helps convert the java class to executable .dex files. We need to understand the whole process of how the source code is finally converted to a runnable APK file.
The below figure describes the working of the Dalvik Virtual machine along with the Dex Compiler.

Whenever you write your codes, they are immediately converted to a .class file using the Java Compiler. After that, the Dex Compiler comes into the picture. The dex compiler task converts the generated .class file into a .dex file (Dalvik Byte Code). This .dex file is then converted to the .apk file with the help of AAPT packaging.

Difference between Android Dalvik Virtual Machine and Android Runtime(ART)

Android Dalvik Virtual Machine  Android Runtime(ART)
It(DVM) converts the bytecode whenever you start a specific application Android Runtime(ART) converts the bytecode only once that too during the installation of that application
It is slower than Android Runtime It is faster than Android Dalvik Virtual Machine
When we consider Booting, then Android Dalvik Virtual Machine is fast Android Runtime is lagging in terms of booting
The Cache is built fast over time and hence reduces boot time The Cache time is made at the first boot and thus takes time while booting
Dalvik Virtual Machine works better with low space capacity devices Android Runtime requires a large amount of space as it stores both the compiled app as well as the APK
It is a tested and stable virtual machine It is currently new and is experimental
Dalvik Virtual Machine uses less space as it uses JIT (Just In Time) Compiler Android Runtime uses more space as it uses the AOT (Ahead Of Time) compiler
Dalvik Virtual Machine doesn’t provide optimized battery life as it consumes more power Android Runtime provides optimized battery performance as it consumes less power.
Dalvik Virtual Machine has a poor garbage collection compared to Android Runtime Android Runtime has a better garbage collection compared to Dalvik Virtual Machine
Dalvik Virtual Machine based apps are less responsive compared to Android Runtime Android Runtime based apps are more responsive compared to Android Dalvik Virtual Machine
This is old and is now replaced by Android Runtime Android Runtime can be thought of as an upgraded version of Android Dalvik Virtual Machine and provides a lot of improvements

Advantages of Dalvik Virtual Machine

  • The execution is faster in Android Dalvik Virtual Machine
  • The Dalvik Virtual Machine has a lower boot time
  • Dalvik Virtual Machine is specifically designed to work on Android devices
  • Every Application can have their instance
  • Android Dalvik Virtual Machine supports running of multiple instances
  • It uses Just in Time (JIT) compiler due to which it consumes less space
  • It is capable of executing APK files

Disadvantages of Dalvik Virtual Machine

  • Dalvik Virtual Machine is only supportive for Android Operating System
  • Dalvik Virtual Machine has a poor garbage collection system
  • The installation of the app takes more time due to the presence of Dex
  • You require more instructions than register machine to implement the same high-level code

Summary

You came across what Dalvik Virtual Machine is and why it is used in Android through this article. You saw the working of Dex Compiler and came across the steps through which your source code is converted to an executable APK file. Then you also saw the roles and applications of the Dalvik Virtual Machine.

Moving further, you came across the difference between Android Dalvik Virtual Machine(DVM) and Android Runtime(ART). Finally, you saw the advantages and disadvantages of the Android Dalvik Virtual Machine.