Home > Java > javaTutorial > Detailed explanation of examples of class loading mechanism in Java

Detailed explanation of examples of class loading mechanism in Java

黄舟
Release: 2017-09-16 10:51:05
Original
1492 people have browsed it

In java, class files are loaded through the JVM. The class loading methods are divided into implicit loading and explicit loading. Among them, when an object is created through new during implicit loading, the corresponding class file is implicitly loaded into the JVM through the class loader. Explicit loading explicitly loads the required class files into the JVM through class.forName().

In the Java language, classes are loaded dynamically. Instead of loading all class files into the JVM at once, the basic classes are loaded into the JVM first, and other user classes are loaded into the JVM when needed. Loaded into JVM.

In the Java language, classes can be divided into three categories: system classes, extension classes and custom classes. Different class loaders are provided for these three types of files

Bootstrap Loader -- Responsible Loading system classes

ExtClass Loader -- Responsible for loading extension classes

AppClassLoader -- Responsible for loading application classes

The class loading process mainly includes the following steps (For details, please refer to "In-depth Understanding of Java Virtual Machine")

1. Loading: Find the corresponding class file according to the search path, and then import it.

2. Link: The link can be divided into 3 steps

(1) Check: Check the correctness of the class file to be loaded

(2)Preparation: Put the class in Allocate memory space for static variables

(3) Parsing: Parse symbol references into direct references

3. Initialization: Perform initialization work on static variables and static code blocks.

The above is the detailed content of Detailed explanation of examples of class loading mechanism in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template