Java Reference
In-Depth Information
Figure 1-14.
Notice that the EmployeeApp class was stored in a file called EmployeeApp.java within myFirstPackage and that
if myFirstPackage is selected it has an expansion icon. Java source code must be stored in a file that has the same
name as the class and the file name extension must be java . RAD generates the correctly named file automatically
so there is less chance of error.
Please note the following about the RAD generated Java code.
RAD has included comments in the source code. Comments are nonexecutable statements. This means that
comments do not perform any computing function. Characters that appear within /* and */ or /** and */ are treated
as comments. These comments can span multiple lines. For a single line of comments use //. Any characters that
appear after // on a line are considered comments.
Comments are used to document the Java code. Generally, programmers will include their name, the date the
class was created, as well as, brief descriptions about what the class does and how the various methods work. Notice
that RAD generated two comment sections: a Methods comment section (in blue, right before the method header)
and a Method body comment section (in green, after the method header). Each comment section has default text that
will be inserted into every class and method that RAD generates. To change the comment default text, click Window ,
then Preferences.... At the Preferences window, expand the Java item then the Code Style item and select Code
Templates. Two expandable items are displayed: Comments and Code. The Methods comment is within Comments
and the Method body comment is within Code. Expand the appropriate item and then select either of comment items
to display the default text. To change the text, click the Edit… button, modify the text, and then click the OK button.
One would think that the default text has been changed—one would be wrong! You must click the Apply button and
then the OK button to make the change permanent.
Changing comments that have already been inserted in a class is much easier. Simply select the comment text
and type over it.
When a class is defined within a package, a package statement must be included . The package statement must
come before the class header and follows the simple syntax of the package keyword followed by at least one space,
the package name, and a semicolon (e.g., package myFirstPackage; ). The package name actually becomes part of
the file identifier. For example, if the file name is Employee and the package is myFirstPackage, the file is identified
as myFirstPackage.Employee.
We'll prove that the package statement is required by “commenting it out.”
Move the cursor before the package k eyword and insert two forward slashes (//). Notice
that the text changes to green. Green text indicates that Java considers the text a comment
and this text will not perform any function.
6.
 
Search WWH ::




Custom Search