JAVA based learning _ naming conventions and comments

First, the naming convention

 

1,  project name all lowercase

2,  the package name unified lowercase, and only separated by a natural break between the semantics of English words, including the name of the unified use of the singular form. If the class name has the plural, the plural form of the class name can be used.

Practical applications:

  The layers were naming convention:
  A)-Service / naming convention method of the DAO layer
    1) a method of obtaining a single object with a prefixed get.
    2) obtaining a plurality of object methods prefixed with list.
    3) obtain a statistical value of the method prefixed with count.
    4) insertion method save (recommended) or insert prefixed.
    5) Remove method using remove (recommended) or delete prefixed.
    6) using the modified method prefixed update.
  B) the naming convention domain model
    1) Data Object: xxxDO, xxx is the table name.
    2) Data Transfer Object: xxxDTO, xxx is the name associated with the business.
    3) display objects: xxxVO, xxx generally page name.
    4) POJO is DO / DTO / BO / VO collectively prohibited named as xxxPOJO.

3,  the class name capitalized, if the class name consists of several words, the first letter of each word should be capitalized, must comply with the hump form .

如:public class MyFirstClass{}

  Abstract class name or the beginning of the use Abstract Base; exception class named using ends Exception; test class named after the name of its class to be tested beginning to the end of the Test.

For Service and DAO classes, based on the concept of SOA, must be exposed service interfaces, internal interfaces of the implementation class with the suffix Impl the difference.

Recommended entity class has no suffix.

Boolean variable of type POJO class, do not add is, or part of the analytical framework will cause serialization error.

4,  variable names, method names first letter lowercase, if the name consists of multiple words, the first letter of each word should be capitalized.

Such as: int index = 0;

       public void toString(){}

5, Constant naming all uppercase, separated by an underscore between words, semantic integrity and strive to clear, not too long name. For example: MAX_NAME_LENGTH

6, all naming conventions must follow these rules:

1), the name can only consist of letters, numbers, underscores, $ symbols

2) can not start with a number

3) the name JAVA keywords can not be used.

4), determined not to appear in Chinese and pinyin name.

7, the source file name: source file name must be the same as the class name. When saving files, you should use the class name as the file name to save (Remember that Java is case-sensitive), the file name extension is .java.
(If the file name and class name are not the same will result in a compilation error).
Method main entrance: all the Java programs public static void main (String [] args) method to begin.

Second, the specification comments

Java can be used in addition to our common way of comment (//, / * * /) outside, Java language specification also defines a special comment, it is what we call the Javadoc comments to / ** at the beginning, and to * / end, Javadoc comments can be automatically converted to online documents, eliminating the hassle of separate programming documents. Recommended Use.

Javadoc comment relates range: classes, properties, methods:

1,    class comments

Must be added in front of each class of Note, Notes templates as follows:

/**

* Copyright (C), 2006-2010, ChengDu Lovo info. Co., Ltd.

* FileName: Test.java

* Detailed description of the class

*

* @Author creator class name
    * @Date creation date

* @version 1.00

*/

 

2,    property comments

Notes property must be added in front of each attribute, comment template as follows:

/ * Message * /

private String strMsg = null;

 

3,    method comments

In front of each method must be plus method comments, which templates are as follows:

/**

* Class methods detailed instructions

*

* @Param parameter 1 parameter descriptions 1

* @Return returns the result of instructions

* @Throws Exception type Error code indicate throw from such methods described abnormalities

*/

4,    configuration method comment

Comments must be added in front of each constructor, comment template as follows:

/**

* Detailed instructions constructor

*

* @Param parameter 1 parameter descriptions 1

* @Throws Exception type Error code indicate throw from such methods described abnormalities

*/

 

5,    method internal Notes

The method of single-line or multi-line inside comment, the comment is added according to the actual situation.

Such as: // background color

       Color bgColor = Color.RED

 

. 1  Import the java.net.InetAddress;
 2  Import java.util.Arrays;
 . 3  / ** 
. 4  * class described integrity.
. 5  *
 . 6  * @author OF
 . 7  * @version 1.0, 05/22/07
 . 8  * @Since 1.0
 . 9   * / 
10  public  class the ChannelBinding {
 . 11  / ** 
12 is  * Note that variable information
 13 is   * / 
14  Private InetAddress Initiator ;
 15  / ** 
16  * Note that variable information
 17   * / 
18 Private InetAddress Acceptor;
 . 19  / ** 
20 is  Remarks * the variable information
 21 is   * / 
22 is      Private   byte [] appData;
 23 is     
24      / ** 
25       Remarks * constructor information that class.
26       *
 27       * @param initAddr notes on parameters.
28       * @param acceptAddr notes on parameters.
29       * @param appData notes on parameters.
30       * / 
31 is      public the ChannelBinding (InetAddress initAddr, InetAddress acceptAddr,
 32                byte [] appData) {
 33 is          = Initiator initAddr;
 34 is           Acceptor = acceptAddr;
 35           IF (! appData = null ) {
 36                the this .appdata = new new  byte [appData.length];
 37 [                java.lang.System.arraycopy (appData, 0, the this .appdata, 0 ,
 38 is                     appData.length);
 39           }
 40      }
 41 is    
42 is      / ** 
43 is       * a function of the particular remark information class
 44 is       *
 45       * @param obj parameter comment information
 46      * @Return return information value Remarks
 47       * / 
48      public  Boolean the equals (Object obj) {
 49           IF ( the this == obj)
 50                return  to true ;
 51 is           IF ((obj! The instanceof the ChannelBinding))
 52 is                return  to false ;
 53 is           the ChannelBinding CB = (the ChannelBinding) obj;
 54 is           return that Arrays.equals (appData, cb.appData);
 55      }
 56 is }

 

Excerpt to: https: //www.cnblogs.com/FocusIN/p/5811189.html

https://www.cnblogs.com/zshibo/p/8007123.html

Guess you like

Origin www.cnblogs.com/Bokeyan/p/10983188.html