The 1.1-Based Class Loader

We’ll take a bottom up approach in this example, so we’ll start with the class loader. In 1.1, writing a class loader means extending the ClassLoader class and overriding its loadClass( ) method to provide the necessary semantics.

The implementation that we’ll use follows the same steps as we listed in Chapter 6. However, some of those steps rely on methods of the class loader that we haven’t yet examined. In Java 2, these methods aren’t used because they’re called automatically by the loadClass( ) method; in 1.1, you’re responsible for calling the following methods:

protected final Class findSystemClass(String name)

Attempt to find the named class by using the internal class loader to search the user’s classpath and the core JDK classes (classes.zip). If the system class is not found, a ClassNotFoundException is generated. This accomplishes a similar task as deferring to the parent class loader does in Java 2 (although the Java 2 mechanism is much more flexible).

protected final Class findLoadedClass(String name)

Find the class object for a class previously loaded by this class loader. This method returns null if it cannot find the given class.

protected final void resolveClass(Class c)

For a given class, resolve all the immediately needed class references for the class; this will result in recursively calling the class loader to ask it to load the referenced class.

In addition to implementing the loadClass( ) method, we need our class loader to provide ...

Get Java Security, 2nd Edition 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.