Skip to main content

Java coding standards


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

Popular posts from this blog

Core Java

Content 1 - Language fundamental   Identifier Reserved words Data types Literals Arrays Types of variables Var arg method Main method Java coding standards 2 -  Declaration and Access Modifiers Java source file structure Class modifiers Member modifiers Interfaces 3 - Exception Handling Introduction Runtime stack mechanism Default exception handling in java Exception hierarchy Customized exception handling by try-catch  Control flow in try-catch Methods to print exception information Try with multiple catch blocks Finally Difference between final, finally, finalize Control flow in try-catch-finally Control flow in nested try-catch-finally Various possible combinations of try-catch-finally throw keyword throws keyword Exception handling keywords summary Various possible compile-time errors in exception handling Customized exceptions Top-10 exceptions  4 - String Concept of String Immutable String String Comparison String Conca