JVM & runtime · interview question
Put the phases a class goes through before it can be used in order.
OrderingHard
Put the items in the correct order.
- Resolution (turn symbolic references into direct references)
- Initialization (run static initializers and field assignments)
- Preparation (allocate static fields with default values)
- Loading (find and read the class file)
- Verification (check the bytecode is valid and safe)
Answer and explanation
Correct answer
1. Loading (find and read the class file)
2. Verification (check the bytecode is valid and safe)
3. Preparation (allocate static fields with default values)
4. Resolution (turn symbolic references into direct references)
5. Initialization (run static initializers and field assignments)
Why
Verification, preparation and resolution together make up linking. Resolution may happen lazily, but it's specified as part of linking, before initialization. Initialization runs the class's <clinit>.
Test yourself on JVM & runtime
A free test with instant, explained results. No account needed.