Java Reference
In-Depth Information
Computer scientists use the word “parameter” broadly to mean both what appears
in the method header (the formal parameter ) and what appears in the method call
(the actual parameter ).
Formal Parameter
A variable that appears inside parentheses in the header of a method that is
used to generalize the method's behavior.
Actual Parameter
A specific value or expression that appears inside parentheses in a method
call.
The term “formal parameter” does not describe its purpose. A better name would
be “generalized parameter.” In the writeSpaces method, number is the generalized
parameter that appears in the method declaration. It is a placeholder for some unspec-
ified value. The values appearing in the method calls are the actual parameters,
because each call indicates a specific task to perform. In other words, each call pro-
vides an actual value to fill the placeholder.
The word “argument” is often used as a synonym for “parameter,” as in “These are
the arguments I'm passing to this method.” Some people prefer to reserve the word
“argument” for actual parameters and the word “parameter” for formal parameters.
Let's look at an example of how you might use this writeSpaces method. Rem-
ember that the DrawFigure2 program had the following method, called drawTop :
// produces the top half of the hourglass figure
public static void drawTop() {
for (int line = 1; line <= SUB_HEIGHT; line++) {
System.out.print("|");
for (int i = 1; i <= (line - 1); i++) {
System.out.print(" ");
}
System.out.print("\\");
int dots = 2 * SUB_HEIGHT - 2 * line;
for (int i = 1; i <= dots; i++) {
System.out.print(".");
}
System.out.print("/");
for (int i = 1; i <= (line - 1); i++) {
System.out.print(" ");
}
System.out.println("|");
}
}
 
Search WWH ::




Custom Search