JAVA naming and colloquial summary

https://blog.csdn.net/qq_36688143/article/details/79428732

 

First come colloquial summary:

       ① named using nouns

       ② hump nomenclature (Camel-Case): When the function name or variable name is linked together by one or more words, while unique identifier consisting of, beginning with the first letter in lower case, each word capitalized (a first words except). Such as: myFirstName

       ③ project name, package name all lowercase. Such as: com.fxy.dao

       ④ class name capitalized. Such as: StudentAnswer.java

       ⑤ interface class: UserInterface (Dao, Service) .java interface classes: UserInterfaceImpl (Dao, Service) .java

       ⑥ variable name: The basic structure typeVariableName, with a 3-character prefix to indicate the data type. Such as: a defined integer variable: intDocCount

           Avoid Flag state variable named

           It is named using logical variables, such as: blnFileIsFound

       ⑦ static variables: all caps, synthetic multi-word variable using "_" to connect the words. Such as: USER_LIST

 

       ⑧ method: start with a lowercase first letter of each word capitalized (except for the first word). Preferably a verb or verb phrase, or the first word of a verb. Such as: getUserName ()

       ⑨ Web layer (action, controller) Method: language is preferably close to the web, such as register, login, logout

           Services layer method (service): According to the method of naming the behavior, meaning the method of description only and not the purpose of the method name. Such as adding new users of the system, the user can register the front desk, the administrator can also add background, the method can be reused, so it is best not to use use the register, the use of add would be better to write. And related methods avoid the use of the web layer

            Data Layer method (dao): can only insert (insert) delete (delete), update (update), select (to find), (statistical) at the beginning, count

       ⑩ comments (Javadoc): with / ** beginning and end with * / that / ** * / 

           Jsp page name:

               1. In all lowercase English characters and "_" component 

               2. Module name in the overall use of the + operator. Such as: user_view.jsp

               3. Jsp page as far as possible correspond with the action means, such as UserListAction correspond user_list.jsp

 

 

Next is part of the official summary of the document:

First, writing specifications package name (the Package)
   1.1 having a degree of recognition, company names (personal name)
   1.2 lowercase
   such as: com.fxy.dao

two, writing the name of the class specifications (Class)
   2.1 Class name (first letter capitalized other lower case)
       , such as: StudentAnswer.java

   2.2 to distinguish between when the interface and implementation classes, they can add "Impl" behind class.
       Such as: interface class: UserInterface.java interface implementation classes: UserInterfaceImpl.java
   
   2.3 
     . 1, Dao layer
a, interface class: + Interface + Dao physical objects  
   such as: a user interface class Object: UserInterfaceDao, where xxx is the module name.
b, implementation class: entity objects + Interface + Impl + Dao
     such as: a user object implementation class: UserInterfaceImplDao

     2, Layer-Service
        a, interface class: Module + Interface + Service.    
   Such as: a user management interface classes: UserMsgInterfaceServiec
B, implementation class: Module + Interface + Impl + Service
   such as: user management implementation class: UserMsgInterfaceImplServiec

     3, Web layer (action type)
A, implementation class: Module + operation + the Action
   as: User Module User + delete Delete + Action = UserDeleteAction

three, the variable name (see java hump nomenclature, the first letter to start with a lowercase, each word capitalized (except for the first word))
    
    3.1 using the basic structure variable named typeVariableName, 3-character prefix used to represent data types.
Such as: the definition of an integer variable: intDocCount, which indicates that the data type int, back to ideographic English name, capitalize the first letter of each word.

     (Ali Baba Embed table)

 

 

   

  3.2 Variable tips:

       a, without using two different variables represent the same values ​​before and after a period of significance function.

       b, unless it is in the loop, or generally not recommended to use a single letter as a variable name, i, j, k, etc. only as a loop index variable small loop.

       c, avoid using Flag state variable named.

       d, with Is named logical variables, such as: blnFileIsFound. With this affirmation in the form of a boolean variable naming, so that other developers can more clearly understand the meaning of Boolean variables represent. 

      e, if need be abbreviated to the variable name, be sure to pay attention to consistency throughout your code abbreviation rules. For example, if intCnt in certain areas of the code, and in other areas and the use of intCount, will add complexity to the code unnecessarily. Try not to recommend the variable name appears abbreviated.  

 

3.3 static variables

    1, reference java hump nomenclature used to write all uppercase, for variable synthesized using a multi-word "_" is connected to each word. Such as: USER_LIST

3.4 method of naming

    1, reference java hump nomenclature, begins with a lowercase first letter of each word capitalized (except for the first word).

 

    2, shows a method of behavior, it represents an action, preferably a verb or verb phrase, or the first word of a verb.

    3, attributes method: start with / get set, followed by the field names, field names capitalized. Such as: getUserName ()

    4, the data layer method (dao): can only insert (insert), delete (delete), update (update), select (to find), (statistics) the beginning of the count, the other layer method to avoid this five words that begin, in order to avoid misleading.

     5, the service layer method (service): The behavior of a method name, meaning described method only, and not the purpose of the method name. Such as adding new users of the system, the user can register the front desk, the administrator can also add background, the method can be reused, so it is best not to use use the register, the use of add would be better to write. The method avoids using web layer relevant.

     6, Web layer (action, controller) Method: language is preferably close to the web, such as register, login, logout and other methods.

Fourth, writing specifications comments (Javadoc)

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.

package org.ietf.jgss;
import java.net.InetAddress;

import java.util.Arrays;

/**

 * 该类的整体性描述。

 *

 * @author 作者

 * @version 1.0, 05/22/07

 * @since 1.0

 */

public class ChannelBinding {

/**

 * 对该变量的备注信息

 */

private InetAddress initiator;

/**

 * 对该变量的备注信息

 */

private InetAddress acceptor;

/**

 * 对该变量的备注信息

 */

    private  byte[] appData;

  

    /**

     * 对该类的构造函数的备注信息。

     *

     * @param initAddr 对参数的备注。

     * @param acceptAddr对参数的备注。

     * @param appData对参数的备注。

     */

    public ChannelBinding(InetAddress initAddr, InetAddress acceptAddr,

              byte[] appData) {

         initiator = initAddr;

         acceptor = acceptAddr;

         if (appData != null) {

              this.appData = new byte[appData.length];

              java.lang.System.arraycopy(appData, 0, this.appData, 0,

                   appData.length);

         }

    }

 

    /**

     * 对该类的具体一函数的备注信息

     *

     * @param obj 参数的备注信息

     * @return 返回值的备注信息

     */

    public boolean equals(Object obj) {

         if (this == obj)

              return true;

         if (! (obj instanceof ChannelBinding))

              return false;

         ChannelBinding cb = (ChannelBinding) obj;

         return Arrays.equals(appData, cb.appData);

    }

}

Five other writing specifications

    Writing 5.1 Jsp page name specifications
        1. In all lowercase English characters and "_" component.

        2. Module name in the overall use of the + operator. Such as: user_view.jsp

        3. Jsp page as far as possible correspond with the action means, such as UserListAction correspond user_list.jsp


    5.2 Interface: Using camel named. In addition to using the term, but also can be used adjectives name (which embodies features)

    5.3 Methods: The provisions of the verb name for naming a camel, but the biggest difference is that the class name, the first letter must be lowercase

    5.4 Variable: defined as a noun, the other with "method" naming the same. Variable names is critical and should contain specific meaning and easy to understand, generally do not allow the use of a single letter variable names. Unless some temporary variables, like to use in the cycle counters. When using single letter variable names, general I, J, K for naming integer variable.

    5.5 constants: provision represents all capital letters, if the name must use multiple words to express, then between each word with "-" to separate. Constant requirements must be clearly understood by the meaning of the expression constants.

Guess you like

Origin blog.csdn.net/gmaaa123/article/details/92613255