We are moved to new domain
Click -> www.ehowtonow.com
Saturday, 14 September 2013

Java Best Practice - File Organization


  1. The Java file consist of section that should be separated by blank lines and optional comments identifying each sections.
  2. Java Source file longer than 2000 lines are cumbersome and should be avoided.
  3. Java program must be properly formatted see the example given below.
Example
This example program created by referring Oracle Java Documentation  
/*
* @(#)JavaTutorialsCorner.java 1.0 2013/08/17
*
* Copyright (c) 2012-2013 Java Tutorials Corner.
* number street, city, state, postal code, country.
* All Rights Reserved.
*
* This software Java Tutorials Best practice tutorials. You shall use it only in
* accordance with the terms of the license agreement of Java Tutorials Corner.
*/
package com.javatutorialscorner.bestpractice;
/**
* Class description goes here.
*
* @version 1.0 17 Aug 2013
* @author Firstname Lastname
*/
public class JavaTutorialsCorner extends Tutorials{

/* A class implementation comment can go here. */
/** classVar1 documentation comment */
public static int classVar1;
/**
* classVar2 documentation comment that happens to be
* more than one line long
*/
private static Object classVar2;
/** instanceVar1 documentation comment */
public Object instanceVar1;
/** instanceVar2 documentation comment */
protected int instanceVar2;
/** instanceVar3 documentation comment */
private Object[] instanceVar3;
/**
* ...constructor JavaTutorialsCorner documentation comment...
*/
public JavaTutorialsCorner() {
// ...implementation goes here...
}
/**
* ...method doSomething documentation comment...
*/
public void doSomething() {
// ...implementation goes here...
}

/**
* ...method doSomethingElse documentation comment...
* @param someParam description
*/
public void doSomethingElse(Object someParam) {
// ...implementation goes here...
}
}
Each sections of the program will be explained in below and upcoming chapters.

Beginning Comments
All source file should begin with c-style comments that list the class name, version information, date and copyrights notice
/*
* class name
*
* version information
*
* date
*
* Copyrights notice
*/
Package and Import statements
The first non-comment line of java source file is package statement.After that, import statement.
package com.javatutorialscorner.bestpractice;

import java.io.*;
Class and Interface Declaration

The below table gives brief introduction about the example program, detailed information will be given in upcoming chapters


Part of Class/Interface Declaration


Description

Class/interface documentation comment(/**….*/) documentation comment used before the class/interface body start.
class or interface statement Class/interface body begins here
Class/Interface implementation comment(/*…..*/) This comment should contain any class-wide/interface wide information that wasn’t appropriate for the class/interface documentation
Class (static) variables Class variables must be declared in following order.

1.public class variable

2.protected class variable

3.private class variable


Instance variables Instance variables must be declared in following order.

1.public class variable

2.protected class variable

3.package level variable (no access modifier)

4.private class variable


Constructor
Methods The methods should be grouped by functionality rather than by scope or accessibility.For example private class method can be in between two public class methods.The goal is to make reading and understanding easier

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: Java Best Practice - File Organization Rating: 5 Reviewed By: eHowToNow