How Android Code İs Compiled?

Burhan ARAS
Jul 4, 2017 · 2 min read

Although, we use Java when developing Android apps, there are many differences between traditional Java SE and the way we code Android.

The virtual machine that runs on an Android device is called Dalvik Virtual Machine(DVM). Maybe the most significant difference between the both is that JVM is stack-based while DVM is register-based.

One minute! What the hell is stack based and register based?

Ok, let me briefly explain:

In Stack Based VM’s, all the arithmetic and logic operations are carried out via Push and Pop operands and results in the stack.

On the other hand, in Register Based VM’s, the data structure where the operands are stored is based on the registers of CPU.

Java code is compiled to an intermediate format called byte-code. Then this byte-code is parsed by JVM and translated to machine code.

Android SDK has a tool called dx that converts Java byte-code to Dalvik byte-code. It is locates under build-tools/android-{version}.

Then Dalvik VM moves in and translates Dalvik byte-code to binary machine code.

Difference between JVM and DVM execution

Finally, i have visualised the different flows with my own handwriting.

In next article, we will answer that how an app is started in Android.

Until then, have fun!

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store