Java naming rules detailed summary _java

Source: Internet
Author: User
Tags constant int size lowercase

1. The Java source file name Java source filename must be the same as the class name of the class defined in the source file.

2. the first part of the named package name of the package should be lowercase ASCII characters and is one of the top-level domain names, usually com, edu, gov, mil, net, org, or a nationally unique flag defined by ISO standard 3166 and 1981. The subsequent part of the package name is determined by the internal naming rules of the organizations, and the internal naming rules specify the directory names of the components, their department names, project names, and so on.

3. The named Class name of the class/interface should be a noun with the first letter capitalized. The name should be concise and descriptive. The name of the exception class should end with exception. Interface's naming rules are the same as class.

4. The letters of the named constant name of a constant should all be capitalized, different words are connected by underlining, and the name combination should be given meaning.

5. Name of variable

5.1 Ordinary variable ordinary variable name first letter lowercase, each other word of the first letter uppercase. The name should be short and have a specific meaning, concise and clear to the user to show their use intent.

5.2 The agreed variable, the so-called contract variable, refers to the temporary variables that can be discarded after use (throwaway). Normally I, J, K, M, and n represent integer variables, and C, D, and E represent character-type variables.

6. The first word of the method's named method name should be the verb, and the first letter is lowercase, and the first letter of each other word is capitalized.

7. Name of method parameterYou should select a meaningful name as the parameter name for the method. If possible, select the same name as the field that you want to assign the value to.

Supplementary information:

1. The first letter of class name should be capitalized. Properties (member variables), methods, object variables, and all identifiers (such as formal arguments, actual arguments, local variables) should be lowercase, with all the words in them close together, and the first letter of the middle word capitalized. For example:
Class Name: Thisisaclassname property or method Name: Thisismethodorfieldname object variable: thisisaclassvariable

2, Java package (Package) is a special case, they are all lowercase letters, even if the middle of the word is so. For global packages, reverse your Internet domain name and connect to the package name. For example:
Cn.edu.usst.dingyuewei.package.
In addition, before the import line, the standard package names in import are preceded by the local package name and are sorted alphabetically by package. If the import row contains a different subdirectory in the same package, it should be treated with *. For example:

Package hotlava.net.stats;
Import java.io.*;
Import java.util.Observable;
Import hotlava.util.Application;

Here java.io.* is used to replace InputStream and OutputStream.

3, Interface (INTERFACE): Use the complete English Descriptor Description Interface encapsulation, all words first letter capitalization. In custom, the name is followed by a suffix able, ible or ER. For example: Contactable,prompter.

4, the component (Component) uses the complete English description to explain the component use, the end Bell the component type. For example: Okbutton,customerlist,filemenu.

5, the class of common methods of naming:

A The method of obtaining a class (typically with a return value) typically requires the name of the field to be accessed using the method name, preceded by a prefix get, such as Getfirstname (), Getlastname ().

b The Boolean judgment method of class generally requires the method name to be prefixed with the word is, such as ispersistent (), isstring (). Or use words that have logical meanings, such as equal or equals.

c) The set method of the class (the general return type is void): The name of the field being accessed is preceded by a prefix set, such as Setfirstname (), Setlastname (), Setwarpspeed ()

D The general method of class generally uses the complete English Description member method function, the first word uses as far as possible a vivid verb, the first letter lowercase, for example openfile (), AddAccount ().

E The construction method should be written in an incremental manner (e.g., the parameter is written in more than the following). For example:
Public CounterSet () {}
public counterset (int size) {this.size = size;}

F) ToString method: In general, each class should define the ToString method, in the format of: public String toString () {...}

g) You should generally consider placing a main () method that contains the code for testing that class, and if the main () method is included, it should be written at the bottom of the class.

6, static constant fields (static final) generally all uppercase, the words are separated by an underscore (there are special cases, such as the Java class Library on the color of the constant does not strictly use all uppercase letters). such as Min_balance,default_date.

7, the cyclic counting variable usually uses the letter i,j,k or the counter. The array should always be named in the following way: objecttype[] or byte[] buffer.

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.