欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java 驼峰命名法详解(必看篇)

程序员文章站 2023-12-22 09:36:40
标识符: java对各种变量、方法和类等要素命名时使用的字符序列称为标识符 凡是自己可以起名字的地方都叫标识符 定义合法标识符的规则: 由26个英文字母大小写,...

标识符:

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 驼峰命名法详解(必看篇)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

上一篇:

下一篇: