Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How exactly does JVM differ from Dalvik and/or ART?

Firstly, I think I may have titled this question poorly, but I couldn't think of the right words, so please, feel free to suggest an edit and I will make it, so that the question is more educational and relevant to others.

I know that javax.Swing simply cannot be used for an Android project, and I've accepted this and learned Android XML based UI design, but just out of curiosity, I want to know exactly why.

I realize that the screen dimensions of a phone might be something Swing wouldn't handle well, but what is to stop a developer from simply importing the javax.Swing package (besides Android Studio simply not letting it happen in the first place), however deformed and hideous Swing windows might be on an Android device screen? I also realize that AWT and SWT would also have to be imported, but the same question applies to these packages as well.

I think my lack of understanding of this might really root from a lack of understanding of how the Java Virtual Machine and the Android equivalent (is Dalvik still used, or have they switched cold-turkey to ART?).

As always, any information or reading on the subject you can provide is greatly appreciated. I really want to learn more about the fundamentals of how the JVM, Dalvik, and ART work.

like image 717
Mat Jones Avatar asked Mar 31 '16 13:03

Mat Jones


People also ask

What is the difference between Dalvik and ART virtual machine?

DVM converts bytecode every time you launch a specific app. ART converts it just once at the time of app installation. That makes CPU execution easier. Improved battery life due to faster execution.

What is the difference JVM DVM and ART?

JVM is stack based but DVM is register based which is designed to run on low memory. JVM uses java byte code and runs '. class' file having JIT (Just in Time) where DVM uses its own byte code and runs '.

What's the difference between ART runtime and Dalvik runtime?

Difference between ART and Dalvik Approach: ART uses AOT(Ahead Of Time) approach and compiles the whole code during the installation time but the Dalvik uses JIT(Just In Time) approach and complies only a part of the code during installation and rest of the code will be compiled dynamically.


1 Answers

There are at least three fundamental differences:

  • the APIs differ; for instance, even the most recent versions of Android's SDK don't have JSR 203;
  • the binary formats differ; Dalvik/ART does not generate JVM bytecode;
  • the language level differs; it is partly a consequence of the previous point, since in order to support a given language level, Dalvik/ART has to reimplement all the parsing/bytecode production to fit its own VM.

The latter point means that as a result, there is still no mainstream support in Android of try-with-resources which appeared in Java 5 years ago; various efforts have seen the day to support this plus Java 8's "goodies" over time, but none of them is really Java "at the core"; understand, they do not use the JVM, they do not use the Java compiler.

Recent news tells that this is bound to change in "Android N" (which will actually use OpenJDK). Which is good news. Also, as to point 1, you may recall that infamous Oracle vs Google case with regards to APIs being copyrightable... This is still not completely settled.

like image 177
fge Avatar answered Sep 24 '22 15:09

fge