What happens after a method is called in Java
15:24 21 Nov 2013

This looks like a silly question but I found it is hard to get it right. I have asked different people but couldn't get an ideal answer.

I want to know what happens after we call a normal method in Java (Provided in a single threaded environment).

My understanding is that:

  1. All current stack variables are poped-up and stored somewhere (where?)
  2. The current method call halts
  3. The arguments of the newly called method are pushed to the stack
  4. The method code runs
  5. After the method finished running, the stack is again emptied and the old stack contents is again restored. (What happened if the function returns a value?).
  6. Code continues with the calling method.

This is a very incomplete and possibly wrong answer. Can someone provide a more detailed description?

Many thanks.

java methods