Java Coding Standard

Hi All,
Herewith i list the rules for java coding with best of my knowledge please try to use as much as possible while coding.

List of Rules
Rule 1    :   Use the Apache Ant tool to automatically build your project
Rule 2    :   When distributing a project, package all necessary class and resource files in a jar file

Rule 3    :   Define only one class or interface per java file
Rule 4    :   Put single variable definitions & statements in separate lines
Rule 5    :   Always put braces around statements contained in control structures

Rule 6    :   Format if-else, for, while, do-while, switch, try-catch statements according to the following models

Rule 7    :   Always use a space character
Rule 8    :   Use American English for identifiers and restrict identifiers to the ASCII character set

Rule 9    :   Avoid names that differ only in case
Rule 10  :   Capitalize the first letter of standard acronyms
Rule 11  :   Do not hide declarations
Rule 12  :   Use the reversed, lower-case form of your organization’s Internet domain name as the root qualifier for
your package names

Rule 13  :   Use a single, lower-case word as the root name of each package

Rule 14  :   Capitalize the first letter of each word that appears in a class or interface name

Rule 15  :   Use nouns or adjectives when naming interfaces
Rule 16  :   Use nouns when naming classes
Rule 17  :   Pluralize the names of classes that group related attributes, static services or constants

Rule 18  :   Use lower-case for the first word and capitalize only the first letter of each subsequent word that
appears in a method name

Rule 19  :   Use verbs in imperative form to name methods that
Rule 20  :   Use verbs in present third person to name analyzer methods returning a Boolean Value

Rule 21  :   Use nouns to name analyzer methods returning a non-Boolean value, or, alternatively,
name them using the verb “get

Rule 22  :   Name methods setting properties of an object (set methods) using the verb “set

Rule 23  :   Use nouns to name variables and attributes
Rule 24  :   When a constructor or “set” method assigns a parameter to a field, give that parameter the same name
as the field

Rule 25  :   Qualify instance variable references with this to distinguish them from local variables

Rule 26  :   Use upper-case letters for each word and separate each pair of words with an underscore
when naming Java constants

Rule 27  :  Provide a summary description and overview for each application or group of packages

Rule 28  :  Use documentation comments to describe the programming interface

Rule 29  :  Wrap keywords, identifiers, and constants mentioned in documentation comments
with <code></code> tags

Rule 30  :  Wrap full code examples appearing in documentation comments with


tags

Rule 31  :  Include Javadoc tags in a comment in the order @author, @version in every class or interface
description

Rule 32  :  Fully describe the signature of each method

Rule 33  :  Add a “fall-through” comment between two case labels, if no break statement separates those labels

Rule 34  :  Use end-line comments to explicitly mark the logical ends of conditionals loops, exceptions,
enumerations, methods or classes4

Rule 35  :  Do not use the wildcard (“*”) notation in import statements
Rule 36  :  Make classes that do not belong to a package’s public API private

Rule 37  :  Hide any constructors that do not create valid instances of the corresponding class,
by declaring them as protected or private

Rule 38  :  Do not call non-final methods from within a constructor
Rule 39  :  Methods that do not have to access instance variables shall be declared static

Rule 40  :  A parameter that is not changed by the method shall be declared final
Rule 41  :  Use generics instead of casting when navigating through collections

Rule 42  :  Preserve method contracts in derived classes
Rule 43  :  Explicitly check method parameters for validity, and throw an adequate exception
in case they are not valid Do not use the assert statement for this purpose

Rule 44  :  Use the Java logging mechanism for all debugging statements instead of resorting
to the System.out.println function

Rule 45  :  Use unchecked, run-time exceptions to handle serious unexpected abnormal situations,
including those that may indicate errors in the program’s logic

Rule 46  :  Use checked exceptions to report errors that may occur, even if rarely, under normal program operation

Rule 47  :  Do not silently absorb a run-time or error exception  and never ignore error values reported by methods

Rule 48  :  Do not rely on thread scheduling particularities to define the behavior of your program, use
synchronization instead

Rule 49  :  Do not mix classes compiled against different versions of the Java platform

Rule 50  :  Restrict the use of the Systemexit method to the cases described below

Rule 51  :  Do not hard-code file names and paths in your program
Rule 52  :  Always make JDBC driver names configurable, do not hard code them

Rule 53  :  Do not override Object finalize()
Rule 54  :  Refrain from using non-final public static variables
Rule 55  :  Never return references to internal mutable objects containing sensitive data

Rule 56  :  Never store user provided mutable objects directly

M.Muthuganesh
Navagate

admin

Back to top