ClassLoaders
This directory contains text and code for the two ClassLoaders chapters, ClassLoaders
and Custom ClassLoaders.
The files FileSystemClassLoader.java,
HashtableClassLoader,
CompilerClassLoader,
StrategyClassLoader,
ClassLoaderStrategy,
CompositeClassLoader,
Service.java,
IServer.java,
and IServerManager.java
can all be found as part of the javageeks.com library.
The rest of the code is located here:
- Hello.java: The basic "Hello, world" class we keep loading from
different ClassLoaders. Note that to see some of the ClassLoaders in action, you need to delete
the Hello.class file from this directory. This file can also be found in the "subdir"
directory, for use with the FileURLClient example.
- DynamicCode.java: Demonstrates the run-time dynamic loading
facilities of Java using
Class.forName
.
- First.java, Second.java: Used to
demonstrate the DynamicCode.java example
- ReflectingDynamicCode.java: Another example of using
run-time dynamic linking, using Reflection instead of a well-known interface.
- TestSuite.java: Demonstration of using Reflection to execute
a test suite on any class that provides a public
test
method.
- FileURLClient.java, HTTPURLClient.java,
FTPURLClient.java: Examples of how to use URLClassLoader to load
the Hello.java class from a local file URL, from an HTTP URL, and from an FTP URL. Note that in
order to make this test truly succeed, you need to delete the Hello.class file from this directory
in order to guarantee that the AppClassLoader doesn't load the class.
- ClassLoadTest.java: This is the sample that demonstrates how
"Hot Deployment" (that is, loading new versions of the same class into the same VM) works. It makes
use of the LoadTest.java class, which must be edited during the
execution of the ClassLoadTest class. To do this from a Win32 Command Prompt, first start the
ClassLoadTest class executing:
C:\> start java ClassLoadTest -unique LoadTest
. This will
create a new shell window, and every 15 seconds ClassLoadTest will display some text to the window.
Once ClassLoadTest is running, cd TestDir
, where the LoadTest.class file must reside,
and call the "switch" batch file--this will change LoadTest over to the second version. Now, when
ClassLoadTest next displays output to the window, the second version of LoadTest will be
used, in conjunction with the existing first versions of LoadTest.