Skip to main content

Section A.3 Naming Conventions

The choice of identifiers for various elements within a program can help improve the readability of the program. Identifiers should be descriptive of the element's purpose. The name of class should be descriptive of the class's role or function. The name of a method should be descriptive of what the method does.

The way names are spelled can also help improve a program's readability. Table A.1 summarizes the various conventions recommended by the Java Language Specification and followed by professional Java programmers.\fontdimen2\font=1.429\fontdimen2\font

Table A.3.1. Naming rules for Java identifiers
Identifier Type Naming Rule Example
Class Nouns in mixed case with the first OneRowNim
letter of each internal word capitalized. TextField
Interfaces Same as class names. Many interface names Drawable
end with the suffix able. ActionListener
Method Verbs in mixed case with the first letter in actionPerformed()
lowercase and the first letter of internal sleep()
words capitalized. insertAtFront()
Instance Variables Same as method names. The name should maxWidth
be descriptive of how the variable is used. isVisible
Constants Constants should be written in uppercase with MAX_LENGTH
internal words separated by _. XREF
Loop Variables Temporary variables, such as loop variables, int k;
may have single character names: i, j, k. int i;
You have attempted of activities on this page.