Monday, May 23, 2016


ClassNotFoundException vs NoClassDefFoundError


Though both of these errors are related to missing classes in the classpath, the main difference between them is their root cause.

ClassNotFoundExcpetion comes when you try to load a class at runtime by using Class.forName() or loadClass() and requested class is not present

in classpath for example when you try to load MySQL or Oracle driver class and their JAR is not available, while in case of

NoClassDefFoundError requested class was present at compile time but not available at runtime. Sometimes due to an exception during class

initialization e.g. exception from static block causes NoClassDefFoundError when a failed-to-load class was later referenced by the runtime

for more details

No comments:

Post a Comment