Naming Conventions


[Page 813 (continued)]

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 a class should be descriptive of the class's role or function. The name of a method should be descriptive of what the method does.


[Page 814]

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.

Table A.1. Naming rules for Java identifiers

Identifier Type

Naming Rule

Example

Class

Nouns in mixed case with the first letter of each internal word capitalized.

OneRowNim
TextField

Interfaces

Same as class names. Many interface names end with the suf.x "able."

Drawable
ActionListener

Method

Verbs in mixed case with the first letter in lowercase and the first letter of internal words capitalized.

actionPerformed()
sleep()
insertAtFront()

Instance Variables

Same as method names. The name should be descriptive of how the variable is used.

maxWidth
isVisible

Constants

Constants should be written in uppercase with internal words separated by _.

MAX_LENGTH
XREF

Loop Variables

Temporary variables, such as loop variables, may have single character names: i, j, k.

int k;
int i;





Java, Java, Java(c) Object-Orienting Problem Solving
Java, Java, Java, Object-Oriented Problem Solving (3rd Edition)
ISBN: 0131474340
EAN: 2147483647
Year: 2005
Pages: 275

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net