Coding Standard in Java

In this article, We will talk about the Coding Standard, Which we should follow as a programmer.

We all know that programming is used to give instructions to the computer or we can say a machine, To perform a particular task,
So we can say that we are communicating with the machine, However,
Is it okay to write a code just to communicate with the machine?
The simple answer is NO. Anyone can write a program which can be understood by computer or machine.

We should write programs, That can also be understood by other developers, SO they can add new features to the application or fix bugs.

Standardization has a positive impact In the Software Industry, There are some coding standards that are needed for successful software development. For most organizations, the consolidated functioning of software programs is essential for their growth.

A coding standard makes sure, That all the developers working on the project are following certain specified guidelines. The code can be easily understood and proper consistency is maintained.

→The code should be easy to read and maintain.

→We should give the proper name to the functions related to their functionality.

→We should use the comments.

→ We should avoid the functions that are complex or the structure that is difficult to understand.

→ The code should be properly indented.

→In Java if we want to create a variable then we should give that variable name in lower camel case.

Let’s see how we can write standard code in java.

Naming conventions :

a) Package name:

→Package name should be in lower case, Which makes it easy to read and understand that this is a package for example com.firstpackage , java.lang, etc.

→ These are the few name we should not write as a package like: com.FirstPackage, com.NEWPACKAGE, etc.

b) Class and Interface name:

→Class name should be in upper camel case, Which makes it easy to read and understand that this is a class for example NewClass, Car, etc.

→These are the few name we should not write as a class like: newClass, employee_Info, etc.

c) Constants:

→Constants name should be in upper case, Which makes it easy to read and understand that this is a constant for example MAX, DATA, We should use underscore if we want to separate two words then we can use ex: MAX_DATA.

→These are the few name we should not write as a constants like: new_VALUE.

b)Methods:

→Method name should be in lower camel case, Which makes it easy to read and understand that this is a method for example calculateRequests().

d) Variable :

→Variable name should be in lower camel case, Which makes it easy to read and understand that this is a variable for example userName, passWord.

Indentation:

→We should use proper indentation inside the program.

public void printNumbers(){

……… for(int number=1;number<11;number++){

……………..System.out.println(number);

………..}

}

Commenting:

→We can use different comment.

a) Block comment:

/*

*block comment

*/

b) Single-Line Comment:

/* single line comment */

c) Trailing Comment:

for(int i=0;i<10;++i){

………System.out.println(i); //Trailing comment.

Enhanced The Efficiency

→Minimal Complexity

Easy to Maintain

→Bug Rectification

→A Comprehensive Look

→Cost-Efficient

→Risk of project failure is reduced

→Code Comments and Proper Documentation

→Use of Indentation

→Avoid Commenting on everywhere

→group task in different block each block for each task

→Proper and Consistent Naming

→Deep nesting structure should be avoided

→Refactoring of code