Java 駝峰命名法詳解(必看篇)
標(biāo)識(shí)符:
Java對(duì)各種變量、方法和類等要素命名時(shí)使用的字符序列稱為標(biāo)識(shí)符
凡是自己可以起名字的地方都叫標(biāo)識(shí)符
定義合法標(biāo)識(shí)符的規(guī)則:
由26個(gè)英文字母大小寫,0-9,_或$組成
數(shù)字不可以開頭
不可以使用關(guān)鍵字和保留字,但是能包括關(guān)鍵字和保留字
Java中嚴(yán)格區(qū)分大小寫,長(zhǎng)度無(wú)限制
標(biāo)識(shí)符不能包括空格
取名盡量做到“見名知意”
關(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.
來(lái)源:http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.8
一般習(xí)慣:
包名:xxxyyyzzz
類名、接口名:XxxYyyZzz
變量名、方法名:xxxYyyZzz
常量名:XXX_YYY_ZZZ
以上這篇Java 駝峰命名法詳解(必看篇)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java實(shí)現(xiàn)簡(jiǎn)單無(wú)界面五子棋
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)簡(jiǎn)單無(wú)界面五子棋,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05java并發(fā)JUC工具包AtomicInteger原子整型語(yǔ)法基礎(chǔ)
這篇文章主要為大家介紹了java并發(fā)JUC工具包AtomicInteger原子整型語(yǔ)法基礎(chǔ),有需要的朋友可以借鑒參考希望能夠有所幫助,祝大家多多進(jìn)步2022-03-03java向多線程中傳遞參數(shù)的三種方法詳細(xì)介紹
但在多線程的異步開發(fā)模式下,數(shù)據(jù)的傳遞和返回和同步開發(fā)模式有很大的區(qū)別。由于線程的運(yùn)行和結(jié)束是不可預(yù)料的,因此,在傳遞和返回?cái)?shù)據(jù)時(shí)就無(wú)法象函數(shù)一樣通過函數(shù)參數(shù)和return語(yǔ)句來(lái)返回?cái)?shù)據(jù)2012-11-11Java運(yùn)算符的知識(shí)點(diǎn)與代碼匯總
這篇文章主要給大家總結(jié)介紹了關(guān)于Java運(yùn)算符知識(shí)點(diǎn)與代碼的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04Spring?@Scheduled定時(shí)器注解使用方式
這篇文章主要介紹了Spring?@Scheduled定時(shí)器注解使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08