What is dalvik virtual machine in android

Android operating system is truly open source in nature. Technically it proves its presence in upcoming smartphones market. As a user we use android functionality in our smartphones and continuously tried to explore new applications on this platform. But as a developer we worked hard to build android applications and ensures its complete development. In this article i explored the technical side of the android operating system, where i mentioned the role of the Dalvik Virtual Machine in android applications.

Note: Android run-time system provides core set of class libraries to ensure smooth platform for developers. With these libraries developers can easily import required libraries into their applications without doing any hard coding in applications.

What is virtual machine ?

A virtual machine is like a software implementation of a physical computer which works like real physical computer. It means a virtual machine can compile and run any program just like a physical computer does for us. In other words we can say it is a like a emulator compared to the real physical machine. But there is a dark-side of virtual machine as it is less efficient than real physical computer and provide unstable performance when multiple virtual machine exist on the same machine.

dalvik virtual machine

Dalvik Virtual Machine

Dalvik is a purpose built virtual machine designed specifically for android which was developed by Dan Bornstein and his team.  Strictly it was developed for mobile devices. While developing Dalvik Virtual Machine Dan Bornstein and his team realize the constraints specific to mobile environment which is not going to change in future at least, like battery life,processing power and many more. So they optimized the dalvik virtual machine. Dalvik virtual machine uses register based architecture. With this architecture dalvik virtual machine has few advantages over java virtual machine such as:

  1. Dalvik uses its own 16 bit instruction set than java 8 bit stack instructions, which reduce the dalvik instruction count and raised its interpreter speed.
  2. Dalvik use less space, which means an uncompressed .dex file is smaller in size(few bytes) than compressed java archive file(.jar file).

Why Java Virtual Machine is not used ?

There is a key aspect of replacing the Java virtual machine with the Dalvik virtual machine is its licensing. The java language, java tools and java libraries are free but the java virtual machine(which is a Stack Machines) is not. Nowadays there are other open source alternatives to Oracle Java virtual machine such as OpenJDK and Apache Harmony projects. Android provides a full featured platform by developing a truly open source and license friendly virtual machine and it also encouraged the developers and mobile companies to adopt for a variety of devices without having to worry about the license.

Role of Dalvik Virtual Machine

The role of dalvik virtual machine is that, In java we write and compile java program using java compiler and run that bytecode on the java virtual machine. On the other side, In android we still write and compile java source file(bytecode) on java compiler, but at that point we recompile it once again using dalvik compiler to dalvik bytecode(dx tool converts java .class file into .dex format) and this dalvik bytecode is then executed on the dalvik virtual machine.

Note: Dalvik team have added Just In Time (JIT) compiler to the Dalvik Virtual Machine. The JIT is a software component which takes application code, analyzes it, and actively translates it into a form that runs faster, doing so while the application continues to run.

Uploaded by:  Author