Java 驼峰命名法详解(必看篇)
标识符:
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 驼峰命名法详解(必看篇)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
idea 隐藏target,iml等不需要展示的文件(推荐)
这篇文章主要介绍了idea 隐藏target,iml等不需要展示的文件,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-11-11MyBatis中resultType和parameterType和resultMap使用总结
这篇文章主要介绍了MyBatis中resultType和parameterType和resultMap使用总结,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-11-11java基本教程之java线程等待与java唤醒线程 java多线程教程
这篇文章主要介绍了对线程等待/唤醒方法,文中使用了多个示例,大家参考使用吧2014-01-01
最新评论