Sponsored Link •
Java's architecture enables you to write programs that dynamically extend themselves at runtime. Java programs can dynamically extend themselves by choosing at runtime classes and interfaces to load and use.
Looked at another way, dynamic extension means that at compile time, you don't necessarily need to know about all the classes and interfaces your program will use at runtime. In fact, some of those classes and interfaces may not even exist when you do your compile.
Java has two ways to do dynamic extension:
forName(), a static method in
java.lang.Class, is the simple, straightforward way to do
dynamic extension. Class loaders, subclasses of
java.lang.ClassLoader, are the more complicated (and more
powerful) way to do dynamic extension.
In a Java program that uses dynamic extension, irrespective of whether
forName() or class loaders or both, names of types
(classes and interfaces) will be passed around in the program as
Strings. To request a certain class be loaded, the program
will pass as a
String the fully qualified name of the
desired type to
forName() or the class loader. Because the
type name is handed to
forname() or the class loader as a
String at runtime, the program can be written such that
the actual contents of the
Strings (the names of the types
your program will load at runtime via dynamic extension) are not known
at compile time.