Wednesday, February 1, 2012

Stack Attack Attack

So after learning how to use a method I wanted to learn how a method works. As far as I can understand, the computer allocates memory for variables and their assigned values when a method is invoked. The main method, that is the method that is first executed when a Java program starts, creates variables and assigns values to them. If you invoke another method based on values from variables in the main method, the new method creates variables and then fills them with the values from the main method. After the new method is done calculating using the values and sends off the result, all the variables and values are deleted from the stack since they don't need to be used anymore. I think this is all correct, as far as my understanding is for now, I'll see if it is true when I write some code using methods. Since the variables and their values are separated and deleted within the stacks when they aren't being used, the variables of different methods (even if they have the same name) are completely unique and independent of each other.

No comments:

Post a Comment