Java class loader acquaintance

The basic concept class loader

Class loader (class loader) loads Java classes for the Java virtual machine. In general, Java Virtual Machine using Java classes as follows: Java source (.java files) are converted into Java byte code (.class files) After Java compiler.

Class loader is responsible for reading Java byte code, and converted into an instance of class java.lang.Class. Each such instance of a Java class is used to represent. By this example newInstance () method can be used to create an object of that class. The actual situation may be more complex, such as Java byte code may be dynamically generated by the tool, or it may be downloaded through the network.

Substantially all of the class loader is an instance of class java.lang.ClassLoader.

Parents delegate class loading mechanism

JVM default when loading the class uses a parent delegate mechanism. Popular speaking, is a particular class loader to load a class, upon request, first loading the task entrusted to the parent class loader, in turn recursion, if the parent class loader class loader can complete the task successfully return; only the parent class loader can not complete this task load, load it themselves.

java.lang.ClassLoader类

Java.lang.ClassLoader basic duty class is based on the name of a specific class, to find or generate the corresponding byte code, and define a Java bytecode from these classes, namely a class java.lang.Class instance. In addition, ClassLoader is also responsible for the resources required to load Java applications, such as image files and configuration files.

Java class loader Category

The Java class loader can be divided into two categories, one is a system provided by another class is a Java application developers to write.

The system provides three main class loader

  • Bootstrap class loader (bootstrap class loader): It is used to load Java core library, native code is implemented, it is not inherited from java.lang.ClassLoader.
  • Extension class loader (extensions class loader): It is used to load a Java extension library. Implementation of the Java Virtual Machine will provide an extensive library directory. This class loader to find and load Java classes in this directory.
  • System class loader (system class loader): It is the Java class according to the class to load Java application path (CLASSPATH). In general, class Java applications are made to complete it loaded. You can get it by ClassLoader.getSystemClassLoader ().

Guess you like

Origin www.cnblogs.com/zxfei/p/11520513.html