JVM vs DVM

19 篇文章 0 订阅

 

In this article, we’ll see the differences between Java Virtual Machine and Dalvik Virtual Machine

 

Himanshu Verma

When I was learning Java programming seven years ago from now, I used to ask a lot of questions from myself and friends about this marvellous language but there was one question which popped up most of the time until I didn’t find the satisfactory answer. The question was why java bytecode can run on any machine or platform and how it is different from the other code?. The answer to this question was not easy for me at that time because I was just getting started.

 

 

So in this guide, I’m going to answer the following questions

  • JVM vs DVM
  • Why Android OS uses DVM instead of JVM?

Java Virtual Machine

Java virtual machine (JVM) is an abstract layer between the Java program and the platform the Java code is running on. JVM is platform dependent and different implementations are available for specific platforms.

For example, If you have a Hello.java class and when you run this class file then javac compiler turns your source code to bytecode and creates Hello.class file which means javac compiler does not convert Java code directly to machine code like other compiler does. Bytecode is intermediate code which means humans can not understand this code and this code is not machine/platform dependent. Since bytecode is an intermediate code so you can give it to anyone to run it on any platform that’s why we call Java applications WORA (Write Once and Run Anywhere).

 

 

As you can see from the image above, once you have .class file ready then you can give this file to any platform and it will convert it to native machine code.

Dalvik Virtual Machine

The Dalvik Virtual Machine (DVM) is a virtual machine which executes the android applications. Since everything in mobiles is very limited whether it would be a battery life, processing and memory etc. It had been optimised so that it can fit in with low-powered devices.

 

 

As you can see from the image above, everything is same as JVM except the last two steps. The Dex compiler converts the class files into the .dex file that run on the Dalvik VM. Multiple class files are converted into one dex file.

JVM vs DVM

One of the main reasons of using DVM in android is because it follows the register based model and it is much faster than stack based model while JVM follows the stack based model which takes a lot of memory and also slower than DVM.

There are some major differences, so let’s have a look them

 

 

Why Android OS uses DVM instead of JVM?

There are couple of reasons why Google not choose JVM over DVM, so let’s understand each one of them one by one.

  • Though JVM is free, it was under GPL license, which is not good for Android as most the Android is under Apache license.
  • JVM was designed for desktops and it is too heavy for embedded devices.
  • DVM takes less memory, runs and loads faster compared to JVM.

— The OHIO State University

Conclusion

JVM will work based on byte code and the DVM will work based on optimized bytecode, it is optimised for mobile platforms because mobile devices have less memory, low process and low power that’s why it is using the linux kernal.

Subscribe my mailing list to get the early access of my articles directly in your inbox and Don’t forget to follow my own publication on Medium The Code Monster to polish your technical knowledge.

Know your author

Himanshu Verma has graduated from the Dr. APJ Abdul Kalam University, Lucknow (India). He is an Android & IOS Developer and Machine Learning & Data Science Learner, a Financial Advisor, and a Blogger.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值