Java development-related naming conventions

Source: Internet
Author: User
Tags naming convention

Java file naming conventions1. Class naming

Abstract classes start with abstract or base.
The exception class ends with exception.
Enum classes use enum as a suffix.
The interface that describes the ability uses able as a suffix.
The implementation class differs from the interface with the suffix impl.
Data class: Table name +do.
Transport class: Domain-related name +dto.
Presentation class: page name +vo.

2.service/dao Layer Method naming

Gets a single object prefixed with get.
Get multiple objects prefixed with list
Gets the statistic value prefixed with count.
Insert prefix with save.
Delete is prefixed with remove.
Modify prefix with update.

Database Naming conventions

Library: Application Name table: Role of Business name _ table (singular form)
Primary key index: PK_ field name
Unique index: UK_ field name
Normal index: IDX_ field name
Indicates whether the field: is_xxxx unsigned tinyint (1. Indicates yes, 0 indicates no)

JUnit unit Test Naming conventions 1. Naming definition specification for test classes

The naming conventions for classes are: Tested business +test, tested interfaces +test, tested classes +test
The name of the class must start with a capital letter and all other letters are lowercase, and if the class name consists of multiple words, the first letter of each word should be capitalized, such as Mobilebindtest. If the class name contains a word abbreviation, each letter of the written word should be capitalized, such as: Xmlexample.

2. Naming definition specification for test cases

test+ use case Operation _ state or test+ use case method Name _ specific test method
The word's contract is named the same as the Test class. such as: Testsetmobilebind_noskyid
For example, to test the use case is "database user information does not exist, get mobile binding message", then its test case name is Testsetmobilebind_noskyid
For example, the method to be tested is findparam, using the boundary value method, then its test case name can be testfindparam_boundaries

3. Package name definition specification for test programs

The package name of the tested class is preceded by "Test." The package name of the class being tested is Com.wistrons.util, so the package name of the test class is test.com.wistrons.util.
The naming rules for a test package are: Test.com.skymobi. Project name; The naming convention for testing public class packages is: Test.com.skymobi.common

4. Naming conventions for variables

First letter in lowercase, followed by the first letter of a word
Example: MaxValue
The variable name should not begin with an underscore or dollar sign, although this is syntactically permissible. Variable names should be short and descriptive. The choice of variable name should be easy to remember, that is, can indicate its use. Try to avoid the variable name of a single character unless it is a one-time temporary variable.

5. Naming conventions for constants

The constant names should all use uppercase letters and underline the words. For example:
Max_value

Version Control tool submission Information naming specification

Line 1th: Submit a summary of the changes (less than 25 characters, no period, use imperative, capital letters start)
Line 2nd: Blank line
After line 3rd: Reasons for the change (about 36 characters in line, what the body explains and why, not how)

Java development-related 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.