Java Reference
In-Depth Information
Reference types
A type name should begin with a capital letter and be written in mixed case
(e.g., String ). If a class name consists of more than one word, each word
should begin with a capital letter (e.g., StringBuffer ). If a type name, or one of
the words of a type name, is an acronym, the acronym can be written in all cap‐
ital letters (e.g., URL , HTMLParser ).
Because classes and enumerated types are designed to represent objects, you
should choose class names that are nouns (e.g., Thread , Teapot , Format
Converter ).
When an interface is used to provide additional information about the classes
that implement it, it is common to choose an interface name that is an adjective
(e.g., Runnable , Cloneable , Serializable ). Annotation types are also com‐
monly named in this way.
When an interface is intended to work more like an abstract superclass, use a
name that is a noun (e.g., Document , FileNameMap , Collection ).
A method name always begins with a lowercase letter. If the name contains
more than one word, every word after the first begins with a capital letter (e.g.,
insert() , insertObject() , insertObjectAt() ). This is usually referred to as
Method names are typically chosen so that the first word is a verb. Method
names can be as long as is necessary to make their purpose clear, but choose
succinct names where possible. Avoid overly general method names, such as
performAction() , go() , or the dreadful doIt() .
Fields and constants
Nonconstant field names follow the same capitalization conventions as method
names. If a field is a static final constant, it should be written in uppercase.
If the name of a constant includes more than one word, the words should be
separated with underscores (e.g., MAX_VALUE ). A field name should be chosen to
best describe the purpose of the field or the value it holds. The constants
defined by enum types are also typically written in all capital letters.
Method parameters follow the same capitalization conventions as nonconstant
fields. The names of method parameters appear in the documentation for a
method, so you should choose names that make the purpose of the parameters
as clear as possible. Try to keep parameter names to a single word and use them
consistently. For example, if a WidgetProcessor class defines many methods
that accept a Widget object as the first parameter, name this parameter widget
or even w in each method.
Search WWH ::

Custom Search