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