CONSTANT_Utf8 tag 1
Most of a class file is Utf8 entries: class names, member names, descriptors, string contents, attribute names.
- Tag
1- Since
- class file 45.0 (Java 1.0)
- Size
- variable
- Loadable
- no
- Referred to by
- Class, String, NameAndType, MethodType, Module and Package entries
- every attribute's name
- member names and descriptors
Layout
| Type | Field | What it holds |
|---|---|---|
u1 | tag | 1 |
u2 | length | number of bytes (not characters) |
u1[length] | bytes | the text, in modified UTF-8 |
What it is for
Most of a class file is Utf8 entries: class names, member names, descriptors, string contents, attribute names. In JDK 25's java.base, more than half of all constants are Utf8.
"Modified" UTF-8 differs from standard UTF-8 in two ways: the NUL character is written as two bytes (C0 80) so the bytes never contain a zero, and characters outside the Basic Multilingual Plane are written as a surrogate pair, three bytes each, instead of one four-byte sequence. The length is a u2, so one constant holds at most 65,535 bytes, which is why a huge string literal fails to compile.
How common it is
JDK 25.0.5's java.base has 603,262 Utf8 constants in 7,391 of its 7,391 classes: 56.9% of all 1,059,609 constants.
A real one, byte by byte
Constant #4 of Hello.class, compiled by javac 25:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 23 | 19 bytes | #4 Utf8 | "java/lang/Object" |
| 23 | 01 | tag | 1 (Utf8) |
| 24 | 00 10 | length | 16 |
| 26 | 6a 61 76 61 2f 6c 61 6e 67 2f 4f 62 … | bytes | "java/lang/Object" |
Specification: JVMS §4.4, CONSTANT_Utf8_info (Java SE 25).