Steps to run a Java program:
1. Edit the source code xxx.java (Recommended learning: java course)
2. Compile the xxx.java file to generate the bytecode file xxx.class
3. The class loader in the JVM loads the bytecode file
4. The execution engine in the JVM finds the entry method main() and executes the methods
From source code to bytecode:
From the java file we wrote to the java bytecode file compiled by the compiler (that is, the .class file), this process is the java compilation process; platform. Virtual machines on various platforms all use this same program storage format. Furthermore, the jvm runs class bytecode files, as long as they are files in this format. Therefore, in fact, the jvm is not as tightly tied to the java language as I thought before.
Redirect the bytecode file generated by a simple HelloWorld program into a txt file:
javap -v HelloWorld > HelloWorld.class.txt, part of the information is as follows
A bytecode file contains the magic number and Class file version, constant pool, access flags and other information. In short, the bytecode file is very simple and powerful. It stores this Various information about the class: fields, methods, parent classes, implemented interfaces, etc.
The above is the detailed content of How to run java program. For more information, please follow other related articles on the PHP Chinese website!