![]() |
VOOZH | about |
ClassNotFoundException and NoClassDefFoundError both indicate class loading failure they occur in different scenarios and have different root causes. ClassNotFoundException occurs when a class is missing at runtime while loading it dynamically through mechanisms like Class.forName. while NoClassDefFoundError appears when the class was available during compilation but cannot be found or loaded at runtime.
ClassNotFoundException is a checked exception thrown when a class is requested at runtime but the JVM cannot locate it in the classpath.
This exception appears when the class com.example.MissingClass is not present in the runtime classpath.
NoClassDefFoundError is an error thrown by the JVM when it tries to load a class that was available during compilation but is missing at runtime.
If the Helper class gets deleted from the classpath after compilation the JVM throws NoClassDefFoundError when executing the program.
| Aspect | ClassNotFoundException | NoClassDefFoundError |
|---|---|---|
| Type | Checked exception | Error |
| Thrown By | Application code | JVM |
| When It Occurs | Runtime while loading a class dynamically | Runtime when a previously available class is now missing |
| Typical Cause | Wrong or missing classpath for dynamic loading | Missing JAR or class removed after compilation |
| Common Scenarios | JDBC drivers reflection frameworks | Deployment issues, incorrect builds missing dependencies |