Java Development Naming conventions

Source: Internet
Author: User

1. Documents

1. attribute file suffix is properties, and conforms to Java I18N specification;
2. For each product module's own configuration file must be placed in its own module Conf directory;
3. File naming needs to have a certain meaning, as short as possible, the name conforms to the requirements of the operating system and must be in English or Hanyu Pinyin composition, the file name can not have spaces, for ordinary file words and words between the use of a downward line.

2. Naming conventions

2.1 Basic Rules

1. The character set is in 26 English letters, 0 to 9 Arabic numerals and underscores. Java class, field, method, variable, constant as far as possible letter expression, no special reason can not use any other characters
2. Naming needs to have a certain meaning, it is recommended to use the terminology in the problem domain naming, so that the name is to some extent self-describing
3. Name as short as possible, if the name is too long, you can use the way of aliases, or abbreviations to simplify the naming. Abbreviations must have meaning, and need to maintain the meaning of these abbreviations throughout the project
4. Rules for abbreviated names (for class names, field names, variable names, module names, etc.)
1) Delete all the original letters and compress the repeated letters. such as button, abbreviated to BTN,
2) If a naming conflict occurs, the original tone is retained in an abbreviation. such as Batton, in order to not conflict with the button, abbreviated to BATN
5. Do not use a leading underline, or underline the end of a name

2.2 constant naming rules

1. All characters must be capitalized. Use a meaningful combination of words, words and words separated by an "_" underline.
2. Name as short as possible, not more than 16 characters

It is best not to work directly on literal in the development of the program, preferably in a constant manner, only in special cases, such as when initializing variables in a for loop, you can use -1,0,1 of these constants directly

Cases

public final int max_size = 120;public final int max_width = 100;public final String property_name= "menu";

2.3 Variable naming rules

1. Avoid the use of numbers in naming, unless the naming meaning is clear, the program is clearer, there should be no numbers in the naming of instance variables
2. Variable name is noun meaning
3. Use a word or word combination that matches the meaning of the problem domain. The first word is all lowercase, each subsequent word is capitalized in the first letter, and the remainder is lowercase (except for special words, such as URLs)
4. Name as short as possible, not more than 16 characters
5. In addition to temporary variables with a short life cycle, avoid single character as the variable name, and the name of the instance variable should not be used as a single character. Commonly used single-character variables such as Integer with I, J, K, M, n character type with C, D, e, coordinates with x, Y, Z.
6. In some cases, a variable may need to be prefixed with a type, all type prefixes must be lowercase, he has no interval from the entity part of the variable name, every word in the entity is capitalized, the remaining letters are lowercase (except for special words such as URLs), the global variables of the class are strongly recommended, and the generic type prefixes are as follows

Type prefix

Type

Example

B

Boolean, Boolean

Bsingle

F

Floating point number

Fsize

D

Ufdouble

Dmoney

Dt

Date

Dttoday

C

Character, Char

Cinput

Obj

Object variable

objuser

Str

String (string, StringBuffer)

strFileName

I

Integral type number

ICount

ary

Array

Aryname

Conn

Connection

Connactiveconnection

stmt

Statement

Stmtfinduser

Rs

Resultset

Rsusers

ArrayList

Al

Aldata

Map

Map

Key_value_map

Set

Set

ValueSet

Col

Collection

Colnames

Msg

News

Msgtext

Err

Error

Errcode

Btn

Button

Btnsubmit










































Cases
public int width;public String filename;public static ApplicationContext context;

2.4 Method naming rules

1. Use a word or word combination that matches the meaning of the problem domain. The first word is lowercase, each subsequent word is capitalized in the first letter, and the rest is lowercase (except for special words such as URLs), no special reason to use underscores as separators
2. Naming attribute methods in Java follows the JavaBean standard:
1) Getter method: get+ attribute Name, the Boolean type with is+ attribute name, some specific attribute name with has, can instead of is may be better
2) Setter Method: set+ Property name
3. The naming of the construction method is consistent with the class name

2.5 Class and interface naming conventions

1. Use a word or word combination with the meaning of the problem domain, capitalize the first letter of each word, and the remaining letters lowercase (except for special words such as URLs)
2. The first character of the interface uses I

Cases

public class Fiugrepublic interface Fiugrecontainerpublic class stdfigure//STD as standard abbreviation

2.6 Naming conventions for packages

1. All characters in the package name are lowercase;
2. Two different business packages do not rely on two-way, can be one-way dependence;
3. Use a logical hierarchy to reduce dependencies

Java Development Naming conventions

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.