Table of Contents
class loading process for the JVM
Loading
Connection
Verification
Preparation
Resolution
Initialization
Home Java javaTutorial Detailed introduction to Java class loading process

Detailed introduction to Java class loading process

Mar 07, 2019 pm 04:49 PM
java

This article brings you a detailed introduction to the Java class loading process. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The process of Java files from encoding to final execution:

  1. Compile: Javac Compile the Java file into a .class file
  2. Run: Submit the .class file Run the

class loading process for the JVM

The JVM virtual machine loads the class information in the .class file into the memory and parses it to generate the corresponding class object. The JVM does not load all classes into memory from the beginning, but only loads them when it encounters a class that needs to be run for the first time, and only once.

Detailed introduction to Java class loading process

Loading

Load class bytecode files from various sources into memory through the class loader
JVM Three things to accomplish

  1. Get the binary byte stream that defines this class through the fully qualified name of a class.
  2. Static storage structure-> Runtime data structure in the method area
  3. Generate the java.lang.Class object of the corresponding class in the Java heap as the access entrance to these data in the method area.

Class loader

  • Start class loader
  • Extend class loader
  • Apply class loader Device
  • Custom class loader

Connection

The process of merging the binary code of the java class into the running state of the JVM

Verification

Ensure that the loaded byte stream complies with the virtual machine specifications and will not cause security errors

Verification classification

  • Verification of the file format, such as whether the constant Are there unsupported constants? Is there any non-standard or additional information in the file?
  • Verification of metadata, for example, does the class inherit a class modified by final? Do the fields and methods in the class conflict with the parent class? Is there an unreasonable overload?
  • Verification of bytecode ensures the rationality of program semantics, such as ensuring the rationality of type conversion.
  • Verification of symbol references, such as verifying whether the corresponding class can be found through the fully qualified name in the symbol reference? Verify the accessibility (private, public, etc.) in the symbol reference is accessible by the current class?

Preparation

Allocate memory for class variables (note, not instance variables) and assign initial values ​​(the default initial values ​​of the Java virtual machine according to different variable types)

Default initial value

  • The initial value of 8 basic types, the default is 0
  • The initial value of the reference type is null
  • The initial value of the constant is For the value set in the code
  • final static tmp = 456

Resolution

The process of replacing symbol references in the constant pool with direct references

Symbol reference: a string, but this string gives some relevant information that can uniquely identify a method, a variable, or a class

Direct reference: can be understood as a memory address, or an offset Quantity

For example, now call the method hello(), the address of this method is 1234567, then hello is a symbolic reference, 1234567 is a direct reference

In the parsing phase, the virtual machine will The symbolic references of class names, method names, and field names are replaced with specific memory addresses or offsets, that is, direct references

Initialization

to class variables (variables or statements modified by static ) Initialization is the process of executing the class constructor

Initialization process

  • When initializing a class, its parent class has not been initialized yet, its parent class will be initialized first
    - At the same time Contains multiple static variables and static code blocks, they are executed in top-down order

The above is the detailed content of Detailed introduction to Java class loading process. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Java Program to Find the Volume of Capsule Java Program to Find the Volume of Capsule Feb 07, 2025 am 11:37 AM

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

Create the Future: Java Programming for Absolute Beginners Create the Future: Java Programming for Absolute Beginners Oct 13, 2024 pm 01:32 PM

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

See all articles