Java Runtime Stack Mechanism (JRSM)
Youssef Najeh
Java | JVM | Kotlin | Angular | DevOps Enthusiast | Oracle Certified Associate (Java 8) | +12K
Java Runtime Stack is a very interesting topic to discuss and it is a good knowledge to have before learn Java Exception Handling, So what is Runtime Stack Mechanism in Java?
Runtime Stack Mechanism as its name indicates is a Stack that have been created by JVM for each Thread at the time of Thread creation, JVM store every methods calls performed by that Thread in the Stack. Each entry or method call called "activation record" / "stack frame".
JVM removes each entry (method call record) after completing execution of it.
JVM destroys the empty stack after completing all methods call and terminates the program normally.
Simple Example:
public class HaveAnIdeaAboutJRSM{
public static void main(String ... args){
m1();
}
public static void m1(){
m2();
}
public static void m2(){
System.out.println("I Like 7");
}
}
Output:
I Like 7
Diagram: