Java Development Naming Specification summary _java

Source: Internet
Author: User
Tags constant lowercase

Pre-use considerations:
1, because of Java object-oriented programming characteristics, in naming should try to choose nouns

2, The Hump Nomenclature (camel-case): When the variable name or function name is a combination of one or more words, and the unique identifier that is made up, the first letter starts with lowercase, and the first letter of each word is capitalized (except the first word).

such as: MyFirstName

Writing specification for a package name (Package)
It is recommended that the top-level domain name of a company or organization be prefixed with the name of the package to ensure uniqueness of the package name used within each company/organization. Package names are all lowercase letters and have a practical sense of distinction.

1.1 General requirements
1, choose a meaningful name, can quickly convey the use of the class.

2. All packages must be named in lowercase English letters.

1.2 Practical applications
Application systems often apply hierarchies, DAO layers (Database access), service layer (business process), Web layer (page control action Class).

1, the first few of the package name for a fixed name, if it is the site, the use of the site's domain name reverse write, if the domain name has not been determined, using a fixed number of companies name. such as: Net.vschool

2, the next word in the package name is the name of the module. Such as: User module, package name is Net.vschool.user

3, on the module access operation, the use of layered form, generally divided into:

DAO layer operations: generally defined in Net.vschool.xxx.dao, where xxx is the module name.

Service layer operations: generally defined in Net.vschool.xxx.servie.

Web-tier operations: generally defined in net.vschool.xxx.action.

Examples of user modules are as follows:

Net.vschool.user

Net.vschool.user.dao

Net.vschool.user.action

Net.vschool.user.service

The writing specification of the second class name (Class)
Class names must use nouns, if a class name contains more than one word, then each word is capitalized in the first letter, followed by lowercase letters, undulating hump-shaped, called hump-style naming. When naming a class name, you must ensure that it is accurate, concise, and easy to understand. Try to use complete words and avoid abbreviations (except for everyone's recognition)

2.1 Naming of Classes
2.1.1 General requirements
1, choose a meaningful name, can quickly convey the use of the class.

2, referring to the Java hump nomenclature, the first letter of the class name must take the form of uppercase, if the class name is a combination of multiple words, then the first letter of each word must use uppercase. such as: Studentanswer.java

3, when you want to distinguish between the interface class and implementation class, you can add "Impl" at the back of the class.

such as: interface class: Userinterface.java interface implementation class: Userinterfaceimp

4, the recommended entity class does not have a suffix name.

2.1.2 Practical Application
Applications are often layered, DAO layer (Database access), service layer (business processing), Web layer (page Control action Class), each layer of the class name as far as possible with this layer suffix.

1, DAO Layer

A, interface class: In the form of Javabean+interface+dao to define, that is, the entity object +interface+dao.

Such as: User Object interface class: Userinterfacedao, where xxx is the module name.

B, implementation class: In the form of Javabean+interface+impl+dao to define, that is, entity objects

+interface+impl+dao. Such as: User Object implementation class: Userinterfaceimpldao

2, service layer

A, interface class: The form of xxx+interface+service to define, that is, module +interface+service.

Such as: User Management interface class: Usermsginterfaceserviec

B, implementation class: The form of xxx+interface+impl+service to define, that is, module +interface+

Impl+service. Such as: User Management implementation class: Usermsginterfaceimplserviec

3, the Web Layer (action Class)

A, the implementation class: Uses the county xxx+operator+action the form to define, namely, module + Operation +action. Such as

User Module user+ delete operation delete+action = Userdeleteaction

2.1 Name of the variable
2.2.1 Ordinary Variable
2.2.2.1 General Requirements
1, choose a meaningful name, can quickly convey the purpose of the variable.

2, referring to the Java Hump naming method, the first letter begins with lowercase, each word is capitalized (except the first word).

2.2.2.2 Practical Application
1, the variable name uses the basic structure for the Typevariablename, uses the 3 character prefix to represent the data type.

For example, define a shape variable: intdoccount, where int indicates the data type, followed by the ideographic English name, and the first letter of each word capitalized.

Data type or object type

Variable prefix

Note

Byte

Bye

1, when doing the array, and then prefix-A, such as String array: Astr,

2, the custom type of variable can use its own name, the first letter to lowercase.

3, the use of name to be able to represent the meaning of the method. If the Employee list: EmployeeList

Char

Chr

Float

Flt

Boolean

bln

Integer/int

Int

Short

Sht

Long/long

Lng

Double/double

Dbl

String

Str


2, Variable use skills:

A, not using the same variable in a function to represent two values that are different in meaning.

b, unless it is in the loop, it is generally not recommended to use a single letter as a variable name, I, J, K, etc. only as a small loop of the circular index variable.

C, avoid using flag to name state variables.

D, use is to name the logical variables, such as: Blnfileisfound. By naming the Boolean variable in the affirmative form, the other developers can understand the meaning of the Boolean variable more clearly.

E, if you need to abbreviate variable names, be sure to pay attention to the consistency of the abbreviation rules throughout the code. For example, if you use intcnt in some areas of your code, and you use intcount in other areas, you add unnecessary complexity to your code. It is recommended that you avoid abbreviations in variable names.

2.2.2 Static variables
1, choose a meaningful name, can quickly convey the purpose of the variable.

2, referring to the Java Hump naming method, the use of all uppercase form to write, for the use of multiple-word synthesis of variables using "_" to connect the words. such as: User_list

2.3 Name of the method
2.3.1 General Requirements
1, choose a meaningful name, can quickly convey the use of the method.

2, referring to the Java Hump naming method, the first letter begins with lowercase, each word is capitalized (except the first word).

2.3.2 Practical Application
1. The method represents a behavior, which represents an action, preferably a verb or a verb phrase or the first word as a verb.

2, the property method: Start with Get/set, followed by the field name, field name first letter uppercase. such as: GetUserName ()

3, the data layer method: Only insert (insert), delete (delete), update (update), select (Find), count (statistics) beginning, the other layer method to avoid this 5 words start, lest cause misunderstanding.

4, the service layer method, according to the behavior of the method named, only describes the meaning of the method, and not the purpose of the method named. For example, the system to add new users, users can register in the foreground, but also can be added to the admin background, the method will be reused, so it is best not to use the register, using add will be better written. Avoid using methods associated with the Web layer.

5, the Web layer method is best close to the Web language, such as Register,login,logout and other methods.

Writing specification for three annotations (Javadoc)
In addition to being able to use our common notation (////*//), the Java language Specification also defines a special annotation, which is what we call Javadoc annotations, beginning with/**, and ending with *, Javadoc annotations can be automatically translated into online documents, Eliminates the hassle of writing program documents separately. Recommended use.

Javadoc annotations are mainly about scope: classes, attributes, methods.

For example:

Copy Code code as follows:

Package ORG.IETF.JGSS;

Import java.net.InetAddress;

Import Java.util.Arrays;

/**

* The overall description of the class.

*

* @author Author

* @version 1.0, 05/22/07

* @since 1.0

*/

public class Channelbinding {

/**

* Note Information for this variable

*/

Private inetaddress Initiator;

/**

* Note Information for this variable

*/

Private InetAddress acceptor;

/**

* Note Information for this variable

*/

Private byte[] AppData;

/**

* Comment information for the constructor of the class.

*

* @param initaddr to the parameters of the note.

* @param acceptaddr to the parameters of the note.

* @param AppData to the parameters of the note.

*/

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);

}

}

/**

* Note information for the specific function of the class

*

* @param the note information for the obj parameter

* @return Comment information for return value

*/

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);

}

}


four other writing specifications

4.1 JSP page name writing specification
1. All use lowercase English characters and "_" composition.

2. The overall use of module name + operation form. such as: user_view.jsp

3. The JSP page, as much as possible, corresponds to the meaning of the action, such as the userlistaction counterpart user_list.jsp


Interface:

Use hump-style naming. In addition to nouns, you can also use adjectives to name (reflect their functional characteristics)

Method:

The rule is to name the verb, which is suitable for the hump, but the biggest difference from the class name is that the first letter must be lowercase

Variable:

The term is the same as the "method" designation. Variable names are critical, contain specific meanings and are easy to understand, and generally do not allow a single letter to be used as a variable name. Unless some temporary variables, such as the counters used in the loop. When using a single letter to make variable names, general I, J, and K are used to name the reshaping variables.

Constant:

The provisions are all in uppercase letters, if the name must be expressed in more than one word, then the words between the "-" separated. Constant requirements must have a clear meaning and can express the meaning of constants.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.