A comprehensive interpretation of identifiers in Java

Source: Internet
Author: User

Definition: A symbol that gives a name to a package, class, interface, method, variable, etc., consisting of letters, numbers, $, and _.

Hello   he123$_		world$  good_   $hello     _hello

The letters contain not only English letters, but also Chinese, French, German, Russian, and so on, Java supports the Unicode character set, contains various languages, and recommends the use of English letters.

hello123    Hello 123   привет123   ハロー123  olá123

The above identifiers are legitimate, some rare characters may not be entered in the Unicode character set, when the identifier will be an error, but this is not a fault of the naming rules, is due to not input.

Naming rules:

* *
package name All lowercase, is generally the company domain name inverted write, followed by the project name
Com.alibaba.taobao;

The first letter of the class name is capitalized, after which the first letter of each word is capitalized;
HelloWorld

method and variable name: First letter lowercase, after each word capitalize
a word: sum        int
multiple words: getsum     MaxAge
*

In fact, the package name, class name, method, and variable name, the letter case can be used in any combination of grammar rules are correct, but for the readability of the Code, the Convention moralize the above naming rules.

Note :

 1, the first character of the identifier can not be a number, it is recommended that the first character be in letter, and $ is not recommended as the beginning or the end, because the class containing the member's inner class is compiled as a. class file in the format: out$ Inner.class, with the $ Beginning or end is easy to confuse, where out for the external class name, Inner for the internal class name 2, identifier can not be a keyword in Java or a reserved word, but can contain keywords and reserved word public is not legitimate, because it is Java keywords; hepu

Blic can use Java is strictly case-sensitive, public can be used as identifiers, but it is not recommended that two reserved words goto and const 3, cannot contain spaces Hello World as an identifier is illegal because there are spaces in the middle 

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.