1, runtime type information (RTTI) allows you to discover and use type information while a
program is running.
2, the class object;
to understand how RTTI works in Java, you must first know how type information is
represented at run time. this is accomplished through a special kind of object called the class
object, which contains information about the class. in fact, the class object is used to create all
of the "regular" objects of your class. java performs its RTTI using the class object, even
if you're doing something like a cast. the class Class also has a number of other ways you
can use RTTI.
there's one Class object for each class that is part of your program.
all classes are loaded into the JVM dynamically, upon the first use of a class. this happens
when the program makes the first reference to a static member of that class. it turns out that
the constructor is also a static method of a class, even though the static keyword is not used for
a constructor. therefor, creating a new object of that class using the new operatior also counts as a
reference to a static member of the class.
the call to static Class.forName() is being made for its side effect, which is to load the classs
if it isn't already loaded.
there are actually three steps in preparing a class for use:
1), loading, which is performed by the class loader. this finds the bytecodes (usually, but not
necessarily, on your disk in your classpath) and creates a Class object from those bytecodes.
2), linking, the link phase verifies the bytecodes in the class, allocates storage for static fields,
and if necessary, resolves all references to other classes made by this class.
3), initialization. if there's a superclass, initialize that. execute static initializers and static initialization
blocks.
if a static final value is a "compile-time constant", that value can be read without casing the
class to be initialized. making a field static and final, however, does not guarantee this behavior:
because it cannot be a compile-time constant.
if a static field is not final, accessing it always requires linking ( to allocate storage for the field)
and initializaion (to initiaalize that storage) before it can be read.