Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java Coding Standards

In this Post describes a collection of Coding Standards for programmers written in Java language. This Post is very useful all Java Software Developers. Whenever you try to learn new language one of the first thing you should determine what coding standards and guidelines for that language exist.

Benefits of Standard coding:

  • Improve the readability 
  • It makes easier to sharing of code among different programmers,when you working on the same project
  • It allows easier development of automated tools to assist in the program development


The fallowing are the Java Coding Standard Guidelines:


Coding standard for class:
The Class name should be noun. The class name should start with Upper case letters and if contains multiple words every inner word also should start with capital letters.

Example: 
String
StringBuffer
NullPointerException
EmpAge

Coding Standard for Interface:

Interface also fallows just like class guidelines, interface name should be adjective. The interface name should start with capital letters and if it contains multiple words,every inner word also should start with capital letters.

Example:

Clonable
Serilaizable
Runnable




Source File Organization:

A Java Source file shall contain a single public class or interface. A public class should be the first class or interface declaration in the file.

A Java Source File should contain the fallowing order:


  • Package Declaration;
  • Import Declaration;
  • Class comments including description,author and version
  • One or more class or interface declarations. Starting with the public class or interface declaration.


 Coding Standards with methods:

It starts with lower case and every inner words starts with upper case letters. This convention is also called as Camel case convention

Example:

toString()
getMessage()
getName()
display()
show()

Coding Standards for Variables:

The variable starts with noun and every inner word should start with upper case. That means camel convention.

Example:

studentName;
rollno;
totalNumber;

Coding Standards for Constants:

It contains only Upper case letters and separated with Underscores.

Example:

MAX_SIZE
MIN_SIZE
COLLEGE_NAME
MAX-PRIORITY


Java Bean Coding Contraventions:

Here Java Bean is a normal java class with private properties and public getter & setter methods.

Example:

Public class StudentBean
{
private String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
}

Modifier Order:

The order in which code appears based on the modifiers is a matter of style. So, the fallowing order should be used.


  • public
  • protected
  • private
  • abstract
  • static
  • final
  • transient
  • volatile
  • synchronized
  • native
  • strictfp


Read Also : Java 7 new features






This post first appeared on Learnprogramingbyluckysir, please read the originial post: here

Share the post

Java Coding Standards

×

Subscribe to Learnprogramingbyluckysir

Get updates delivered right to your inbox!

Thank you for your subscription

×