您好,登錄后才能下訂單哦!
標識符:
Java對各種變量、方法和類等要素命名時使用的字符序列稱為標識符
凡是自己可以起名字的地方都叫標識符
定義合法標識符的規則:
由26個英文字母大小寫,0-9,_或$組成
數字不可以開頭
不可以使用關鍵字和保留字,但是能包括關鍵字和保留字
Java中嚴格區分大小寫,長度無限制
標識符不能包括空格
取名盡量做到“見名知意”
關于使用中文,Oracle 官網給出的文檔是這樣描述的:
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 駝峰命名法詳解(必看篇)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。