Java Reference
In-Depth Information
To Code the Method Header
1. With the insertion point in line 12, type the main() method header and
opening brace as shown in Figure 2-21 on page 67.
The main() method header is displayed in line 12 in the coding window
(Figure 2-22). The keywords, public, static, and void, display in blue and the
opening brace is displayed in red. TextPad automatically indents the line
after the opening brace of the method.
method
name
void indicates
method has no
return value
main method
header
opening brace
insertion point
parameter
list
FIGURE 2-22
After the code for the class and the main() method is complete, closing
braces indicate the end of each method. To make it easier to see what code is
included in the body of the class and main() method, the closing brace for each
should be indented so that it aligns underneath the respective opening brace. To
facilitate entering methods, TextPad automatically reduces the indent after you
type a closing brace.
Placement of Braces
You can place the opening brace on the same line as the class or
method header, or on the line below. Each opening brace must be
paired with a closing brace. A simple way to avoid forgetting a
closing brace is to immediately place the closing brace on a line
below the opening brace before writing the code within the
braces. Some Java programmers indent the braces; others do not.
When writing code, it is good programming practice to be consis-
tent in the placement of the opening brace. Some programmers
place a line comment directly after the closing brace to help
remember which class or method the brace closes.
 
Search WWH ::




Custom Search