- The Java file consist of section that should be separated by blank lines and optional comments identifying each sections.
- Java Source file longer than 2000 lines are cumbersome and should be avoided.
- Java program must be properly formatted see the example given below.
This example program created by referring Oracle Java Documentation
/*Each sections of the program will be explained in below and upcoming chapters.
* @(#)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...
}
}
Beginning Comments
All source file should begin with c-style comments that list the class name, version information, date and copyrights notice
/*Package and Import statements
* class name
*
* version information
*
* date
*
* Copyrights notice
*/
The first non-comment line of java source file is package statement.After that, import statement.
package com.javatutorialscorner.bestpractice;Class and Interface Declaration
import java.io.*;
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 |
0 comments:
Post a Comment