1. During the running phase, the classLoader class loader will put the code fragment corresponding to the method in the class file into the method area in the memory area so that it can be used the next time the method is called. this method.
2. During the running process, the JVM will push the code blocks in the method into the stack space in the memory according to the order of method calls. Use the execution order of statements (from top to bottom, from inside to outside) to perform stack popping and running operations
When calling for the first time, the corresponding code block of the method will be loaded into the memory method area through the class loader
Every time the method is called It is equivalent to astack push process. When all the statements in the method are executed, the method will be popped from the stack (if the stack is not popped, a stack will be generated at some point Overflow exception)
2. Sample codepublic class Practice { public static void main(String[] args) { System.out.println("main 开始"); show1(); System.out.println("main 结束"); } public static void show1(){ System.out.println("show1 开始"); show2(); System.out.println("show1 结束"); } public static void show2(){ System.out.println("show2 开始"); System.out.println("show2 结束"); } }
3.1 JVM will automatically call the main method, Therefore, the main method first pushes the stack, and then executes the statements in the main method in sequence
4. Sample code running screenshot
The above is the detailed content of What is the execution process of java method calls in memory?. For more information, please follow other related articles on the PHP Chinese website!