The difference from the Java API Specifications is as follows.
Thrown when an application tries to load in a class through its string name using:
- The
forName
method in classClass
.- The
findSystemClass
method in classClassLoader
.- The
loadClass
method in classClassLoader
.but no definition for the class with the specified name could be found.
This exception also occurs when you have two class loaders and if a ClassLoader tries to access a class which is loaded by another classloader in Java. You must be wondering that what actually is classloader in Java. Java ClassLoader is a part of Java Runtime Environment that dynamically loads Java classes in JVM(Java Virtual Machine). The Java Runtime System does not need to know about files and files system because of classloaders.
For
For
NoClassDefFoundError
:NoClassDefFoundError occurs when class was present during compile time and program was compiled and linked successfully but class was not present during runtime. It is error which is derived from LinkageError. Linkage error occurs when a class has some dependencies on another class and latter class changes after compilation of former class. NoClassFoundError is the result of implicit loading of class because of calling a method or accessing a variable from that class. This error is more difficult to debug and find the reason why this error occurred. So in this case you should always check the classes which are dependent on this class.Thrown if the Java Virtual Machine or aClassLoader
instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
ClassNotFoundException
|
NoClassDefFoundError
|
It is an exception. It is of type java.lang.Exception.
|
It is an error. It is of type java.lang.Error.
|
It occurs when an application tries to load a class at run time which is not updated in the classpath.
|
It occurs when java runtime system doesn’t find a class definition, which is present at compile time, but missing at run time.
|
It is thrown by the application itself. It is thrown by the methods like Class.forName(), loadClass() and findSystemClass().
|
It is thrown by the Java Runtime System.
|
It occurs when classpath is not updated with required JAR files.
|
It occurs when required class definition is missing at runtime.
|
ClassNotFoundException | NoClassDefFoundError |
It is an exception. It is of type java.lang.Exception. | It is an error. It is of type java.lang.Error. |
It occurs when an application tries to load a class at run time which is not updated in the classpath. | It occurs when java runtime system doesn’t find a class definition, which is present at compile time, but missing at run time. |
It is thrown by the application itself. It is thrown by the methods like Class.forName(), loadClass() and findSystemClass(). | It is thrown by the Java Runtime System. |
It occurs when classpath is not updated with required JAR files. | It occurs when required class definition is missing at run time |
Comments
Post a Comment