Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between bytecode in .class file and that of .dex file [duplicate]

Tags:

java

android

I wanted to know what are the differences between - the bytecode in the .class files which are obtained after compilation of .java files and the byte code in the .dex file. Are they of different format? if yes, which format

like image 474
FAZ Avatar asked Nov 30 '22 09:11

FAZ


1 Answers

A JVM .class contains JVM bytecode. You can read the specification of JVM bytecode as part of the JVM Specification, specifically, Chapter 6: The Java Virtual Machine Instruction Set.

A .dex file contains Dalvik bytecode. Dalvik was the original VM used by Android. It has now been replaced by the Android Runtime. The original version of Dalvik was a pure interpreter, later a compiler was added. ART used to be a pure compiler, it compiled your code once ahead-of-time when it was installed (not every time when it is run as a JIT compiler does). As of today in 2020, ART is capable of interpreting, AOT-compiling and JIT-compiling.

The major differences between JVM bytecode and Dalvik bytecode are:

  • the JVM is stack-based, Dalvik is register-based
  • JVM bytecode was originally designed for interpretation, although most JVMs nowadays actually have compilers, whereas Dalvik bytecode was originally designed for compilation, although in the first versions it actually was interpreted
like image 169
Jörg W Mittag Avatar answered Dec 04 '22 12:12

Jörg W Mittag