11.07.2015 Views

A Quick and Dirty Overview of Java and Java Programming

A Quick and Dirty Overview of Java and Java Programming

A Quick and Dirty Overview of Java and Java Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

int a=2;int b=9;System.out…swap(a,b);….MEMORY29abWhen we perform a call to a method, the following steps are taken:• first <strong>of</strong> all, the expressions that are specified as actual parameters in the method callare completely evaluated. Each actual parameter in the call should ultimately reduceto a single element. For example, if we consider the following call to the methodsqrt:Math.sqrt(12*x+5)The actual parameter in this method call is the expression 12*x+5; when the methodis called, the system will first compute the value <strong>of</strong> this expression.• Next, the method is started; upon starting the method, all the local variables <strong>of</strong> themethod are created; in particular, the formal parameters <strong>of</strong> the method are treatedjust as any other local variables, <strong>and</strong> thus they are created as new variables when themethod is started. Let us consider the example above. When we call the methodswap, then all its local variables, including the formal parameters, are created. Thememory configuration when the call starts is as follows:MEMORYint a=2;int b=9;System.out…swap(a,b);….29abxtempypublic static void swap(int x, int y){int temp;…..}• once all the local variables <strong>of</strong> the method are created, the values <strong>of</strong> the actualparameters (computed in the first step) are copied in the newly created formalparameter variables. In our example, the values <strong>of</strong> the actual parameters (a,b) are 2,5;23

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!