Coding Standards in Java Programming:

Satyendra Kumar Gupta
2 min readJun 6, 2021

In this article, we will see about coding standards in java programming.

Why coding standard is needed?

Using good programming style, common idioms, and best practices is essential to produce reliable software efficiently. Good software is quicker to build, cheaper to maintain, and more fun (or at least less difficult) to work with. But no set of rules can cover all situations. You must also have guiding principles. A good start would be to use the following.

Readability: Make your program as readable as possible ( good names, spacing, etc).

Simplicity: Don’t add unnecessary complications and duplication.

Convention: Use standard conventions and good practices as much as possible.

For Classes:

In Java class name should be a noun starting with an uppercase letter. If it contains multiple words then every inner word should start with an uppercase letter.

Example: String, StringBuffer, StringBuilder, ArrayList, etc.

For Interface:

interface name should be an adjective starting with an uppercase letter. If it contains multiple words then every inner word should start with uppercase.

Example: Runnable, Serializable, Comparable, etc.

For Methods:

In the Java method name should either be a verb or verb-noun combination starting with a lower letter. If it contains multiple words then every inner word should start with an uppercase letter (in camel case).

Example: getName(), SetName(), display(), print(), etc.

For Variables:

In java variable name should be a noun starting with a lowercase letter. If it contains multiple words then every inner word should start with an uppercase letter.

Example: name, email, password, mobileNumber, etc.

For Constants:

In the case of a constant value, the name should be a noun. It should contain only an uppercase letter. If it contains multiple words then words are separated with ( _ ) underscore symbol. Usually, we declare constants with public static and final modifiers.

Example: MIN_AGE=18, MAX_PRICE=100, etc.

For Model Class(Java Bean) :

A Java Bean is a simple java class that contains private variables(properties) and public getter and setter methods names.

Getter Methods:

  • It should be a public method
  • Method name should be prefixed with “get”
  • It should not take any argument
  • It Should be a return value based on properties

Setter Methods:

  • It should be a public method
  • Method name should be prefixed with “set”
  • It should take some argument
  • Return Type should be void

Example:

public class EmployeeBean{

private String name;
public void setName(String name){
this.name=name;
}

public String getName(){
return name;
}
}

Note: For boolean properties, the getter method can be prefixed with “get” or “is”.

Conclusion: This article explains the naming convention provided by Java technology. Because 75% to 85% of the lifetime cost of a piece of software goes to maintenance. And code conventions improve the readability of software, allowing new engineers to understand new code more quickly and completely.

Thanks.

--

--