Home  >  Article  >  Java  >  How to run the java program after it is compiled

How to run the java program after it is compiled

PHPz
PHPzforward
2023-05-05 18:28:073604browse

1. After compiling the java program to obtain the MainApp.class file, type java AppMain on the command line. The system will start the jvm process. The jvm process will find a binary file called iPhone from the classpath path and load the category information of iPhone into the method area of ​​the runtime data area. This process is called loading of the Apple phone.

2. The JVM finds the main function entry of AppMain and starts executing the main function.

The first command of the main function is Animalanimal=newAnimal("Puppy") to let the JVM create an Animal object. However, there is no Animal class information in the method area at this time. The JVM immediately loads the Animal class and changes the type of the Animal class. Information is placed into the method area.

3. After loading the Animal class, the Java virtual machine first allocates a new Animal instance memory in the accumulation area and calls the structure function to initialize the Animal instance. The Animal instance has Animal type information pointing to the method area (including method table, Basic implementation of java dynamic binding)

4. When using animal.printName(), the JVM finds the animal object based on the animal reference, and locates the method table of the animal type information in the method area based on the reference held by the animal object. , get the address of the printName() function bytecode.

5. Start running the printName() function.

Expansion:

Running Instructions

The compiled byte code file format is mainly divided into two types: constant pool and method byte code part. The constant pool records the working code of the method that appears in the code (class name, member variable name, etc.) and symbol reference (method reference, member variable reference, etc.) and places it in the working code of various methods in the category.

The above is the detailed content of How to run the java program after it is compiled. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete