Java ClassLoader is used to load the classes at run time. In other words, JVM performs the linking process at runtime. Classes are loaded into the JVM according to need.
loadClass(String name, boolean resolve): This method is used to load the classes which are referenced by the JVM. It takes the name of the class as a parameter. This is of type loadClass(String, boolean). defineClass(): The defineClass() method is a final method and cannot be overriden.
From the Javadocs for the URLClassLoader(URL[])
constructor:
Constructs a new URLClassLoader for the specified URLs using the default delegation parent ClassLoader. The URLs will be searched in the order specified for classes and resources after first searching in the parent class loader. Any URL that ends with a '/' is assumed to refer to a directory. Otherwise, the URL is assumed to refer to a JAR file which will be downloaded and opened as needed.
So you have two options:
(1) is easier in this case, but (2) can be handy if you're using networked resources.
You must provide the directories or the jar files containing your .class files to the URLClassLoader:
classUrl = new URL("file:///home/kent/eclipsews/SmallExample/bin/");
And yes, you can load as many classes as you like
You have to load the class by giving the fully qualified class name that is class name with with its package path as,
Class c = ucl.loadClass("com.mypackage.IndependentClass");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With