【Java专题】标识符和关键字
本篇记录标识符使用规范和内置关键字。
标识符
用来标识 类 / 方法 / 变量名 / 包
通用规则
必须以 字母 / _ / $ 开头
开头以后可以是 字母 / _ / $ / 数字 的任意组合
大小写敏感,没有长度限制
不可以是关键字
表示类名
每个单词的首字母都需要大写(大驼峰)
标识方法/变量
第一个单词全小写,后续每个单词首字母大写(标准驼峰)
标识常量
所有单词大写 + _分割
关键字
abstract
assert
boolean
break
byte
case
catch
char
class
const
continue
default
do
double
else
extends
final
finally
float
for
goto
if
implements
import
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
strictfp
super
switch
synchronized
this
throw
throws
transient
try
void
volatile
while
代码示例
1 | public class TestVars { |