Java / JVM Architecture (Java21) Interview questions
Explain the internal working of the linking phase (verification, preparation, resolution)?
Verification runs the bytecode through the JVM's structural checks - stack map validation, type safety of operations, and ensuring branches only jump to valid instructions - so that malformed or maliciously crafted class files are rejected before they can run.
Preparation then allocates memory for the class's static fields and sets them to their type's default value (0, null, false), not the values written in source code - those come later.
Resolution converts symbolic references in the constant pool, names of other classes, fields, and methods, into direct references the JVM can use without repeated name lookups. HotSpot mostly resolves these lazily, on first actual use of a given reference, rather than resolving everything up front.
Only after all three sub-phases complete for a class does initialization run and assign the real, source-specified static values.
More Related questions...