Java中的类名、变量名、常量名不能使用任意字符,需要使用规定字符:
字母、数字、下划线、$
必须是用 字母、下划线、$ 开头,不能以数字开头
关键字不能用于定义标识符名称,是Java语法的保留关键字,具有特殊用途。
abstract boolean break byte case cast
catch char class const continue default
do double else extends false final
finally float for future generic goto
if implements import inner instanceof int
interface long native new null operator
outer package private protected public rest
return short static strictfp super switch
synchronized this throw throws transient true
try var void volatile while
Java中的3种注释形式:
(1)//单行注释。
例如:
//生成随机整数,能被2整除表示业务逻辑为true,否则为false
boolean b = r.nextInt(10)%2 == 0;
(2)/—行或多行的注释/ :多行注释。
例如:
public void check() {
/*
* 检查剩余弹药
* bullets 子弹
*/
System.out.println("剩余子弹数"+ bullets.size());
bullets.forEach(System.out::println);
}
(3)/*文档注释/ :注释内容能够生成文档。注释中以符号@开头的特定的标签(Tags)标识出方法的不同方面。例如,使用@param标识参数,@return标识返回值。
例如:
/**
* 战斗技能--开枪
* bullets 子弹
*/
public void fire() {
//三连发点射,消耗散发子弹
for(int i=0; i<3; i++) {
bullets.remove(0);
}
}