Class file

Class file is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Magic

A sequence of bytes.

The sequence is expected to match this hexidecimal sequence: ca fe ba be.

32 (4 bytes)

Minor version

A 16-bit integer value (big endian).

16 (2 bytes)

Major version

A 16-bit integer value (big endian).

16 (2 bytes)

Constant pool count

A 16-bit integer value (big endian).

16 (2 bytes)

Constant pool

A list of list of elements elements.

The number of elements in the list is the difference between Constant pool count of Class file and 1.

The particular choice is based on a 8-bit value preceeding the actual encoded value. If 7, then Class cp info will be choosen. If 6, then Double cp info will be choosen. If 9, then Field ref cp info will be choosen. If 4, then Float cp info will be choosen. If 3, then Integer cp info will be choosen. If 11, then Interface method ref cp info will be choosen. If 10, then Method ref cp info will be choosen. If 12, then Name and type cp info will be choosen. If 8, then String cp info will be choosen. If 1, then Utf8 cp info will be choosen.

(unknown)

Access flags

A 16-bit integer value (big endian).

16 (2 bytes)

This class

A 16-bit integer value (big endian).

16 (2 bytes)

Super class

A 16-bit integer value (big endian).

16 (2 bytes)

Interfaces count

A 16-bit integer value (big endian).

16 (2 bytes)

Interfaces

A list of 32-bit integer value (little endian) elements.

The number of elements in the list is Interfaces count of Class file.

Interfaces count of Class file times 32

Field count

A 16-bit integer value (big endian).

16 (2 bytes)

Fields

A list of Field info elements.

The number of elements in the list is Field count of Class file.

(unknown)

Method count

A 16-bit integer value (big endian).

16 (2 bytes)

Methods

A list of Method info elements.

The number of elements in the list is Method count of Class file.

(unknown)

Attribute count

A 16-bit integer value (big endian).

16 (2 bytes)

Attributes

A list of Source file or Deprecated elements.

The number of elements in the list is Attribute count of Class file.

The particular type of data structure is selected based on the value of 16 leading bits. These bits are interpreted as an unsigned int. The table below lists the conditions, and the data structure assumed when these conditions are met.

Condition

Data structure

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "SourceFile"

Source file

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "Deprecated"

Deprecated

(unknown)

Class cp info

Class cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Name index

A 16-bit integer value (big endian).

16 (2 bytes)

Double cp info

Double cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Value

A 64-bit integer value (big endian).

64 (8 bytes)

Field ref cp info

Field ref cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Class index

A 16-bit integer value (big endian).

16 (2 bytes)

Name and type index

A 16-bit integer value (big endian).

16 (2 bytes)

Float cp info

Float cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Value

A 32-bit integer value (big endian).

32 (4 bytes)

Integer cp info

Integer cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Value

A 32-bit integer value (big endian).

32 (4 bytes)

Interface method ref cp info

Interface method ref cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Class index

A 16-bit integer value (big endian).

16 (2 bytes)

Name and type index

A 16-bit integer value (big endian).

16 (2 bytes)

Method ref cp info

Method ref cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Class index

A 16-bit integer value (big endian).

16 (2 bytes)

Name and type index

A 16-bit integer value (big endian).

16 (2 bytes)

Name and type cp info

Name and type cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Name index

A 16-bit integer value (big endian).

16 (2 bytes)

Descriptor index

A 16-bit integer value (big endian).

16 (2 bytes)

String cp info

String cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

String index

A 16-bit integer value (big endian).

16 (2 bytes)

Utf8 cp info

Utf8 cp info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Length

A 16-bit integer value (big endian).

16 (2 bytes)

Value

A sequence of characters, encoded in ASCII.

The number of characters of the string is Length of Utf8 cp info.

8 times Length of Utf8 cp info

Constant value

Constant value is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Attribute length

A 32-bit integer value (big endian).

32 (4 bytes)

Constant value index

A 16-bit integer value (big endian).

16 (2 bytes)

Synthetic

Synthetic is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Attribute length

A 32-bit integer value (big endian).

32 (4 bytes)

Deprecated

Deprecated is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Attribute length

A 32-bit integer value (big endian).

32 (4 bytes)

Field info

Field info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Access flags

A 16-bit integer value (big endian).

16 (2 bytes)

Name index

A 16-bit integer value (big endian).

16 (2 bytes)

Descriptor index

A 16-bit integer value (big endian).

16 (2 bytes)

Attributes count

A 16-bit integer value (big endian).

16 (2 bytes)

Attributes

A list of Constant value, Synthetic or Deprecated elements.

The number of elements in the list is Attributes count of Field info.

The particular type of data structure is selected based on the value of 16 leading bits. These bits are interpreted as an unsigned int. The table below lists the conditions, and the data structure assumed when these conditions are met.

Condition

Data structure

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "ConstantValue"

Constant value

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "Synthetic"

Synthetic

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "Deprecated"

Deprecated

(unknown)

Line number table entry

Line number table entry is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Start pc

A 16-bit integer value (big endian).

16 (2 bytes)

Line number

A 16-bit integer value (big endian).

16 (2 bytes)

Line number table

Line number table is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Attribute length

A 32-bit integer value (big endian).

32 (4 bytes)

Line number table length

A 16-bit integer value (big endian).

16 (2 bytes)

Line number table

A list of Line number table entry elements.

The number of elements in the list is Line number table length of Line number table.

Line number table length of Line number table times 32

Local variable table entry

Local variable table entry is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Start pc

A 16-bit integer value (big endian).

16 (2 bytes)

Length

A 16-bit integer value (big endian).

16 (2 bytes)

Name index

A 16-bit integer value (big endian).

16 (2 bytes)

Descriptor index

A 16-bit integer value (big endian).

16 (2 bytes)

Index

A 16-bit integer value (big endian).

16 (2 bytes)

Local variable table

Local variable table is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Attribute length

A 32-bit integer value (big endian).

32 (4 bytes)

Local variable table length

A 16-bit integer value (big endian).

16 (2 bytes)

Local variable table

A list of Local variable table entry elements.

The number of elements in the list is Local variable table length of Local variable table.

Local variable table length of Local variable table times 80

Code

Code is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Attribute length

A 32-bit integer value (big endian).

32 (4 bytes)

Max stack

A 16-bit integer value (big endian).

16 (2 bytes)

Max locals

A 16-bit integer value (big endian).

16 (2 bytes)

Code length

A 32-bit integer value (big endian).

32 (4 bytes)

Code

A list of 8-bit integer value (little endian) elements.

The number of elements in the list is Code length of Code.

Code length of Code times 8

Exception table length

A 16-bit integer value (big endian).

16 (2 bytes)

Attributes count

A 16-bit integer value (big endian).

16 (2 bytes)

Attributes

A list of Line number table or Local variable table elements.

The number of elements in the list is Attributes count of Code.

The particular type of data structure is selected based on the value of 16 leading bits. These bits are interpreted as an unsigned int. The table below lists the conditions, and the data structure assumed when these conditions are met.

Condition

Data structure

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "LineNumberTable"

Line number table

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "LocalVariableTable"

Local variable table

(unknown)

Exceptions

Exceptions is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Attribute length

A 32-bit integer value (big endian).

32 (4 bytes)

Number of exceptions

A 16-bit integer value (big endian).

16 (2 bytes)

Exception index table

A list of 32-bit integer value (little endian) elements.

The number of elements in the list is Number of exceptions of Exceptions.

Number of exceptions of Exceptions times 32

Method info

Method info is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Access flags

A 16-bit integer value (big endian).

16 (2 bytes)

Name index

A 16-bit integer value (big endian).

16 (2 bytes)

Descriptor index

A 16-bit integer value (big endian).

16 (2 bytes)

Attributes count

A 16-bit integer value (big endian).

16 (2 bytes)

Attributes

A list of either one of 4 elements.

The number of elements in the list is Attributes count of Method info.

The particular type of data structure is selected based on the value of 16 leading bits. These bits are interpreted as an unsigned int. The table below lists the conditions, and the data structure assumed when these conditions are met.

Condition

Data structure

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "Code"

Code

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "Exceptions"

Exceptions

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "Synthetic"

Synthetic

the value (a String) of the nth element of Constant pool of Class file (with n being the difference between the value of the first 16 bits and 1) equals the String "Deprecated"

Deprecated

(unknown)

Source file

Source file is composed out of several other smaller elements. The table below provides an overview.

Name

Description

Size (in bits)

Attribute length

A 32-bit integer value (big endian).

32 (4 bytes)

Source file index

A 16-bit integer value (big endian).

16 (2 bytes)