Java Edition-recursion

Source: Internet
Author: User

The 1.Java stack and the run-time stack are two different concepts: they have similarities: the roles played in processing method invocations are essentially the same, so, although stored differently, they store similar information for this process. The task of the Java interpreter is to convert the information bytecode in the. class file so that the runtime stack can take over the work of the Java stack, which is simply an abstract construct.

2. The state of each method, including the main () method, is described by the contents of all automatic variables, the parameters of the method, and the return address (indicating the location of the caller of the re-return). The data fields that contain all this information are in the run-time stack, called the activity record or the stack structure. As long as one of the methods is executing, the activity records that belong to him exist. This record is the private information pool for this method and is the necessary information warehouse to store the correct execution of the method and return the method call location. The lifetime of an activity record is usually very short because they are dynamically allocated when the method is entered, and are dynamically retracted when the method exits.

An activity record typically contains the following information:

The value of all parameters of the method, the first cell address;

Local (automatic) variables can exist elsewhere, and the activity records contain only their descriptors and pointers to their stored addresses;

return address;

a dynamic link;

The return value of a method of non-void type.

3. Recursion: Tail recursion, non-tail recursion, indirect recursion, nested recursion, excessive recursion (logical simplicity and readability are the basis of support for recursive use). The cost of recursion is that it takes longer to run and is relative to a non-recursive method, consumes more runtime stack space, and if the recursion level is too deep, the run causes the stack to overflow and the program ends abnormally, resulting in an unrecoverable error stackoverflowerror).

4. Backtracking

Java Edition-recursion

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.