Difference between ClassNotFoundException and NoClassDefFoundError in java ?

  • ClassNotFoundException and NoClassDefFoundError occur when a particular class is not found at runtime. However, they occur at different scenarios.
  • ClassNotFoundException is an exception that occurs when you try to load a class at run time using Class.forName() or loadClass() methods and mentioned classes are not found in the classpath.
  • NoClassDefFoundError is an error that occurs when a particular class is present at compile time, but was missing at run time.
NoClassDefFoundError ClassNotFoundException
NoClassDefFoundError is an error. It is the type of
java.lang.Error.
ClassNotFoundException is an exception. It is the type of java.lang.Exception.
It occurs when java runtime system doesn’t
find a class definition, which is present at compile time,
but missing at run time.
It occurs when an application tries to load a class at run time which is not updated in the classpath.
It is thrown by the Java Runtime System. It is thrown by the application itself. It is thrown by the methods like Class.forName(), loadClass() and findSystemClass().
It occurs when required class definition is missing
at runtime.
It occurs when classpath is not updated wih required JAR files.

Categorized in:

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,