Static class loading:
Classes are statically loaded with Java’s new operator.
Car c= new Car();
A NoClassDefFoundException is thrown if a class is referenced with Java new operator but the runtime system cannot find the referenced class.
Dynamic class loading:
Dynamic loading is a technique for programatically invoking the function of a class loader at runtime. Done by
Class.forName(String className);
The above static method returns the class object associated with the class name.Unlike the static loading the dynamic loading will decide whether to load the class Car or Jeep.Once the class is dynamically loaded the following method reutnrs an instance of the loaded class.It’s just like creating a class object with no arguments.
class.newInstance();
A classNotFoundException is thrown when an application tries to load in a class through its string name using the following methods but no definition for the class with the specified name could be found:
forName() method in class – Class
findSystemClass() method in class – ClassLoader.
loadClass() method in class – ClassLoader.