There are some minor complications dealing with chaining ClassLoaders so they ask other ClassLoaders first before going to look on their own.
The default ClassLoader can drive you nuts. Sometimes it refuses to look on the local hard disk CLASSPATH. It won’t look in a jar other than the ones mentioned in the <APPLET ARCHIVE ones. These archives are downloaded en masse whether you need the files in them or not. The ClassLoader/Security system won’t let net-loaded classes use pre-installed local DLLs. Unsigned Applets cannot use custom ClassLoaders.
Why would you ever want a custom ClassLoader?
java.lang.ClassLoader.defineClass( String name, byte[] b, int off, int len ) // returns an instance of a class defined by the byte[].
With a new ClassLoader, you can load a different version of a class. The old objects continue to use the old code. New objects use the new code. A given ClassLoader can load a given class only once. There is no need to unload a class. When the objects using it are no longer referenced, the class object itself, along with the code, will be garbage collected. The same classes, loaded by different class loaders are considered distinct classes. They are not instanceofs each other!
You will have to instantiate a new ClassLoader every time you have a new generation of classes. You can load all the replacement classes of a generation with the same ClassLoader. However, when you want to replace the replaced classes, you need a yet another new ClassLoader. You can do this with multiple instances of the same ClassLoader. You only need to write one ClassLoader, perhaps not even one, not one for each generation.
Have a look at the java.net.URLClassLoader. You may find for your given problem you don’t even have to write whole new ClassLoader, just instantiate one of Sun’s.
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.18] | The information on this page is for non-military use only. | ||
| You are visitor number 29,307. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/Mindprod website mirror) | ||
| http://mindprod.com/jgloss/classloader.html | J:\mindprod\jgloss\classloader.html | ||