Java Programming specification

Source: Internet
Author: User
Tags uppercase letter to domain

I. Common naming conventions (1) Hungarian nomenclature

The more famous naming conventions are the Hungarian nomenclature, but the nomenclature is a disaster for cross-platform porting. This naming method was proposed by Microsoft programmer Charles Simonyi Charles Simonyi. The main idea is to "add prefixes to variables and function names to improve people's understanding of the program". The key to the Hungarian nomenclature is that the name of the identifier is prefixed with one or more lowercase letters, followed by a word or combinations of words that are capitalized in the first letter, which indicates the purpose of the variable. For example: Lpszstr, which represents a long-pointer (LP) variable that points to a string (SZ) ending with '/'.

(2) Camel name law

Camel's nomenclature has become more and more popular in recent years, with many new libraries and Java-based platforms being used properly. The camel nomenclature, as its name implies, refers to the mixture of uppercase and lowercase letters to form the name of an identifier. One of the first words is lowercase, and the remaining words are capitalized in the first letter. For example: Printemployeepaychecks (), each logical breakpoint in the function name is marked with an uppercase letter.

(3) Pascal's name Law

Pascal (Pascal) nomenclature is similar to the Camel name law. Except that the camel name is the first lowercase letter, and the Pascal nomenclature is the first letter of a word capitalized. For example: DisplayInfo () and username are all using the Pascal nomenclature.
In C #, the name of Pascal and the name of the camel are mostly. In fact, many programmers use camel nomenclature and Pascal in the actual naming process, such as the name of the variable named Camel, and the function using the Pascal name method.

(4) Underline naming method

The underline is popular with the advent of the C language, in environments such as Unix/liunx, and in the GNU code.
For several of these naming conventions, we think that comparing the description of variables or functions is camel naming and underline naming, so we recommend using both of these naming aspects.

Ii. Java naming Style (1) package naming

Package names are listed by domain name from large to small, just as opposed to domain naming rules on the Internet.

By a group with "." The identifier of the connection is composed, usually the first identifier is two or three lowercase letters that conform to the network domain name.

 Package Cn.edu.scau.mk.testdemo;

(2) class, interface naming (Pascal name method)

The name of the class must start with a capital letter and the other letters in the word are lowercase, and if the class name consists of multiple words, the first letter of each word should be capitalized such as Testdemo, and if the class name contains a word abbreviation, each letter of the word should be capitalized, such as: Xmlmanager, One more naming technique is that because a class is designed to represent an object, you should choose a noun when you name the class.

 Public class Testdemo {}

(3) Method name (hump naming method)

The first word of the name of the method should begin with a lowercase letter, and the following words begin with a capital letter. can be a verb or verb + noun combination.

1, set/Get a value of method, should follow the SETV/GETV specification (v is the variable name)

2, return the array length method, should be named length

3, return the set length method, should be named size

4, test A Boolean value of method, should be named as an ISV

5. Converting an object to a specific type of mehod should be named Tot (T is a type name)

 PackageCn.edu.scau.mk.testdemo;Importjava.util.ArrayList;Importjava.util.List;/** * * @authorMK*/ Public classTestdemo {Private intKey=0; Private BooleanFinish=false; Private int[] scores=New int[2]; PrivateList<string> names=NewArraylist<>(); /**     * @returnThe key*/     Public intGetKey () {returnkey; }    /**     * @paramkey The key to set*/     Public voidSetkey (intkey) {         This. Key =key; }    /**     * @returnThe finish*/     Public BooleanIsfinish () {returnfinish; }    /**     * @paramfinish the finish to set*/     Public voidSetfinish (Booleanfinish) {         This. finish =finish; }          Public intLength () {returnscores.length; }         Public intsize () {returnnames.size (); }}

(4) Variable name (hump naming method)

The normal variable name should be in the first letter lowercase, the other letter capitalized the way.

 Public class Testdemo {    private  String personname;}

(5) Static constants

The name of the final static variable should be capitalized and indicate the full meaning. If a constant name consists of multiple words, you should use underscores to split the words.

 Public class Testdemo {    staticfinal String person_name= "Jack";    }

(6) Logical variables

Avoid naming state variables with flag, and use is to name logical variables.

 Public class Testdemo {    privateboolean  isfinish;}

(7) Array

Arrays are always defined in the following ways:

int[] arr = new INT[10];

Prohibition of the use of C language is the form:

int New int [2];

(8)Generic Parameters

The element in the container should be denoted by e, and the key in the map is denoted by K, and value is denoted by T with V;type, and the exception is denoted by x

If you need to receive more than one type of parameter, you should use the uppercase letter of the adjacency T--for example, s--to indicate it in order, and of course you can use T1, T2 this way

If the paradigm method exists in the generic class, try to avoid using the same type Variable Names, so as not to confuse

 Public class extends Abstractset<e> {
}publicclassextends abstractmap<k, v> {
}publicclass threadlocal<t> {
}publicinterfaceextends throwable> { throws X;}

(9) Recommended naming

1. When you want to distinguish between an interface and an implementation class, you can add "Impl" to the class.

Interface container{} class Implements container{}

2.Exception class is best to use "Exception" as the end of class naming

class extends exception{} class extends exception{}

3: Abstract class is best to use "abstract" as the beginning of the class naming

Abstract class abstractbeandefinition{} Abstract class abstractbeanfactory{}

4. The test class should be able to use "test" as the end of the class name

class persontest {}

5. Abbreviation and abbreviations (deprecated)

CP representative COLORPOINTBUF on behalf of Bufferoff on behalf of Offsetlen representative length

Unless it is in the loop, it is generally not recommended to use a single letter as the variable name, but there are exceptions to the conventional single letter

B on behalf of BYTEC representative Chard on behalf of Doublee representative Exceptionf on behalf of Floati, J, K for Integer l for Longo on behalf of objects on behalf of STRINGV for certain types of specific values

Java Programming specification

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.