- 雙語版Java程序設計
- 何月順主編
- 261字
- 2018-12-27 20:14:11
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.