Home  >  Article  >  Java  >  How are java classes loaded?

How are java classes loaded?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-12-27 15:02:504048browse

How are java classes loaded?

Class loading is to read the .class file into the memory, put it into the method area, and create an object of type java.lang.Class in the heap area. This object encapsulates the class The data structure in the method area.

When does class loading occur? It usually occurs when a class is used, including the following 6 situations:

- Use the new keyword to create a class example;

- Access static variables;

- Call static methods;

- Reflection (such as Class.forName("com.shengsiyuan.Test"));

- Initialize the subclass, and its parent class will also be initialized;

– The class that is marked as the startup class when the java virtual machine starts (for example: Java Test).

When the Java virtual machine ends its life cycle, including the following 4 situations:

– The System.exit() method is executed;

– The program ends normally;

- The program encounters an exception or error during execution and terminates;

- An operating system error causes the virtual machine process to terminate.

PHP Chinese website has a large number of free JAVA introductory tutorials, everyone is welcome to learn!

The above is the detailed content of How are java classes loaded?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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