The constant pool
Every name, type, string and number a class uses is stored once in its constant pool, and everything else refers to it by index. These are its 17 kinds of entry.
The constant pool comes right after the version numbers and is usually the largest part of a class file: across JDK 25.0.5's java.base it averages 143 entries a class, the biggest has 6,004 (sun.util.resources.cldr.LocaleNames_en). Entries are numbered from 1; index 0 means "none" (a class with no superclass has super_class 0). Each starts with a one-byte tag that says what kind it is and so how long it is, which is why the pool has to be read in order from the start.
Entries build on each other. A call such as System.out.println("hi") touches a Fieldref (class System, field out), a Methodref (class PrintStream, method println), two NameAndTypes, two Classes and a String, all ending in Utf8 text. The viewer shows every reference as a link.
| Tag | Kind | Since | Size | ldc | In java.base | What it is |
|---|---|---|---|---|---|---|
| 1 | Utf8 | Java 1.0 | variable | 603,262 | Most of a class file is Utf8 entries: class names, member names, descriptors, string contents, attribute names. | |
| 3 | Integer | Java 1.0 | 5 bytes | yes | 10,819 | An int constant. |
| 4 | Float | Java 1.0 | 5 bytes | yes | 100 | A float constant. |
| 5 | Long | Java 1.0 | 9 bytes | yes | 4,374 | A long constant, loaded with ldc2_w. |
| 6 | Double | Java 1.0 | 9 bytes | yes | 1,435 | A double constant, loaded with ldc2_w. |
| 7 | Class | Java 1.0 | 3 bytes | yes | 84,644 | A class or interface, by its internal name: dots become slashes. |
| 8 | String | Java 1.0 | 3 bytes | yes | 59,564 | A java.lang.String literal. |
| 9 | Fieldref | Java 1.0 | 5 bytes | 35,942 | A reference to a field. | |
| 10 | Methodref | Java 1.0 | 5 bytes | 98,719 | A reference to a method of a class. | |
| 11 | InterfaceMethodref | Java 1.0 | 5 bytes | 14,940 | A reference to a method of an interface. | |
| 12 | NameAndType | Java 1.0 | 5 bytes | 139,071 | A member's name and type without its class. | |
| 15 | MethodHandle | Java 7 | 4 bytes | yes | 2,634 | A handle to a field or method, with a kind that says how to use it. |
| 16 | MethodType | Java 7 | 3 bytes | yes | 1,699 | A method descriptor as a value: loads as a java.lang.invoke.MethodType. |
| 17 | Dynamic | Java 11 | 5 bytes | yes | 0 | A constant whose value a bootstrap method computes the first time it is loaded, and which then never changes ("condy", constant dynamic). |
| 18 | InvokeDynamic | Java 7 | 5 bytes | 2,143 | A call site for invokedynamic: which bootstrap method links it and the call's name and type. | |
| 19 | Module | Java 9 | 3 bytes | 67 | A module's name. | |
| 20 | Package | Java 9 | 3 bytes | 196 | A package exported or opened by a module, by its internal name (demo/api). |
Tags 2, 13 and 14 are unused. Long and Double entries take two slots each, so the index after one is never valid, and constant_pool_count is one more than the highest index rather than the number of entries.
Specification: JVMS §4.4, The Constant Pool.