Java Class File

Byte Order: Big-endian
Offset   Length   Contents
  0      4 bytes  Java Class File Magic (0xcafebabe)
  4      2 bytes  Minor version
  6      2 bytes  Major version
  8      2 bytes  Number of constant pools (c)
[ // Constant pools
         1 byte   Constant tag
         ? bytes  Constant pools
]{c}
         2 bytes  Access flags
         2 bytes  This class index
         2 bytes  Super class index
         2 bytes  Number of interfaces (i)
[ // Interfaces
         2 bytes  Interface index
]{i}
         2 bytes  Number of field (f)
[ // Fields ]{f}
         2 bytes  Number of methods (m)
[ // Methods ]{m}
         2 bytes  Number of class attribute informations (a)
[ // Class attribute informations]{a}

Constant Pool

Constant Asciz:
         1 byte   Constant tag (0x01)
         2 bytes  Length (n)
        (n)bytes  Asciz

Constant Unicode:
         1 byte   Constant tag (0x02)
        (?)bytes  Unicode

Constant Integer value:
         1 byte   Constant tag (0x03)
         4 bytes  Inveger value

Constant Floating value:
         1 byte   Constant tag (0x04)
         4 bytes  Floating value

Constant Long Floating point value:
         1 byte   Constant tag (0x05)
         4 bytes  High Floating value bytes
         4 bytes  Low  Floating value bytes

Constant Double Floating point value:
         1 byte   Constant tag (0x06)
         4 bytes  High bytes of double
         4 bytes  Low  bytes of double

Constant Class:
         1 byte   Constant tag (0x07)
         2 bytes  Name index

Constant String:
         1 byte   Constant tag (0x08)
         2 bytes  String index

Constant Field Reference:
         1 byte   Constant tag (0x09)
         2 bytes  Class index
         2 bytes  Name and Type index

Constant Method Reference:
         1 byte   Constant tag (0x0a)
         2 bytes  Class index
         2 bytes  Name and Type index

Constant Interface Method Reference:
         1 byte   Constant tag (0x0b)
         2 bytes  Class index
         2 bytes  Name and Type index

Constant Name and Type:
         1 byte   Constant tag (0x0c)
         2 bytes  Name index
         2 bytes  Signature index

Field

         2 bytes  Access flags
         2 bytes  Name index
         2 bytes  Signature index
         2 bytes  Number of field attributes (f)
[ // Field attributes
         2 bytes  Attribute name index
         4 bytes  Field Attribute length (n)
        (n)bytes  Field Attribute
]{f}

Method

         2 bytes  Access flags
         2 bytes  Name index
         2 bytes  Signature index
         2 bytes  Number of method attributes (m)
[ // Method attributes
         2 bytes  Attribute name index
         4 bytes  Method attribute length (n)
        (n)bytes  Method attribute
]{m}

Class attribute information

         2 bytes  Attribute name index
         4 bytes  Class attribute  length(n)
        (n)bytes  Class attribute