Skip to content
Ameen Abozaid
Planned lessonMID-001-L02

Class loading and class loaders

  • Lesson 2 of 6
  • Mid-level
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

java
System.out.println(Shop.class.getClassLoader());   // application loader
System.out.println(String.class.getClassLoader()); // null = bootstrap

Check 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.