ClassLoader related content

Source: Internet
Author: User

1, what is called Bootstrap? As adjectives have their own strength, and so on, in our computer world, we generally refer to bootstrap, guide, and boot programs.

So what is Bootstrapclassloader? It is the bootloader, the most primitive loader, what does it do? It is responsible for loading the entire Java core class.

What is its parent class? It is not a parent class, it is created by the JVM

Java provides dynamic loading characteristics, which are loaded and linked at runtime at the first reference to a class, rather than at compile time. The class loader for the JVM is responsible for dynamic loading. The Java class loader has the following features:

public static void Main (string[] args) {
Java.net.url[] Urls=sun.misc.launcher.getbootstrapclasspath (). Geturls ();
for (int i = 0; i < urls.length; i++) {
System.out.println (Urls[i]);
}

File:/d:/program%20files/java/jdk1.6.0_23/jre/lib/resources.jar
File:/d:/program%20files/java/jdk1.6.0_23/jre/lib/rt.jar
File:/d:/program%20files/java/jdk1.6.0_23/jre/lib/sunrsasign.jar
File:/d:/program%20files/java/jdk1.6.0_23/jre/lib/jsse.jar
File:/d:/program%20files/java/jdk1.6.0_23/jre/lib/jce.jar
File:/d:/program%20files/java/jdk1.6.0_23/jre/lib/charsets.jar
File:/d:/program%20files/java/jdk1.6.0_23/jre/lib/modules/jdk.boot.jar
File:/d:/program%20files/java/jdk1.6.0_23/jre/classes

2. What is the Extensionclassloader extension class loader

System.out.println (System.getproperty ("Java.ext.dirs"));
ClassLoader Extensionclassloader=classloader.getsystemclassloader (). GetParent ();
System.out.println ("The parent of Extension ClassLoader:" +extensionclassloader.getparent ());

D:\Program Files\java\jdk1.6.0_23\jre\lib\ext; C:\Windows\Sun\Java\lib\ext
The parent of extension classloader:null

In fact, he is the original ClassLoader in Java, it is loaded by Bootstrapclassloader, but his parent class is not bootstrapclassloader, because Boostrapclassloader is not a Java object ...

3. What is Systemclassloader?

If the Bootstrap class loader and extension class loader are responsible for loading the components of the JVM, then System class loader is responsible for loading the application classes. It is responsible for loading the classes specified by the user in the $classpath.

Each class loader has its own namespace to hold the loaded class. When a class loader loads a class, it searches through the class globally qualified name (Fully qualified class name) stored in the namespace to detect whether the class has already been loaded. If the globally qualified names of the two classes are the same, they are different classes if the namespaces are not the same. Different namespaces indicate that class is loaded by different class loaders.

As the name implies, the class loader is used to load classes (class) into the JVM. The JVM specification defines two types of class Loaders: The Start class loader (bootstrap) and the user custom loader (user-defined class loader). Bootstrap is a class loader that comes with the JVM, which is used to load core class libraries such as java.lang.*. such as the Java.lang.Object is loaded by bootstrap.

Java provides an abstract class ClassLoader, where all user-defined class loaders instantiate subclasses from ClassLoader. The System class loader is a special user-defined class loader, provided by the JVM's implementation, which loads the user class by default when the programmer does not specifically specify the loader. The System class loader can be obtained by means of the Classloader.getsystemclassloader () method. Each class loader has its own namespace, which maintains the type it loads. So a Java program can load multiple types with the same fully qualified name multiple times. A fully qualified name of such a type is insufficient to determine that multiple types with the same fully qualified name can be loaded more than once in a Java program. Therefore, when more than one class loader loads a type with the same name, to uniquely identify the type, precede the type name with an identity of the class loader that mounts the type that indicates the namespace in which he is located. The namespace in the Java Virtual machine is actually the result of the parsing process. For each loaded type, the Java Virtual Machine records the class loader that loads it, and when the virtual machine resolves a class to another symbol reference for a class, he needs the class loader of the referenced class.

ClassLoader related content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.