2.3. Explicit and Implicit Class Loading
The simplest class loading API is provided by the ClassLoader class shown in Listing 2-2.
Listing 2-2. Explict Loading with ClassLoader
package java.lang; public class ClassLoader { public Class loadClass(String n) throws ClassNotFoundException; //remainder omitted for clarity } |
This is fairly straightforward. You pass in the full name of the class, delimiting packages with dots, and you get back a distinguished Class object that represents the loaded class. If the class loader fails, it throws the checked ClassNotFoundException.
2.3.1. Explicit Loading with URLClassLoader
The easiest way to see loadClass in action is to use a concrete ClassLoader implementation provided by the core API. By far, the ...
Get Component Development for the Java™ Platform now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.