Static class loading
Classes are statically loaded with Java’s "new" operator.
Car c = new Car();
A NoClassDefFoundException is thrown if the runtime system cannot find the referenced class.
Dynamic class loading
It is invoking the functions of a classloader at run time.
Class.forName(String className); // returns a Class
It returns class object associated with the class name dynamically at run time.
Once the class is dynamically loaded the following method returns an instance of the loaded class.
It’s just like creating a class object with no arguments.
String myClassName = "au.com.Jeep" ;
Class vehicleClass = Class.forName("com.my.Jeep") ;
Jeep myJeep = (Jeep) vehicleClass.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 :
Class.forName(..)
ClassLoader.findSystemClass(..)
ClassLoader.loadClass(..)
No comments:
Post a Comment
Note: only a member of this blog may post a comment.