Bagmita
Bagmita

Reputation:

Is the DVM an interpreter or a Compiler?

Is the DVM an interpreter or a compiler? Why did google have to come up with the DVM when there is already the JVM? Can the JVM not be used in mobile platforms? If not why not?

Upvotes: 1

Views: 1044

Answers (3)

Buhake Sindi
Buhake Sindi

Reputation: 89169

Is the DVM an interpreter or a compiler?

There's a tool called dx that converts your java bytecode to a dex file. So, you compile with java to create a java bytecode (a class file) and a dx tool converts these bytecodes to a .dex file (executable).

Why did google have to come up with the DVM when there is already the JVM?

Dalvik is optimised to run on mobile devices or devices with low memory requirement. Dalvik VM takes less space to run compared to the JVM.

One important factor is LICENSE. If Google had to go to J2ME, the application had to be licensed, etc and Google wanted to avoid being licensed.

Also a quote from @leo's - Is Dalvik the better J2ME?:

As J2ME is not really a strong framework, you have a single programming language, but it's up to the vendor which functionality he likes to integrate, every single phone is different. That makes porting J2ME to a real pain.

3)

Can the JVM not be used in mobile platforms? If not why not?

At the present moment, no as it requires resources (that's available on PC) to run. Also, it's a stack machine, so it uses "instructions to load data on the stack and manipulate that data, and, thus, require more instructions than register machines to implement the same high level code" (source).

We can expect future mobile/portable devices to be able to have the processing power, storage capability and security features to run the JVM, but for now, Dalvik is king! :-)

Hope this helps.

Upvotes: 3

Blrfl
Blrfl

Reputation: 7003

Is the DVM an interpreter or a compiler?

Given that the version of Dalvik that shipped with 2.2 has just-in-time compilation, the answer is "yes."

Why did google have to come up with the DVM when there is already the JVM?

Can the JVM not be used in mobile platforms? If not why not?

When you say "the" JVM, I'll assume you mean Sun's* JVM. There's no reason why it can't be used in a mobile platform, and it has been. ("Mobile" being a very broad term.) However, that particular implementation is not ideal in every environment, and Java was always intended to have many ways to run its bytecode ranging from VMs on desktops to silicon that runs it directly.

Exactly what drove the decision to implement Dalvik is a question only the people who wrote it can answer, although it may have come down to licensing or having the ability to fine-tune it as they pleased. In general, though, Dalvik's more compact executable format (DEX) makes it better suited to environments where on-board memory is precious as was the case with early Android devices. Its register-based implementation may also provide better compute performance and lower power consumption than Sun's stack-based JVM on the kinds of CPUs that the OS targets.

*Sorry, Larry, no soup for you.

Upvotes: 1

prap19
prap19

Reputation: 1868

DVM = Interpreter wiki

Dalvik is very optimized and has different architecture to support Android features. Do look at the wiki link above you will have answers for everything. JVM can be used in mobile platforms. Infact, J2ME is based on JVM.

Upvotes: 1

Related Questions