JAVA code development specifications and java code specifications

Source: Internet
Author: User

JAVA code development specifications and java code specifications

I. Development Tool specifications:

1. the development tool is determined after debugging by the project owner.
2. Once the development tool is determined, it is not allowed to integrate any non-uniform plug-ins. If necessary, it should be added to the project team members with the consent of the project owner.
3. The encoding format of the development tool cannot be modified.

Ii. Typographical specifications:

1. Add a space between the keyword (or variable) and the operator. For example, int iCont = 1; // there is a space between the operator and the value.

2. Empty lines are added between relatively independent code blocks and blocks. For example, two methods must be separated by spaces.

3. Long statements and expressions should be divided into multiple books.
4. Long expressions should divide the new line at the lower-priority operator, and the operator should be placed at the beginning of the new line.
5. The new line of the Code and the previous line should be indented according to the logical relationship (a table key), so that the layout is neat and the statement is easy to read.
6. You are not allowed to write multiple phrase sentences in one row, that is, only one statement can be written in one row.
7. The code in the statements such as the start of a function or process, the definition of the structure, and the cycle and judgment should adopt the indent style. Use the TABLE key indent.
8. If a long expression or statement exists in statements such as loop and judgment, an appropriate division is required.
9. If the parameters in a function or process are long, appropriate division is required.
10. when you use braces '{' and '}' to define a block, '{' and '}' should each have an exclusive row and be located in the same column, at the same time, it is left aligned with the statements that reference them. At the beginning of the function body, the definition of the class, the definition of the structure, the definition of enumeration, and the programs in the if, for, do, while, switch, and case statements must adopt the above indent method.

JAVA code development specification (WISHSOFT)

11. main method: if the main (String []) method has been defined, it should be written at the bottom of the class.

Iii. Naming rules:

1. Package name
The Package name must be a lowercase word. Example: package com. wish;

2. Class Name
The Class name must start with an upper-case letter, and all other letters must be lowercase words. For all identifiers

All the words in the middle should be placed together, and the first letter of the middle word should be capitalized. For example:

Public class DatabaseOperator {
}

3. the name of the member variable in the Class must start with a lower-case letter, followed by a word that starts with an upper-case letter, without the need for data types

. For example, userName and size.

4. Name Static Final variable in Class
The names of static Final variables should all be in uppercase and indicate the complete meaning.
For example:
Public static final String DB_CONFIG_FILE_PATH = "com. neu. etrain. dbconfig ";

5. The name of the method in the Class must start with a lowercase letter, followed by an uppercase letter. For example, setName () and getMethod ().

6. In the method declaration, use a meaningful parameter name. If possible, use the same name as the field to be assigned a value. For example:
Public void setCounter (int size)
{

JAVA code development specification (WISHSOFT)

        this.size = size;    }

7. Name the variables in the Method
Class member variable name.

8. array naming
The array should always be named in the following way: byte [] buffer; instead of byte buffer [];

9. The variable of the number of page lists on the page uses pageSize. The current page number is pageNumber. Iv. annotation specifications:

1. Annotations should be simple and clear.
2. Write and annotate the code, modify the code, and modify the corresponding comments to ensure the consistency between the comments and the code.
3. Make comments where necessary. The comments must be moderate. The content of the comment must be clear, clear, and accurate, so as to prevent the ambiguity of the comment. Keep comments adjacent to the code described by them, that is, the proximity principle of comments.
4. Comments of variables and constants should be placed in adjacent positions or the right side above them.
5. global variables should be annotated in detail, including descriptions of their functions, value ranges, functions or processes to access them, and precautions for access.
6. class. The method annotation uses the eclipse automatic generation method.

After writing a complete declaration of a class or method, enter:/** on the top of the class or method (no space allowed) in the English input method, the system will automatically generate their Annotation Templates. You only need to fill in the corresponding instructions. Note: The next line of/** must write functional instructions.
7. Specific requirements:

N Declaration (variable definition class) must be annotated. For example, String myName; // The class definition of user name n must generate a document (JavaDoc) annotation.
The n method must generate a document (JavaDoc) annotation (including the set and get methods of object classes ). N member variables must generate document (JavaDoc) comments.

The logic part of the n method is written by the programmer based on the complexity.

8. annotation information of class definition, including: author; date; module function description (such as function, main algorithm, internal Department

The relationship between the file and other files), historical modification records of the file, and version information.

/**
* What to use (description)

JAVA code development specification (WISHSOFT)

* @ Author lifw20080320
* @ Modify lifw20080321
* @ Modify lifw20080322 (if there are multiple, write multiple @ modify in sequence) * @ copyright wishsoft
**/

9. javadoc annotation label syntax
@ Author the description of the class indicates the author who developed the class module.
@ Version the description of the class indicates the version of the class module.
@ See refers to the instruction of classes, properties, and methods, that is, the description of a parameter in the method described by @ param.
@ Return description of the method description of the return value of the Method
@ Exception description of methods description of possible exceptions thrown by methods

5. Basic data type prefix table (other object types can be supplemented at any time ):

Data Types in Java

Data Type prefix

Int

I

String

Str

Char

C

Long

L

Float

F

Double

D

Boolean

B

Short

S

Byte

Byte

Vector

V

Vi. Log component usage specification (log4j)

1. Log method usage:
A) log. debug () is placed in the middle of the code line for output during debugging. It is permanently retained and does not need to be deleted.
B) log. error () is used in the catch part of try {} catch () {} to output error exception information.

 

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.