双语版Java程序设计
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人

2.9 Identifiers

These are the names you get to make up for classes, methods and variables like args and HelloWorld in the HelloWorld example. An identifier is any sequence of uppercase letters, lowercase letters, digits, $, and _ (underscore), except that it cannot start with a digit to avoid confusion with numbers. The set of “letters” in Java is much broader than in most other programming languages. Java letters include the symbols from most written languages used in the world today.

必须给类、方法和变量加上名字,例如args and HelloWorld in the HelloWorld example。标志符可以为任何大写字母、小写字母、阿拉伯数字、$和_(下画线),但是不能以阿拉伯数字开头,以防与数字混淆。

Here are some legal identifiers:

helloWorld $$$$$$ you_can_almost_make_a_sentence

_something x12345 $__$123

Here are some illegal identifiers:

123 x+y some***name no space 1floor

Some naming conventions (not required rules) used by many Java programmers are

(1)class names start with uppercase and capitalize embedded words - e.g. HelloWorld

(2)public methods and variables start with lowercase and capitalize embedded words-e.g. drawOval

(3)private and local variables are all lowercase, separating words with underscore-e.g. loop_index, input_value

(4)Although legal, the dollar sign “$” should not be used except in machine generated Java programs.