The overall structure of a compiled class is quite simple. Indeed, unlike natively
compiled applications, a compiled class retains the structural information
and almost all the symbols from the source code. In fact a compiled class
contains:
• A section describing the modifiers (such as public or private), the
name, the super class, the interfaces and the annotations of the class.
• One section per field declared in this class. Each section describes the
modifiers, the name, the type and the annotations of a field.
• One section per method and constructor declared in this class. Each section
describes the modifiers, the name, the return and parameter types,
and the annotations of a method. It also contains the compiled code of
the method, in the form of a sequence of Java bytecode instructions.
There are however some differences between source and compiled classes:
• A compiled class describes only one class, while a source file can contain
several classes. For instance a source file describing a class with one inner
class is compiled in two class files: one for the main class and one for the
inner class. However the main class file contains references to its inner
classes, and inner classes defined inside methods contain a reference to
their enclosing method.
• A compiled class does not contain comments, of course, but can contain
class, field, method and code attributes that can be used to associate
additional information to these elements. Since the introduction of annotations
in Java 5, which can be used for the same purpose, attributes
have become mostly useless.
• A compiled class does not contain a package and import section, so all
type names must be fully qualified.
Another very important structural difference is that a compiled class contains
a constant pool section. This pool is an array containing all the numeric, string
and type constants that appear in the class. These constants are defined only
once, in the constant pool section, and are referenced by their index in all other
sections of the class file. Hopefully ASM hides all the details related to the
constant pool, so you will not have to bother about it.