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

TypeFieldWhat it holds
u1tag1
u2lengthnumber of bytes (not characters)
u1[length]bytesthe 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:

OffsetBytesFieldValue
2319 bytes#4 Utf8"java/lang/Object"
2301tag1 (Utf8)
2400 10length16
266a 61 76 61 2f 6c 61 6e 67 2f 4f 62 …bytes"java/lang/Object"

Open in the viewer

Specification: JVMS §4.4, CONSTANT_Utf8_info (Java SE 25).