Java Reference
In-Depth Information
16.13. Loading Classes
The runtime system loads classes when they are needed. Details of load-
ing classes vary between implementations, but most of them use a class
path mechanism to search for a class referenced by your code but not
yet loaded into the runtime system. The class path is a list of places in
which the system looks for class files. This default mechanism works well
in many cases, but much of the power of the Java virtual machine is its
ability to load classes from places that make sense to your application.
To write an application that loads classes in ways different from the de-
fault mechanism, you must provide a ClassLoader object that can get the
bytecodes for class implementations and load them into the runtime sys-
tem.
For example, you might set up a game so that any player could write a
class to play the game using whatever strategy the player chooses. The
design would look something like this:
To make this work, you would provide a Player abstract class that players
would extend to implement their strategy. When players were ready to
try their strategy, they would send the compiled class's bytecodes to your
system. The bytecodes would need to be loaded into the game and the
 
Search WWH ::




Custom Search