Java 駝峰命名法詳解(必看篇)
標識符:
Java對各種變量、方法和類等要素命名時使用的字符序列稱為標識符
凡是自己可以起名字的地方都叫標識符
定義合法標識符的規(guī)則:
由26個英文字母大小寫,0-9,_或$組成
數(shù)字不可以開頭
不可以使用關(guān)鍵字和保留字,但是能包括關(guān)鍵字和保留字
Java中嚴格區(qū)分大小寫,長度無限制
標識符不能包括空格
取名盡量做到“見名知意”
關(guān)于使用中文,Oracle 官網(wǎng)給出的文檔是這樣描述的:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. Identifier: IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral IdentifierChars: JavaLetter {JavaLetterOrDigit} JavaLetter: any Unicode character that is a "Java letter" JavaLetterOrDigit: any Unicode character that is a "Java letter-or-digit" A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true. A "Java letter-or-digit" is a character for which the method Character.isJavaIdentifierPart(int) returns true. The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\|u0041-\|u005a), and a-z (\u0061-\|u007a), and, for historical reasons, the ASCII underscore (_, or \|u005f) and dollar sign (\$, or \|u0024). The $ sign should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems. The "Java digits" include the ASCII digits 0-9 (\|u0030-\|u0039). Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today, including the large sets for Chinese, Japanese, and Korean. This allows programmers to use identifiers in their programs that are written in their native languages.
來源:http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.8
一般習慣:
包名:xxxyyyzzz
類名、接口名:XxxYyyZzz
變量名、方法名:xxxYyyZzz
常量名:XXX_YYY_ZZZ
以上這篇Java 駝峰命名法詳解(必看篇)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
java并發(fā)JUC工具包AtomicInteger原子整型語法基礎
這篇文章主要為大家介紹了java并發(fā)JUC工具包AtomicInteger原子整型語法基礎,有需要的朋友可以借鑒參考希望能夠有所幫助,祝大家多多進步2022-03-03