return and using parameters

When I run this through a debugger in Java Studio Enterprise, after it reaches the return statement in gdc() it says that num1 does not have a value, but it says that common does. I got this code from a book and I am just trying to understand how passing variables, parameters/arguements and the return statement work. How is the value of num1 used to create the value in common if it doesnt have the value? Or maybe it just loses its value after it passes it to common? Can someone tell me what is going on under the hood here?

publicvoid reduce()

{

if (numerator !=0)

{

int common = gcd (Math.abs(numerator),denominator);

numerator = numerator/common;

denominator = denominator/common;

}

}

privateint gcd (int num1,int num2)

{

while(num1 != num2)

if(num1 > num2)

num1= num1 - num2;

else

num2 = num2 - num1;

return num1;

}

[1494 byte] By [pberardi1a] at [2007-11-27 11:16:57]
# 1

Interesting question. You have two independent variables... after the return statement, the method's variable stack becomes invalid, and, - I have to admit not to know the specific behavior (and couldn't care less, albeit I wonder whether any behaviour is even *specified* in the JVM specs - if it isn't, all research is even more pointless) - the return value probably passed to a certain register upon return. In the next step, the register's value will be assigned to that common variable. The method's variables can't exist anymore as they ran out of scope.

CeciNEstPasUnProgrammeura at 2007-7-29 14:22:07 > top of Java-index,Java Essentials,Java Programming...
# 2

thank you

pberardi1a at 2007-7-29 14:22:07 > top of Java-index,Java Essentials,Java Programming...
# 3

> When I run this through a debugger in Java Studio

> Enterprise, after it reaches the return statement in

> gdc() it says that num1 does not have a value,

Not only does it not have a value, it doesn't exist. Your method has ended. All its parameters and local variables do not exist. Their scope--the context in which they exist--is while that method is executing.

jverda at 2007-7-29 14:22:07 > top of Java-index,Java Essentials,Java Programming...
# 4

> care less, albeit I wonder whether any behaviour is

> even *specified* in the JVM specs - if it isn't, all

> research is even more pointless) -

It must be specified. Should be in the JLS, I'd think, but might be VMSpec. If it's not spec'd, one compiler could put the return value in one place, and another in another place, and code that I compiled wouldn't work with code that you compiled.

jverda at 2007-7-29 14:22:07 > top of Java-index,Java Essentials,Java Programming...