Deep analysis of ClassLoader (ii)--Root loader, extended class loader and System class loader

Source: Internet
Author: User
Tags reflection

The end product of a class's load is a class object in the heap (heap)

class objects encapsulate the data structures in the method area and provide Java programmers with an interface to access data structures within the method area. And reflection is like a mirror. This interface is a reflection interface, so we can get the methods and properties of the class, including private methods and properties, by reflection.

Let's introduce the class loader in detail

There are two types of loaders for the class

1, Java Virtual machine with the loader

2, user-defined class loader

And the Java Virtual machine has its own loader and includes 3 kinds of loaders

? Root class loader (Bootstrap)

? Extended class loader (Extension)

? System class loader (Ststem)

The System class loader is also known as the Application class loader

where the extension class loader and the System class loader are implemented using Java. The root loader is implemented using C + +, and the JVM API does not expose the root class loader, and programmers cannot get the root loader in Java code.

The user-defined class loader is a class loader written by the user, but must inherit the Java.lang.ClassLoader class, which allows the user to customize how the class is loaded.

Let's take a look at the relevant API for the class loader

Each class object contains a definition of Classloader, that is, we can get the corresponding Classloader by class, so let's take a look at how the class object gets Classloader.

Class object has a getClassLoader method for returning the class loader of the class, but some implementations may use NULL to identify the boot class loader (root ClassLoader). That is, when we use the object loaded by the root loader using this method to get the ClassLoader is null, why is this so? As we've said before, the root loader is written in C + +, the JVM cannot and does not allow the programmer to get the class, so the return is null, and if this object represents a primitive type or void, then NULL is returned, in fact, the further implication is that all the bases in Java This data type is loaded by the root loader. (JDK1.5 Void is later included as the base data type).

Let's go through the code to see the class's first-off loader. (see section of code below)

package com.yhj.jvm.classloader.test;

/**

* @Description: ClassLoader Test and research

* @Author yhj create at 2011-6-25 04:08:32

* @FileName Com.yhj.jvm.classloader.test.ClassLoaderTest.java

*/

Public class classloadertest {

/**

*

* @Description: main function, launch entry

* @param args

* @author yhj create at 2011-6-25 04:08:57

* @throws classnotfoundexception

*/

Public Static void

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.