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:
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
.
length
, as in class java.lang.String
(§20.12.11).
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).
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
.
Whenever possible and appropriate, basing the names of methods in a new class on names in an existing class that is similar, especially a class from the standard Java Application Programming Interface classes, will make it easier to use.
Method names cannot hide or be hidden by other names (§6.5.6).