Naming of the package
The package name should be made up of a lowercase word.
Name of Class
Class names must be made up of uppercase letters and other lowercase words.
Name of Class variable
The name of the variable must begin with a lowercase letter. The following words start with capital letters.
Name of the Static Final variable
The name of the Static Final variable should be capitalized and indicate the full meaning.
Name of the parameter
The name of the parameter must be the same as the variable's naming convention.
Naming the array
Arrays should always be named in the following way:
byte[] buffer;
Instead of:
BYTE buffer[];
Parameters of the method
Use meaningful parameters to name them, and, if possible, use the same names as the fields to be assigned:
Setcounter (int size) {
this.size = size;
}
Java File Styles
All Java (*.java) files must adhere to the following style rules
Copyright information
The copyright information must be at the beginning of the Java file, such as:
/**
* Copyright? 0?3 Shanghai XXX Co. Ltd.
* All right reserved.
*/
Other information that does not need to appear in Javadoc can also be included here.
Package/imports
Before the package line is to be import, the standard package name in import is preceded by the local pack name and is sorted alphabetically. If the import row contains a different subdirectory in the same package, it should be handled with *.
Package hotlava.net.stats;
Import java.io.*;
Import java.util.Observable;
Import hotlava.util.Application;
Here java.io.* used instead of InputStream and OutputStream.
-
class
The next is the comment of the class, which is generally used to interpret the class.
/**
* a class representing a set of packet and byte counters
* it is observable to allow it to be watched , but only
* reports changes when the current set is Complete
*/
Next is the class definition, which contains extends and implements
public class on different lines CounterSet
extends observable
implements cloneable
Class fields
Next is the member variable for the class:
/**
* packet counters
*/
Protected int[] packets;
The member variables of the public must generate a document (JAVADOC). Proceted, private, and package defined member variables can have no comment if the name has a clear meaning.
-
Access Method
Next is the method of accessing the class variable. It is simply used to get the value of the class variable assignment, which can be simply written on one line.
/**
* get the counters
* @return an array containing the statistical data. this array has been
* freshly Allocated and can be modified by the caller.
*/
Public int[] getpackets () { return copyarray (packets, offset); }
Public int[] getbytes () { return copyarray (bytes, offset); }
Public int[] getpackets () { return packets; }
Public void setpackets (Int[] packets) { this.packets = packets; }
Other methods do not write on one line
-
constructor
Next is the constructor, which should be written in an incremental manner (e.g., the number of arguments is written in the back).
Access type ("Public", "private" etc.) and any "static", "final" or "synchronized" should be on one line, and the method and parameter write another line, which makes the methods and parameters easier to read.
Public
CounterSet (int size) {
This.size = size;
}
Cloning method
If this class can be cloned, the next step is the clone method:
Public
Object clone () & nbsp {
try {
counterset obj = (CounterSet) super.clone ();
obj.packets = (int[]) packets.clone ();
Obj.size = size;
Return obj;
}catch (clonenotsupportedexception e) {
Throw new internalerror ("Unexpected clonenotsupportedexception: " + e.getmessage ());
}
}
-
class method
The method to begin writing the class:
/**
* set the Packet counters
* (such as when restoring from a database)
*/
Protected final
Void setarray (INT[] R1, INT[] R2, INT[] R3, INT[] R4)
Throws illegalargumentexception
{
// ensure the arrays www.gzlij.com are of equal size
if ( r1.length != r2.length | | r1.length != r3.length | | r1.length != r4.length)
Throw new illegalargumentexception ("Arrays must be of the same size ");
System.arraycopy (r1, 0, r3, 0, r1.length);
System.arraycopy (r2, 0, r4, 0, r1.length);
}
ToString method
In any case, each class should define the ToString method:
Public
String toString () {
String retval = "CounterSet:";
for (int i = 0; i < data.length (); i++) {
retval + = data.bytes.toString ();
retval + = data.packets.toString ();
}
return retval;
}
}
Main method
If the main (string[]) method is already defined, it should be written at the bottom of the class.