Try to come up with meaningful method names that succinctly describe the purpose of the method, making your code self-documenting and reducing the need for additional comments.
Compose method names using mixed case letters, beginning with a lower case letter and starting each subsequent word with an upper case letter.
Begin method names with a strong action verb (for example,
deposit). If the verb is not descriptive enough by itself, include a noun (for example,
addInterest). Add adjectives if necessary to clarify the noun (for example,
Use the prefixes
set for getter and setter methods. Getter methods merely return the value of a instance variable; setter methods change the value of a instance variable. For example, use the method names
setBalance to access or change the instance variable
If the method returns a boolean value, use
has as the prefix for the method name. For example, use
hasCreditLeft for methods that return true or false values. Avoid the use of the word not in the boolean method name, use the
! operator instead.
For example, use
!isOverdrawn instead of
These conventions are common practice in the Java development community as well as the naming convention for methods used by Sun for the Java core packages. Writing code that follows these conventions makes methods easy for others to identify in your code. Even though variables and methods both begin with a lower-case letter followed by mixed case, they can easily be differentiated from each other because method names begin with a verb and are immediately followed with a set of parenthesis, for example: