5.2. Custom Class Loaders

The rules for writing class loaders have changed over time, but the principle has remained basically the same. You implement a subclass of ClassLoader that knows, given a class name, how to create or find a byte array that is the class bytes for that class.

5.2.1. Pre-Java 2 Custom Class Loaders

Prior to SDK version 1.2, the relevant methods were loadClass, define-Class, and resolveClass, as shown in Listing 5-4. To implement a custom loader, you override the abstract method loadClass. Using the name argument, you find or create an array of bytes that has the correct binary class format, and then you pass these bytes to the defineClass method. ClassLoader's defineClass implementation then calls to native code inside ...

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.