Bytecode, linking and initialization
Definition:
Bytecode is the JVM instruction format emitted by javac.
Explanation:
javac resolves language-level types and writes class files.
Illustration image:
Example:
javac Example.java
javap -c -v Example
java -Xlog:class+load=info,class+init=info ExampleExpected behavior. Compare when a type is loaded and when it initializes; the logging flags are for modern HotSpot, available on Java 17 and 21.
Internal working:
Class loading finds bytes and defines a class; linking verifies them, prepares static storage and resolves symbolic references when required. Initialization executes static initializers. Reading a compile-time constant may leave the declaring class uninitialized because callers can inline it. A binary-compatible-looking constant change can therefore require recompiling callers.
Interview questions:
Why can reading a static final constant skip initialization?
A compile-time constant can be copied into the caller’s bytecode; no active use of the declaring class is required.