How Java String Constants Are Stored Inside .class Files
A visual deep-dive into how string constants are encoded in the Java constant pool — CONSTANT_Utf8, CONSTANT_String, and the ldc instruction — with hex diagrams and patching examples.
The Constant Pool
CONSTANT_Utf8 (tag = 1)
CONSTANT_String (tag = 8)
The ldc Instruction
Patching a String: Step by Step
What About Different Lengths?
Same-Length Edits Are Still Safest
Modified UTF-8: One Subtlety
Strings That Appear Multiple Times
Practical Example: Patching a Config String