The purpose of programming standards is to support the development of consistent and well-written applications. It helps developers to create a code base with a uniform presentation, which is understandable, reusable and maintainable. It also helps developers to avoid common pitfalls of Java that leads to robust, reliable and portable code. In series of articles I will touch upon various aspects of Java coding standards,best practices and guidelines.
While writing Java classes it is quite important how you layout your code.It means how you structure and order constituents of your Java code.The order in which package,import statements and file header are placed:
- The first line of code represents 'package declaration'.
<blank line>
- The import list in sorted order
<blank line>
- The file header
It is important to have specific import statements rather with suffix '*'.Hence no "*" in import statements.You must separate Sun classes and project specific classes.The order in which the parts of a class or interface declaration should appear in the java files is as below:
a. Class/interface documentation comment (/**...*/)
b. Class or interface statements
c. Class/interface implementation
comment (/*...*/), if necessary
{This comment should contain any class-wide or interface-wide information that wasn't appropriate for the class/interface documentation comment.}
d.Variables should always be defined before constructors and methods, irrespective of the order of variable declarations.
e.Constructor(s)
f.Method(s)
In next post, I will discuss about how we should document our code so that Javadoc utility will help build the documentation from code.
1 comments :
I'm a beginer to Java and the post is really useful..
Post a Comment