Method calls, the details

Figure 422. Method calling Slide presentation
public class Circle {
  static final double
    PI = 3.141592653589793;
  double r;
  /** Change a circle's area
   *  @param area The desired new area
   *  @return The circle's new radius */
  double setArea(final double area ) {
    double val  = area  / PI ;
    return  r  = Math.sqrt(val);
  }
}

Passing arguments.

Defining method local variables.

Accessing class variable.

returning values.

Accessing instance variable.


Figure 423. Three variable scopes Slide presentation
public class Circle {

  static final double
    PI  = 3.141592653589793;

  double r  ;

  double setArea(final double area ) {
    double val  ...
    ...
  }
}

Class scope.

Instance scope

Method scope


Figure 424. Scope lifetimes Slide presentation
Class scope (static) Application process
Instance scope Object lifetime: new (...) until being garbage collected.
Method scope Method invocation until return.

Figure 425. Two runtime memory categories Slide presentation
Heap memory
  • Allocation of class or array instances:

    new String()
    new float[200]
  • De-allocation subject to garbage collection.

Execution stack
  • One instance per process thread.

  • Hosting variables (values or references)


Figure 426. IDE debugger Slide presentation
IDE debugger

Three call stack frames corresponding to main() calling circleArea(2) calling square(2).

Local variables corresponding to selected stack frame.

Tip

In the above example you may select stack frame circleArea showing its local variables while leaving your debugger resting at line 3.