Java Naming rules

Source: Internet
Author: User

Java Naming rules

 

Hump rule:

All letters are in lowercase (including abbreviations) and the first letter of the word is in uppercase.

The first letter of each word is capitalized to get a big camper name.

Except for the first word, the first letter of each word is capitalized to get a (small) camper name.

 

In order to avoid ambiguity, the small and medium-sized hump method is called the hump method, and the large hump/Pascal method is called the big hump law.

 

1. Package

Project package naming rules: <domain name reversal>. <team name>. <Project Name>. For related projects, you can use the naming rules of <domain name reversal>. <team name>. <Parent Project Name>. <sub-project name>.

The name must contain lowercase English letters, and cannot contain underscores. (Except constants, underlines and other characters are not recommended in Java Naming Conventions)

Example:

com.cnblogs.niceboat.soyteam.anticorruptionsystem

 

2. Class/Object, Interface

Classes and interfaces use the big camper Method

Abstract classes start with "Abstract ".

The Exception class name uses "Exception" as the end of the class name

The Test class uses "Test" as the end of the class name

 

In interface-oriented programming, the naming rules for interface implementation classes are: <Interface Name> + "Impl ". The Hungarian naming method is forbidden.

Example (correct ):

Interface

Implementation class

HandsomeProvider

HandsomeProviderImpl

 

 

 

 

Hungarian naming method (not recommended ):

Interface

Implementation class

IHandsomeProvider

HandsomeProvider

 

 

 

 

3. Method/Function

The method is named by the camper method. Generally, a verb or verb + noun combination is used.

Set/obtain a value method, named setV/getV

Return length method, named length

Method for Determining boolean values, named isV

To convert an object to a specific type, you should name it toT.

Example:

GetSecretStage ()
Length ()
IsEmpty ()
ToSpecialFormat ()

 





 

4. Variable

Variable naming uses the hump method

Example:

OpenId

 

The name of changliang is separated by uppercase letters and underscores (_).

Example:

MAX_SUITABLE_SIZE

 

 

For more information about the naming rules of the hump rule (especially the abbreviations), see the following table:

Original Camper Method Big hump method Not recommended
Xml http request XmlHttpRequest XmlHttpRequest XMLHTTPRequest
New customer ID NewCustomerId NewCustomerId NewCustomerID
Inner stopwatch InnerStopwatch InnerStopwatch InnerStopWatch
Support IPv6 on iOS SupportIpv6OnIos SupportIpv6OnIos SupportIPv6OniOS
Anglo-Saxon England AngloSaxonEngland AngloSaxonEngland Anglo-SaxonEngland

 

 






 

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.