Difference between NoClassDefFoundError and ClassNotFoundException?

ClassNotFoundException vs NoClassDefFoundError in Java

1- Both are related to class not found at runtime
2-Both are related to imported class which are unresolvable at Runtime.


ClassNotFoundException

1- You want to use some class or want to load it, and it all because of you,

    you can load any class by these ways
    1-Class.forName()
    2-ClassLoader.loadClass()
        3-ClassLoader.findSystemClass()

These all checks in the ClassPath but could not find the class and throws ClassNotFoundException
it may be due to the precedence of classpath
ClassPath Defined in jar manifestwill take the more precedence then defined in the classpath 

2-This is a checked Exception directly from java.lang.Exception
need to provide the explicit handling or throws exception

NoClassDefFoundError in Java

This is just so bad because class present at compile time but so anonymous power make it unavailable at RunTime 
Reason for this-
1- code deployed on 2 JVM and when you deploy your new code to one JVM and if the request goes to your previous JVM this error occur only if you includes some new JAR's

2-You are using 2 Class loader and class loaded by one will not be available for other

Comments