surface seems can’t find the abnormal, but specific what difference?
As their name suggests: NoClassDefFoundError is an Error, and ClassNotFoundException is an exception.
there is a difference between errors and anomalies in Java, we can recover from abnormal program but it should not be trying to recover from errors,
that is the Exception we can use the try… The catch… If an Error occurs, we cannot resume normal execution of the program.
ClassNotFoundException:
ClassNotFoundException is usually exposed at compile time, but can also occur at run time because of Java’s reflection and dynamic loading of classes. Java supports dynamically loading classes using the Class.forName method. Passing the Class name of any Class as an argument to the method will cause the Class to be loaded into the JVM memory. If the Class is not found in the classpath, then a ClassNotFoundException is thrown at runtime.
1) Missing JAR package.
1) missing JAR package.
2) There is no shortage of JARs, dependencies conflict, and dynamic loading (especially in frameworks such as Spring/Dubbo) can also occur.
3) There is no shortage of JARs and no conflicting dependencies, but class isolation is still possible (for example, there is a custom ClassLoader during framework execution that breaks the parental delegate mechanism), as is the Tomcat container.
NoClassDefFoundError:
ClassDefFoundError is not due to missing packages or class conflicts, but rather class initialization failure.
If the JVM or ClassLoader instance tries to load a class (either through normal method calls, or by using new to create new objects), the class definition is not found. The class you are looking for exists at compile time but cannot be found at run time. The error is when you use the new operator to create a new object but cannot find the corresponding class for that object. This will result in a NoClassDefFoundError. Since the NoClassDefFoundError is caused by a JVM, you should not attempt to catch this error.
1) private member variable initialization failed.
1) private member variable initialization failed.
2) Static member variable initialization failed.
3) Static code block execution exception…