Common naming convention : Coding Style

**Variable names must be in mixed case starting with lower case. ** Common practice in the Java development community and also the naming convention for variables used by Sun for the Java core packages. Makes variables easy to distinguish from types, and effectively resolves potential naming collision as in the declaration eg. int state; Names representing constants (final variables) must be all uppercase using underscore to separate words. MAX_ITERATIONS, COLOR_RED [Read More]

Improving coding style into classes

**Class and Interface declarations should be organized in the following manner: ** 1. Class/Interface documentation. 2. class or interface statement. 3. Class (static) variables in the order public, protected, package (no access modifier), private. 4. Instance variables in the order public, protected, package (no access modifier), private. 5. Constructors. 6. Methods (no specific order). Reduce complexity by making the location of each class element predictable. Imported classes should always be listed explicitly. [Read More]

Improving coding style into functions or methods

Method modifiers should be given in the following order: static abstract synchronized final native The modifier (if present) must be the first modifier. public static double square(double a); // NOT: static public double square(double a); is one of public, protected or private while includes volatile and transient. The most important lesson here is to keep the access modifier as the first modifier. Of the possible modifiers, this is by far the most important, and it must stand out in the method declaration. [Read More]

Java specific naming convention

JFC (Java Swing) variables should be suffixed by the element type. widthScale, nameTextField, leftScrollbar, mainPanel, fileToggle, minLabel, printerDialog Enhances readability since the name gives the user an immediate clue of the type of the variable and thereby the available resources of the object. Array specifiers must be attached to the type not the variable. int[] a = new int[20]; // NOT: int a[] = new int[20] The arrayness is a feature of the base type, not the variable. [Read More]

Specific cases of naming enhancing naming style

The term find can be used in methods where something is looked up. vertex.findNearestVertex(); matrix.findSmallestElement(); node.findShortestPath(Node destinationNode); Give the reader the immediate clue that this is a simple look up method with a minimum of computations involved. Consistent use of the term enhances readability. The term initialize can be used where an object or a concept is established. printer.initializeFontSet(); The American initializeshould be preferred over the English initialise. Abbreviation init must be avoided. [Read More]