Coding Standards in Java Programming:

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

Why coding standard is needed?

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:

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

For Interface:

Example: Runnable, Serializable, Comparable, etc.

For Methods:

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

For Variables:

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

For Constants:

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

For Model Class(Java Bean) :

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.

Software Engineer Trainee