Java Reference
In-Depth Information
• Parameter . A method may have parameters , which are variables that are
declared in the header of the method (within the parentheses and separated by
commas).
• Method body . A method body consists of a sequence of statements. It may also
contain declarations of local variables to simplify the body and make it more
efficient.
• Assertion . An assertion is a relation that we place as a comment before or after
a statement in a method body to assert that the relation is true at that point.
Assertions help programmers understand method bodies.
• Return statement in a function . Execution of a function body must terminate
by executing a statement return expression ; ; the value of the expression is the
result of the function call.
• Method call (or invocation) . A method does nothing until is called, or invoked,
just as a cooking recipe just sits there until someone looks at it and follows the
instructions for cooking something. A procedure call is a statement; it is execut-
ed. A function call is an expression; it is evaluated. A constructor call is execut-
ed; it can appear only in a new-expression.
• Argument . Each method call can have arguments , which are expressions that
appear within the parentheses of a call (and separated by commas).
• Execution or evaluation of a method call . Executing or evaluating a call con-
sists of assigning the values of the arguments to the corresponding parameters
and then executing the body of the called method. The process of executing the
method body stops when there are no more statements to execute or until a return
statement is executed.
• Method specification . The specification of a method gives constraints (pre-
conditions) on the parameters of the method and explains precisely what it does
(or what value it produces). The specification should generally be written before
writing the method body. Someone wanting to write a call to the method should
be able to do so using only the specification and header of the method.
• Static versus non-static . Method definitions (except constructor definitions)
may have the modifier static . A static method is placed in the file drawer for
the class in which the method definition appears. A non-static method is called
an instance method because a copy of it is placed in each folder (or instance, or
object) of the class in which the method definition appears.
• Stepwise refinement or top-down programming . Stepwise refinement is an
idealized approach used to develop a method. The process starts with a specifi-
cation and refines it, step by step, into the final program.
• An execution model . Our model of execution of a method call is in terms of
the call stack of frames for calls that have been started but have not yet been-
 
Search WWH ::




Custom Search