dex
file is a file that is executed on the Dalvik VM.
Dalvik VM includes several features for performance optimization, verification, and monitoring, one of which is Dalvik Executable (DEX).
Java source code is compiled by the Java compiler into .class
files. Then the dx
(dexer) tool, part of the Android SDK processes the .class
files into a file format called DEX
that contains Dalvik byte code. The dx
tool eliminates all the redundant information that is present in the classes. In DEX
all the classes of the application are packed into one file. The following table provides comparison between code sizes for JVM jar files and the files processed by the dex
tool.
The table compares code sizes for system libraries, web browser applications, and a general purpose application (alarm clock app). In all cases dex tool reduced size of the code by more than 50%.
In standard Java environments each class in Java code results in one .class
file. That means, if the Java source code file has one public class and two anonymous classes, let’s say for event handling, then the java compiler will create total three .class
files.
The compilation step is same on the Android platform, thus resulting in multiple .class
files. But after .class
files are generated, the “dx” tool is used to convert all .class
files into a single .dex
, or Dalvik Executable, file. It is the .dex
file that is executed on the Dalvik VM. The .dex
file has been optimized for memory usage and the design is primarily driven by sharing of data.