ClassNotFoundException and NoClassDefFoundError - Similarity and Difference


It's frequently asked interview question.

Similarity

Both errors result due to unavailability of class files during runtime and are related to classpath problems.

Difference

ClassNotFoundException comes up when there is an explicit loading of class is involved by providing name of class at runtime using ClassLoader.loadClass, Class.forName while NoClassDefFoundError is a result of implicit loading of class because of a method call from that class or any variable access.