In-memory representation of method invocations in Java

Source: Internet
Author: User

In Java, methods and local variables (that is, variables declared in a method) are placed on the stack memory. When you invoke a method, the method is placed at the top of the stack on the call stack. The method at the top of the stack is the method that is currently executing until execution is complete before it is released from the top of the stack. We know that stacks are a data structure that performs "advanced out-of-date". I'll give you some practical examples below. Look at the code first.

public void Graduate ()//First method

{

Study ();

}

public void Study ()//A second method

{

Readbooks ();

}

public void Readbooks ()//third method

{

Boolean done = true;

}

The first method will call the second method in the execution process, at this time, the first method in the stack is pressed below, the second method into the stack, placed on top of the stack, the second method at the time of execution call the third method, at this time, the second method is pressed into the following, the third method into the stack, as to the top, The method at the top of the stack is currently being executed.

Call the first method
Graduate ()
Call a second method
Study ()
Graduate ()

Call a third method
Readbooks ()
Study ()
Graduate ()

When the third method finishes executing
Study ()
Graduate ()

In-memory representation of method invocations in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.