What are the differences between NoClassDefFoundError and ClassNotFoundException?

NoClassDefFoundError occurs when a class was found during compilation but could not be located in the classpath while executing the program.
For example: class A invokes method from class B and both compile fine but before executing the program, an ANT script deleted B.class by mistake. Now on executing the program NoClassDefFoundError is thrown.


ClassNotFoundException occurs when a class is not found while dynamically loading a class using the class loaders.


For example: The database driver is not found when trying to load the driver using Class.forName() method.


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email