Conventions for naming methods
Conventions for naming procedures
1. A procedure name should consist of small letters, except that all “words” with-
in it (except the first) should be capitalized (e.g. printSmallest ).
2. A procedure name can be a command to do something. That is, make it an
action phrase or verb phrase. For example, use drawLine , not lineDrawing or
Here is the reason for this convention. A call on a procedure does some task;
it performs an action. Make the call read like a command to perform the task, e.g.
printSum(5, 95, 43)
3. A procedure name can be the name of an algorithm (e.g. quickSort ).
Conventions for naming functions
1. A function name should consist of small letters, except that all “words” with-
in it (except the first) should be capitalized (e.g. indexOfMedian ).
2. A function name can be a noun phrase that names the result (e.g. min(a,b) ).
Here is the reason. A function produces a value, so let the function name be a
description of that value.
3. The name of a boolean function can be an abbreviation for the true-false state-
ment that is its specification. E.g. comesBefore(date1, date2) stands for the
result of “ date1 comes before date2 ”.
4. A function name may be the name of the algorithm used to compute the result
(e.g. binarySearch ).
Conventions for class names
1. Use a noun phrase for the name —a list of adjectives followed by a noun—
that describes an instance of the class. Capitalize each word in the noun phrase.
Examples: Date , GregorianCalendar , Checkbox , MenuItem .
2. If the class is generally not instantiated, perhaps because it consists mainly of
static methods, then do not use convention 1. An example of this is class Math .
3. Capitalize all words in the class name, including the first. Class names are case
sensitive. A class CheckboxMenu is stored in a file CheckboxMenu.java . Even
though your operating system does not use case sensitive names, (e.g. Microsoft
Windows and Macintosh OS 9), some operating systems do (e.g. Unix), so
always use the same capitalization in the file name that you do in the class name.
E.g. do not put a class CheckMenu in a file checkmenu.java .