Skip to content
Preptima
hardConceptScenarioMidSeniorStaff

Where does a class come from at runtime, and what is the difference between ClassNotFoundException and NoClassDefFoundError?

Loaders delegate to their parent before searching themselves, so the JDK always wins a name clash. ClassNotFoundException means a loader was asked for bytes it could not find; NoClassDefFoundError means the JVM needed a class that was there at compile time, or one whose static initialiser had already failed.

6 min readUpdated 2026-08-15

Answer

Short answer

ClassLoader delegation means a loader asks its parent first, so class identity depends on both the fully qualified class name and the defining loader. ClassNotFoundException means loading failed when requested, while NoClassDefFoundError usually means a class that was present at compile time cannot be resolved or initialized at runtime.

Was this answer helpful?

Likely follow-ups

  • Two modules load the same class file and a cast between them fails. What is happening?
  • Why does reading a static final int constant not initialise the class that declares it?
  • Which of Class.forName and loadClass runs the static initialiser?
  • Why do repeated hot redeploys exhaust Metaspace rather than the heap?

Related questions

Further reading