Class loading and class loaders
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
explain the three class-loading phases and the loader hierarchy.
Planned topics
- Phases: loading (read bytes), linking (verify, prepare, resolve), initialization (run static initializers).
- Hierarchy: bootstrap (core JDK), platform, application loader; each delegates to its parent first.
- Delegation prevents user code from replacing
java.lang.String. ClassNotFoundException: a checked exception when code asks for a class by name and it is not found.NoClassDefFoundError: the class was present at compile time but is missing, or failed to initialize, at runtime.- Frameworks and app servers use custom loaders for isolation.
Draft outline details
Demonstration
System.out.println(Shop.class.getClassLoader()); // application loader
System.out.println(String.class.getClassLoader()); // null = bootstrapCheck your understanding
Which one is an Error raised during linking or use: ClassNotFoundException or NoClassDefFoundError?
Show answer
NoClassDefFoundError.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.