Java coding standards
· It is highly recommended to follow coding standards.
· Whenever we are writing any component the name of the component should reflect the
purpose or functionality.
Example:
Coding standards for classes:
· Usually class names are nouns.
· Should starts with an uppercase letter and if it contains multiple words every inner word
should start with an upper case letter.
Example:
Coding standards for interfaces:
· Usually interface names are adjectives.
· Should starts with upper case letter and if it contains multiple words every inner word
should start with an upper case letter.
Example:
1) Serializable
2) Runnable adjectives
3) Cloneable
Coding standards for methods:
· Usually method names are either verbs or verb-noun combinations.
· Should starts with lowercase character and if it contains multiple words every inner
a word should start with an upper case letter.
Example:
Coding standards for variables:
· Usually variable names are nouns.
· Should starts with lowercase alphabet symbol and if it contains multiple words every
the inner word should start with an upper case character.
Example:
length
name
salary nouns
age
mobileNumber
Coding standards for constants:
· Usually constants are nouns.
· Should contain only uppercase characters and if it contains multiple words then these
words are separated with underscore symbol.
· Usually we can declare constants by using public static final modifiers.
Example:
MAX_VALUE nouns
MIN_VALUE
Java bean coding standards:
· A java bean is a simple java class with private properties and public getter and setter
methods.
Example:
The syntax for setter method:
1) The method name should be prefixed with the set.
2) It should be public.
3) The return type should be void.
4) Compulsory it should take some argument.
The syntax for getter method:
1) The method name should be prefixed with getting.
2) It should be public.
3) The return type should not be void.
4) It is always no argument method.
Note: For the boolean properties the getter method can be prefixed with either get or is.
Example:
Coding standards for listeners:
To register a listener:
· Method name should be prefixed with add.
1) public void addMyActionListener(MyActionListener l)(valid)
2) public void registerMyActionListener(MyActionListener l)(invalid)
3) public void addMyActionListener(ActionListener l)(invalid)
To unregister a listener:
· The method name should be prefixed with remove.
1) public void removeMyActionListener(MyActionListener l)(valid)
2) publc void unregisterMyActionListener(MyActionListener l)(invalid)
3) public void removeMyActionListener(ActionListener l)(invalid)
4) public void delete MyActionListener(MyActionListener l)(invalid)
Comments
Post a Comment