First, the operation mechanism of Java program
The entire life cycle of Java development can be summed up in two phases: the compile phase and the run phase .
1. Compile Stage
① Programmers Write a Xx.java source file that conforms to the Java syntax.
② uses the Javac.exe command to compile the above Java source program.
③ generates a Xxx.class file if the compilation is passed.
2. Operation phase
① Open a Command window and run the Java program using the Java.exe command in the command window.
Second, Java Virtual machine run
As shown, the Java file Interpretation execution starts the JVM (the Java Virtual Machine) to run the program by dividing the memory area of the program into a binary file that can be recognized by the computer system.
Let's start with a picture of how the JVM works.
After compiling the class file, the JVM launches its ClassLoader to load the file, then the JVM divides the memory into 5 regions, and we currently only need to understand the main three areas
1. Method Area , also called data structure sharing area, the program will first go into this area
2. Stack memory , when the program executes, the main method first enters the bottom of the stack memory, then the code from the top down to execute the loading method, etc. will be stacked one by one, also known as compression stack.
3. Heap memory , loading instantiated objects executed in the stack memory, or some reference data types will open up a space in the heap memory and generate a 16-based address to the reference name.
Attached: The specific implementation will be in line with the specific procedures for detailed explanation.
Java Basics 8-talking about the running mechanism of Java program and JVM running