JAVA Class Loader section 14th
Today we will load the first phase of the class loading mechanism in 5 stages, also called loading . In order to read the good distinction, the following is called loading.
The first step in loading is to get a binary byte stream, which can be obtained from a read. class file, or it can receive a stream of bytes sent from someone else on the network. Anyway, you can enter this phase as long as the virtual machine's specified byte stream format is met.
With the byte stream, you need a tool to load and that is the loader. The loader can either use the system-provided boot class loader, or the user can define the loader himself, simply inherit the ClassLoader, and then rewrite the LoadClass () method to implement a simple loader of its own.
Just like the code above, it's a simple classloader. When we want to load a class by ourselves, we can call the LoadClass method, which is usually the full class name of the class to be loaded, and then the file is obtained by name, and then the byte stream can be loaded.
In general, we are not going to implement the loader ourselves, all using the system default loader. Most Java programs use the following 3 types of loaders available to the system:
Bootstrap ClassLoader: Starts the class loader. Responsible for loading all classes (such as: Rt.jar) that can be identified by the virtual machine in the java_home/lib/. cannot be referenced directly by Java programs, implemented by C + +, not classloader subclasses.
Extension ClassLoader: Extension class loader. Some jar packages that are responsible for loading the extensions in the Java platform, including all class libraries in the java_home/lib/ext/directory or java.ext.dirs system variables under the specified directory. is a subclass of Classload, and developers can use the loader directly.
App ClassLoader: Application class loader. Responsible for loading the jar package specified in Classpath and the class in the directory. The return value of Getsystemclassloader () is the loader, which the developer can use directly.
Get to know these points today, and tomorrow we'll talk about how virtual machines work together with these loads.
For the code just above, the small partner can try to write on their own. The byte stream can be read from a file, can also be obtained through the network, obtained after loading, and then by Reflection execution LoadClass () The associated method of the returned object.
JAVA Class Loader section 14th