6.8.2
Class and Interface Type Names
NAMES
6.8.2 Class and Interface Type Names
Names of class types should be descriptive nouns or noun phrases, not overly
long, in mixed case with the first letter of each word capitalized. For example:
ClassLoader
SecurityManager
Thread
Dictionary
BufferedInputStream
Likewise, names of interface types should be short and descriptive, not overly
long, in mixed case with the first letter of each word capitalized. The name may be
a descriptive noun or noun phrase, which is appropriate when an interface is used
as if it were an abstract superclass, such as interfaces
java.io.DataInput
and
java.io.DataOutput
; or it may be an adjective describing a behavior, as for the
interfaces
java.lang.Runnable
and
java.lang.Cloneable
.
Hiding involving class and interface type names is rare. Names of fields,
parameters, and local variables normally do not hide type names because they
conventionally begin with a lowercase letter whereas type names conventionally
begin with an uppercase letter.
6.8.3 Method Names
Method names should be verbs or verb phrases, in mixed case, with the first letter
lowercase and the first letter of any subsequent words capitalized. Here are some
additional specific conventions for method names:
Methods to
get
and
set
an attribute that might be thought of as a variable
V
should be named
get
V
and
set
V
. An example is the methods
getPriority
( 20.20.22) and
setPriority
( 20.20.23) of class
java.lang.Thread
.
A method that returns the length of something should be named
length
, as in
class
java.lang.String
( 20.12.11).
A method that tests a
boolean
condition
V
about an object should be named
is
V
. An example is the method
isInterrupted
of class
java.lang.Thread
( 20.20.32).
A method that converts its object to a particular format
F
should be named
to
F
. Examples are the method
toString
of class
java.lang.Object
( 20.1.2) and the methods
toLocaleString
( 21.3.27) and
toGMTString
( 21.3.28) of class
java.util.Date
.
108
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved