ClassLoader in Java

it works on 3 principle 
1- Uniqueness
load the class only once which can be done through delegation
Ensure that it only load once if the class is loaded by child class loader if it is not loaded by parent classLoader
2- Delegation
Forward the request of class loads the class if the parent class loader is not able to load the class
3- Visibility
allows child class loader to see all the classes loaded by parent ClassLoader, but parent class loader can not see classes loaded by child.

Every ClassLoader has the preDefined Location
There are three default class loader used in Java,
1-Bootstrap
Bootstrap ClassLoader is responsible for loading standard JDK class files from rt.jar and it is parent of all class loaders in Java. Bootstrap class loader don't have any parents
2-Extension - delegates the class loading to its parents Bootstrap  if unsuccessful load from directory defined  jre/lib/ext -- other library
3- System or Application class loader -- defaults loads from classPatha

classNotFoundException - when classLoader fails to load the class -- with explicitly Class.forName();

So, it appears that the NoClassDefFoundError occurs when the source was successfully compiled, but at runtime, the required class files were not found. This may be something that can happen in the distribution or production of JAR files, where not all the required class files were included.

As for ClassNotFoundException, it appears that it may stem from trying to make reflective calls to classes at runtime, but the classes the program is trying to call is does not exist.

Comments