Look at the Java code development specifications it! good for everyone!

Preface:

Episode: Timo time and rework, double, Cheese, Li, extended! Bed - the computer - the table - the computer - the table - the living conditions of more than 10 days in bed!

As a developer, when you take over someone else's project, and when you read other people's code, is not encountered head congestion, Java make you feel "away" feeling? Before we develop with Java development technology, we must firmly adhere to the Java development standards, so the only way you can sum Java development more smoothly. And mastering the Java development skills, you can let you work together more efficiently.

A layout specifications:

  1. A space between the keywords (or variable) and operators. For example: int iCont = 1; // there is a space between the operator and value.

  2. Plus blank line between opposing separate code block to block. For example: a space between the two separated with either method.

  3. Longer statements, expressions, etc. to be divided into multiple lines written.

  4. To divide long expression in a new line of low priority operators, the operators on the first of the new line.

  5. The new line of code in accordance with the logic on line to indent (a key table) adapted to the layout neat, legible statement.

  6. Do not allow multiple short statement written on one line, that line of writing only one statement.

  7. Start function or process, and the cycle definition structure, judgment of code statements have indented style. Using TABLE key to indent.

  8. Cycle and judgment statement if the statement or expression longer, will have to be divided adaptation.

  9. If the function or process parameters is longer, it will have to be properly divided.

  10. Braces '{' and '}' defining a program block, when the block write '{' and '}' should each separate line in the same column and, simultaneously with left-justified statements that reference them. In the beginning of the function of the definition of class definition of the structure, and the definition of the enumeration if, for, do, while, switch, case statement must procedure as above using indentation.

JAVA code development specification (WISHSOFT)

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

Second naming convention:

1.Package (package) name

Package names should be lowercase words are from a composition. For example: package com.wish;

2.Class named

Class names must begin with a capital letter and other letters are lowercase word composition for all identifiers, which

All the words contained shall close together, and the initials middle of a word. E.g:

public class DatabaseOperator { }

Named variables 3.Class member variables must begin with a lowercase letter, followed by a word beginning with a capital letter, no data type prefix. For example: userName, size.

4.Class in Static Final Variable naming

Static Final variable name should be capitalized, and pointed out that the full meaning.

E.g:

public static final String DB_CONFIG_FILE_PATH ="com.neu.etrain.dbconfig";

Words that begin naming names of 5.Class method must be a word with lowercase letters, followed by a capital letter at the beginning. For example: setName (), getMethod ().

6. The method declaration parameter name with a meaningful parameter name, if possible, and use the fields to be assigned the same name. E.g:

public void setCounter(int size) {

JAVA code development specification (WISHSOFT)

this.size = size;

}

The method of the variable name

Named in Class member variables.

8. named array

Array should always be named in the following way: byte [] buffer; instead: byte buffer [];

9. tab page lists the number of variables pageSize, where the current page number pageNumber.

Three comments specification:

1. Notes should be simple and straightforward.

2. The side edge writing code comments, modify the code at the same time modify the notes, in order to ensure consistency with the annotated code.

3. Where necessary annotations, to moderate volume. The content of comments to make it clear, clear, precise meaning, to prevent ambiguity comment. Notes held adjacent thereto description code, i.e., annotations proximity principle.

4. variables, constants should be placed above it notes or right adjacent positions, not at the bottom.

The global variables to have more detailed annotations, including its function, the range, in which it functions or procedures and precautions access accessing FIG.

6. Note class, using the method of automatic generation method eclipse.

After the declaration of a class, or method of writing complete, just above the class, method (not allowed to have spaces) entered in the English state input method: / ** later, the system will automatically generate their comments template, we only need to fill in the appropriate captions can pay attention to: / ** next line must write the functional description.

7. Specific requirements Description:

n declarative (defined class variables) must be annotated. For example: String myName; // username n must be generated class definition document (the JavaDoc) annotations.

The method of generating a document to be n (the JavaDoc) Note (including entity class set, get method). n member variables must generate documentation (JavaDoc) annotations.

N logic portion by a programming method according to the writing person itself complications.

8. Note class definition information, comprising: author; date; Description Function module (e.g., function, main algorithm, within departments

The relationship between points and the relationship with other document files, etc.); modify this file history record; version information.

/**

* Used to do (description)

JAVA code development specification (WISHSOFT)

*@author lifw20080320

*@modify lifw20080321

* @ Modify lifw20080322 (if there is more, in order to write more @modify) * @copyright wishsoft ** /

9.javadoc comment tag syntax

@Author description of the class indicated the development of the class module

Description @version indicate the class of the class module version

@See described with reference to the steering classes, attributes, methods, i.e. a method described @param topic description of a process parameter

Description of the method described @return return value of the method

@exception description of the method may be thrown by a method explained

Four basic data type prefix table (other object types, added at any time):

Preparation of specifications V. Methods

1. member method, do not easily adopt a public member variables. The main modifiers have public, private, protected, no

2. The method of process air and functions thereof may be declared in a row. Such as: void func () {}

3. The blank line between and a method

4. A method in documentation comments immediately preceding method, is not a blank line.

5. Avoid excessive parameter list, ideally controlled within 5, if the need to pass a plurality of parameters, when an object is used to accommodate a transfer of these parameters in order to improve the readability and scalability

6. The method of latent circulating jacket layer can not exceed 2

7. For subclass does not need to reload during the design classes, to make use of final

8. The method as far as possible the number of lines of code each as not more than 100 lines (effective line of code, not including comments), but must ensure the integrity of the logic

9. When the interface default level is protected, only a confirmation of other subsystems package calls the method of their own subsystem interface, it will expose the method as public.

VI. Language and writing specifications

1. The definition of a variable with the same name to avoid a layer of variable scope.

With the desired separated by a blank line between Method 2 and Method

3. Local variables declared at time of use, local variables / static variables are initialized at the same time when they are declared

4. In comparison with the time constant of the constant in front of such comparison expression:

if(“simpleCase”.equals(obj))… if(null == obj)….
复制代码

5.return statement, do not have complex operations.

6.switch statement requires a default branch

Written in the last:

This article to end here! If this article there are any errors, comments or suggestions, be grateful!

There are now more than 1,000 tidy road company java face questions over 400-page pdf document, sub-themes have been collated. There are hundreds of pages of Java core knowledge PDF, and massive learning materials

(No public concern: JavaTimo reply: PDF to) all the way to seek praise! Thank you!

Guess you like

Origin juejin.im/post/5e43b6786fb9a07c951ccd4b