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

# Chapter 4. The `class` File Format

This chapter describes the `class` file format of the Java Virtual Machine. Each `class` file contains the definition of a single class, interface, or module. Although a class, interface, or module need not have an external representation literally contained in a file (for instance, because the class is generated by a class loader), we will colloquially refer to any valid representation of a class, interface, or module as being in the `class` file format.

A `class` file consists of a stream of 8-bit bytes. 16-bit and 32-bit quantities are constructed by reading in two and four consecutive 8-bit bytes, respectively. Multibyte data items are always stored in big-endian order, where the high bytes come first. This chapter defines the data types `u1`, `u2`, and `u4` to represent an unsigned one-, two-, or four-byte quantity, respectively.

In the Java SE Platform API, the `class` file format is supported by interfaces `java.io.DataInput` and `java.io.DataOutput` and classes such as `java.io.DataInputStream` and `java.io.DataOutputStream`. For example, values of the types `u1`, `u2`, and `u4` may be read by methods such as `readUnsignedByte`, `readUnsignedShort`, and `readInt` of the interface `java.io.DataInput`.

This chapter presents the `class` file format using pseudostructures written in a C-like structure notation. To avoid confusion with the fields of classes and class instances, etc., the contents of the structures describing the `class` file format are referred to as *items*. Successive items are stored in the `class` file sequentially, without padding or alignment.

*Tables*, consisting of zero or more variable-sized items, are used in several `class` file structures. Although we use C-like array syntax to refer to table items, the fact that tables are streams of varying-sized structures means that it is not possible to translate a table index directly to a byte offset into the table.

Where we refer to a data structure as an *array*, it consists of zero or more contiguous fixed-sized items and can be indexed like an array.

Reference to an ASCII character in this chapter should be interpreted to mean the Unicode code point corresponding to the ASCII character.

**Sections:**

- [4.1. The ClassFile Structure](4.1.md)
- [4.2. Names](4.2.md)
- [4.3. Descriptors](4.3.md)
- [4.4. The Constant Pool](4.4.md)
- [4.5. Fields](4.5.md)
- [4.6. Methods](4.6.md)
- [4.7. Attributes](4.7.md)
- [4.8. Format Checking](4.8.md)
- [4.9. Constraints on Java Virtual Machine Code](4.9.md)
- [4.10. Verification of class Files](4.10.md)
- [4.11. Limitations of the Java Virtual Machine](4.11.md)
