CONSTANT_String tag 8
A java.lang.String literal.
- Tag
8- Since
- class file 45.0 (Java 1.0)
- Size
- 3 bytes
- Loadable
- yes, with
ldc,ldc_w - Referred to by
- ldc and ldc_w
- ConstantValue of String fields
- bootstrap method arguments
Layout
| Type | Field | What it holds |
|---|---|---|
u1 | tag | 8 |
u2 | string_index | a Utf8 with the string's contents |
What it is for
A java.lang.String literal. ldc of it pushes an interned String: every class that uses the same literal gets the same object, which is why "a" == "a" is true.
The String entry only points at the Utf8 that holds the text. The same Utf8 can also serve as a name elsewhere in the file.
Compile-time constant expressions are folded first: "limit" + " exceeded" with constant operands becomes one String constant.
How common it is
JDK 25.0.5's java.base has 59,564 String constants in 3,477 of its 7,391 classes: 5.6% of all 1,059,609 constants.
A real one, byte by byte
Constant #7 of Hello.class, compiled by javac 25:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 57 | 3 bytes | #7 String | world |
| 57 | 08 | tag | 8 (String) |
| 58 | 00 08 | string_index | #8 |
Specification: JVMS §4.4, CONSTANT_String_info (Java SE 25).