---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 13 Edition"
java_version: 13
chapter: "Chapter 4. The class File Format"
section: "4.1"
heading: "4.1. The ClassFile Structure"
parent: "Chapter 4. The class File Format"
source: https://docs.oracle.com/javase/specs/jvms/se13/html/jvms-4.html#jvms-4.1
id: "4.1"
url: https://jvm.obfuscated.software/jvms/se13/4.1.html
raw: https://jvm.obfuscated.software/jvms/se13/4.1.md
---

# 4.1. The `ClassFile` Structure

A `class` file consists of a single `ClassFile` structure:

```
ClassFile {
    u4             magic;
    u2             minor_version;
    u2             major_version;
    u2             constant_pool_count;
    cp_info        constant_pool[constant_pool_count-1];
    u2             access_flags;
    u2             this_class;
    u2             super_class;
    u2             interfaces_count;
    u2             interfaces[interfaces_count];
    u2             fields_count;
    field_info     fields[fields_count];
    u2             methods_count;
    method_info    methods[methods_count];
    u2             attributes_count;
    attribute_info attributes[attributes_count];
}
```

The items in the `ClassFile` structure are as follows:

- **magic**

  The `magic` item supplies the magic number identifying the `class` file format; it has the value `0xCAFEBABE`.

- **minor_version, major_version**

  The values of the `minor_version` and `major_version` items are the minor and major version numbers of this `class` file. Together, a major and a minor version number determine the version of the `class` file format. If a `class` file has major version number `M` and minor version number `m`, we denote the version of its `class` file format as `M`.`m`.

  A Java Virtual Machine implementation which conforms to Java SE `N` must support exactly the major versions of the `class` file format specified in the third column of Table 4.1-A, "Supported major versions". The notation A .. B means major versions A through B, inclusive of both A and B. The second column, "Corresponding major version", shows the major version introduced by each Java SE release, that is, the first release that could have accepted a `class` file containing that `major_version` item. For very early releases, the JDK version is shown instead of the Java SE release.

  **Table 4.1-A. `class` file format major versions**

  | Java SE | Corresponding major version | Supported major versions |
  |---|---|---|
  | 1.0.2 | 45 | 45 |
  | 1.1 | 45 | 45 |
  | 1.2 | 46 | 45 .. 46 |
  | 1.3 | 47 | 45 .. 47 |
  | 1.4 | 48 | 45 .. 48 |
  | 5.0 | 49 | 45 .. 49 |
  | 6 | 50 | 45 .. 50 |
  | 7 | 51 | 45 .. 51 |
  | 8 | 52 | 45 .. 52 |
  | 9 | 53 | 45 .. 53 |
  | 10 | 54 | 45 .. 54 |
  | 11 | 55 | 45 .. 55 |
  | 12 | 56 | 45 .. 56 |
  | 13 | 57 | 45 .. 57 |

  For a `class` file whose `major_version` is 56 or above, the `minor_version` must be 0 or 65535.

  For a `class` file whose `major_version` is between 45 and 55 inclusive, the `minor_version` may be any value.

  A historical perspective is warranted on JDK support for `class` file format versions. JDK 1.0.2 supported versions 45.0 through 45.3 inclusive. JDK 1.1 supported versions 45.0 through 45.65535 inclusive. When JDK 1.2 introduced support for major version 46, the only minor version supported under that major version was 0. Later JDKs continued the practice of introducing support for a new major version (47, 48, etc) but supporting only a minor version of 0 under the new major version. Finally, the introduction of preview features in Java SE 12 (see below) motivated a standard role for the minor version of the `class` file format, so JDK 12 supported minor versions of 0 *and* 65535 under major version 56. Subsequent JDKs introduce support for `N`.0 and `N`.65535 where `N` is the corresponding major version of the implemented Java SE Platform. For example, JDK 13 supports 57.0 and 57.65535.

  The Java SE Platform may define *preview features*. A Java Virtual Machine implementation which conforms to Java SE `N` (`N` ≥ 12) must support all the preview features of Java SE `N`, and none of the preview features of any other Java SE release. The implementation must by default disable the supported preview features, and must provide a way to enable all of them, and must not provide a way to enable only some of them.

  A `class` file is said to *depend on the preview features of Java SE `N`* (`N` ≥ 12) if it has a `major_version` that corresponds to Java SE `N` (according to Table 4.1-A) and a `minor_version` of 65535.

  A Java Virtual Machine implementation which conforms to Java SE `N` (`N` ≥ 12) must behave as follows:

  - A `class` file that depends on the preview features of Java SE `N` may be loaded only when the preview features of Java SE `N` are enabled.
  - A `class` file that depends on the preview features of another Java SE release must never be loaded.
  - A `class` file that does not depend on the preview features of any Java SE release may be loaded regardless of whether the preview features of Java SE `N` are enabled.

- **constant_pool_count**

  The value of the `constant_pool_count` item is equal to the number of entries in the `constant_pool` table plus one. A `constant_pool` index is considered valid if it is greater than zero and less than `constant_pool_count`, with the exception for constants of type `long` and `double` noted in [§4.4.5](4.4.5.md).

- **constant_pool[]**

  The `constant_pool` is a table of structures ([§4.4](4.4.md)) representing various string constants, class and interface names, field names, and other constants that are referred to within the `ClassFile` structure and its substructures. The format of each `constant_pool` table entry is indicated by its first "tag" byte.

  The `constant_pool` table is indexed from 1 to `constant_pool_count` - 1.

- **access_flags**

  The value of the `access_flags` item is a mask of flags used to denote access permissions to and properties of this class or interface. The interpretation of each flag, when set, is specified in Table 4.1-B.

  **Table 4.1-B. Class access and property modifiers**

  | Flag Name | Value | Interpretation |
  |---|---|---|
  | `ACC_PUBLIC` | 0x0001 | Declared `public`; may be accessed from outside its package. |
  | `ACC_FINAL` | 0x0010 | Declared `final`; no subclasses allowed. |
  | `ACC_SUPER` | 0x0020 | Treat superclass methods specially when invoked by the *invokespecial* instruction. |
  | `ACC_INTERFACE` | 0x0200 | Is an interface, not a class. |
  | `ACC_ABSTRACT` | 0x0400 | Declared `abstract`; must not be instantiated. |
  | `ACC_SYNTHETIC` | 0x1000 | Declared synthetic; not present in the source code. |
  | `ACC_ANNOTATION` | 0x2000 | Declared as an annotation type. |
  | `ACC_ENUM` | 0x4000 | Declared as an `enum` type. |
  | `ACC_MODULE` | 0x8000 | Is a module, not a class or interface. |

  The `ACC_MODULE` flag indicates that this `class` file defines a module, not a class or interface. If the `ACC_MODULE` flag is set, then special rules apply to the `class` file which are given at the end of this section. If the `ACC_MODULE` flag is not set, then the rules immediately below the current paragraph apply to the `class` file.

  An interface is distinguished by the `ACC_INTERFACE` flag being set. If the `ACC_INTERFACE` flag is not set, this `class` file defines a class, not an interface or module.

  If the `ACC_INTERFACE` flag is set, the `ACC_ABSTRACT` flag must also be set, and the `ACC_FINAL`, `ACC_SUPER`, `ACC_ENUM`, and `ACC_MODULE` flags set must not be set.

  If the `ACC_INTERFACE` flag is not set, any of the other flags in Table 4.1-B may be set except `ACC_ANNOTATION` and `ACC_MODULE`. However, such a `class` file must not have both its `ACC_FINAL` and `ACC_ABSTRACT` flags set (JLS §8.1.1.2).

  The `ACC_SUPER` flag indicates which of two alternative semantics is to be expressed by the *invokespecial* instruction ([§*invokespecial*](6.5.invokespecial.md)) if it appears in this class or interface. Compilers to the instruction set of the Java Virtual Machine should set the `ACC_SUPER` flag. In Java SE 8 and above, the Java Virtual Machine considers the `ACC_SUPER` flag to be set in every `class` file, regardless of the actual value of the flag in the `class` file and the version of the `class` file.

  The `ACC_SUPER` flag exists for backward compatibility with code compiled by older compilers for the Java programming language. Prior to JDK 1.0.2, the compiler generated `access_flags` in which the flag now representing `ACC_SUPER` had no assigned meaning, and Oracle's Java Virtual Machine implementation ignored the flag if it was set.

  The `ACC_SYNTHETIC` flag indicates that this class or interface was generated by a compiler and does not appear in source code.

  An annotation type (JLS §9.6) must have its `ACC_ANNOTATION` flag set. If the `ACC_ANNOTATION` flag is set, the `ACC_INTERFACE` flag must also be set.

  The `ACC_ENUM` flag indicates that this class or its superclass is declared as an enumerated type (JLS §8.9).

  All bits of the `access_flags` item not assigned in Table 4.1-B are reserved for future use. They should be set to zero in generated `class` files and should be ignored by Java Virtual Machine implementations.

- **this_class**

  The value of the `this_class` item must be a valid index into the `constant_pool` table. The `constant_pool` entry at that index must be a `CONSTANT_Class_info` structure ([§4.4.1](4.4.1.md)) representing the class or interface defined by this `class` file.

- **super_class**

  For a class, the value of the `super_class` item either must be zero or must be a valid index into the `constant_pool` table. If the value of the `super_class` item is nonzero, the `constant_pool` entry at that index must be a `CONSTANT_Class_info` structure representing the direct superclass of the class defined by this `class` file. Neither the direct superclass nor any of its superclasses may have the `ACC_FINAL` flag set in the `access_flags` item of its `ClassFile` structure.

  If the value of the `super_class` item is zero, then this `class` file must represent the class `Object`, the only class or interface without a direct superclass.

  For an interface, the value of the `super_class` item must always be a valid index into the `constant_pool` table. The `constant_pool` entry at that index must be a `CONSTANT_Class_info` structure representing the class `Object`.

- **interfaces_count**

  The value of the `interfaces_count` item gives the number of direct superinterfaces of this class or interface type.

- **interfaces[]**

  Each value in the `interfaces` array must be a valid index into the `constant_pool` table. The `constant_pool` entry at each value of `interfaces[i]`, where 0 ≤ *i* < `interfaces_count`, must be a `CONSTANT_Class_info` structure representing an interface that is a direct superinterface of this class or interface type, in the left-to-right order given in the source for the type.

- **fields_count**

  The value of the `fields_count` item gives the number of `field_info` structures in the `fields` table. The `field_info` structures represent all fields, both class variables and instance variables, declared by this class or interface type.

- **fields[]**

  Each value in the `fields` table must be a `field_info` structure ([§4.5](4.5.md)) giving a complete description of a field in this class or interface. The `fields` table includes only those fields that are declared by this class or interface. It does not include items representing fields that are inherited from superclasses or superinterfaces.

- **methods_count**

  The value of the `methods_count` item gives the number of `method_info` structures in the `methods` table.

- **methods[]**

  Each value in the `methods` table must be a `method_info` structure ([§4.6](4.6.md)) giving a complete description of a method in this class or interface. If neither of the `ACC_NATIVE` and `ACC_ABSTRACT` flags are set in the `access_flags` item of a `method_info` structure, the Java Virtual Machine instructions implementing the method are also supplied.

  The `method_info` structures represent all methods declared by this class or interface type, including instance methods, class methods, instance initialization methods ([§2.9.1](2.9.1.md)), and any class or interface initialization method ([§2.9.2](2.9.2.md)). The `methods` table does not include items representing methods that are inherited from superclasses or superinterfaces.

- **attributes_count**

  The value of the `attributes_count` item gives the number of attributes in the `attributes` table of this class.

- **attributes[]**

  Each value of the `attributes` table must be an `attribute_info` structure ([§4.7](4.7.md)).

  The attributes defined by this specification as appearing in the `attributes` table of a `ClassFile` structure are listed in [Table 4.7-C](4.7.md).

  The rules concerning attributes defined to appear in the `attributes` table of a `ClassFile` structure are given in [§4.7](4.7.md).

  The rules concerning non-predefined attributes in the `attributes` table of a `ClassFile` structure are given in [§4.7.1](4.7.1.md).

If the `ACC_MODULE` flag is set in the `access_flags` item, then no other flag in the `access_flags` item may be set, and the following rules apply to the rest of the `ClassFile` structure:

- `major_version`, `minor_version`: ≥ 53.0 (i.e., Java SE 9 and above)
- `this_class`: `module-info`
- `super_class`, `interfaces_count`, `fields_count`, `methods_count`: zero
- `attributes`: One `Module` attribute must be present. Except for `Module`, `ModulePackages`, `ModuleMainClass`, `InnerClasses`, `SourceFile`, `SourceDebugExtension`, `RuntimeVisibleAnnotations`, and `RuntimeInvisibleAnnotations`, none of the pre-defined attributes ([§4.7](4.7.md)) may appear.
