8.2 Loading Classes without a Class Loader

Some classes are loaded without a class loader. (You knew that there had to be at least one such class, since the first class loader couldn't load itself!) These classes are called system classes.

The virtual machine has a built-in way to load classes independent of the ClassLoader class. It varies from implementation to implementation, but one common way is to use an environment variable called CLASSPATH to contain a list of directories. When loading the class named name, the system looks for a file called name.class in each directory in the CLASSPATH, treating each period-separated part of the package name as a subdirectory. Once a file is found, the loading and linking proceeds the same way it does for a class loaded with a class loader.

Array classes are also loaded without a class loader. An array is an object and must have a class. However, there's no need to locate a definition for the class, since all the properties of an array class are known just from its name. The JVM constructs this class internally.

If you have a class named foo, then an array of these objects is called [foo. When the system sees a name like this, it internally creates a class definition for an array of foo. Of course, foo may be an array itself. This class extends java.lang.Object and defines no methods or fields of its own.

Programming for the Java Virtual Machine
Programming for the Javaв„ў Virtual Machine
ISBN: 0201309726
EAN: 2147483647
Year: 1998
Pages: 158
Authors: Joshua Engel

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net