Java Reference
In-Depth Information
14 separate the import statements from the class declaration. In all other cases, only a single
blank line is used to separate minor sections: line 11 separates the package statement from
the first import statement, and line 19 separates the contructor and method declarations.
Beginning Comments
Beginning comments are separate from Javadoc comments and, as such, are often not under-
stood by Java programmers. The beginning comments contain some of the same information
as the Javadoc comment for the class, but there are a couple of major differences: the infor-
mation is provided in one standard place, and very specific information is listed. While the
Javadoc comments might contain a superset of the same information as the beginning com-
ments, there is no specific line number the information will appear on, and the desired
information may be buried among API documentation. Beginning comments contain the
following:
Class name
Version information (might be automatically filled in by your revision control system)
Creation/modification date (might be automatically filled in by your revision control
system)
Author/last modifier (might be automatically filled in by your revision control system)
The entire comments block is a C type comment, not a Javadoc comment—that is, the com-
ment block starts with /* and not /** .
Package and Import Statements
Following the beginning comments, you put your package statement, a blank line, and then
your import statements, as shown in lines 10-12 of the preceding code example.
Although the Sun Coding Conventions document does not specify whether you should
list every class or include the entire package, one common usage is to list individual classes in
a package until there are three classes listed in a single package. After that, it is common to
import the entire package.
Likewise, the Sun Coding Conventions do not specify whether import statements should
be in any particular order. Worrying about such details is probably going beyond the scope of
the requirements (and may cause your colleagues to look at you in a funny way). Many devel-
opers tend to keep them in alphabetical order, but don't get too concerned about this.
Tip Many integrated development environments (IDEs) have some of the following features: automatic
addition of missing import statements; automatic removal of unused import statements; and automatic
refactoring of too many or too few imports in a given package. While these features can help improve your
coding speed in your real job, we recommend you switch these features off while working on the SCJD
assignment. One of the problems with using some of the IDE “features” is that it can become difficult to
determine what has gone wrong if something does go wrong—if you learn to work with import statements
manually for the SCJD assignment, you are more likely to be able to handle any issues later in life.
Search WWH ::




Custom Search