1、Identifiers:标识符
①Names of class,method and variable:用于类名、方法名、变量名
②Begin with character,"_" or "$":标识符不能以数字开头
③Case sensitive:大小写敏感(区分大小写)
④No length limitation:长度无限制
⑤标识符不能是Java关键字,汉字也可以做标识符,但是不建议使用(使用汉字涉及到编码问题,跨平台时回出现问题)。
⑥String是Java的一个类,类名是标识符,所以String可以做标识符。
⑦There is no sizeof operator.Java中没有sizeof运算符,所以sizeof可以作为标识符
⑧关键字、保留字(const、goto、true、false、null)不能用作标识符。
1 public class Identifiers { 2 public static void main(String[] args) { 3 String $abc="abc1"; 4 String _abc="abc2"; 5 //编译错误,标识符不能以数字开头 6 //String 8abc="abc3"; 7 String 中国="China"; 8 String String="wanghao"; 9 int Integer=22; 10 //Java中没有sizeof运算符,所以sizeof可以作为标识符 11 String sizeof="sizeof"; 12 System.out.println(String);//wanghao 13 System.out.println(Integer);//22 14 } 15 }
2、Keywords:关键字
The goto and const keyword are not used in the Java programming.
const 保留关键字(留儿不用)。const是从C++继承而来的,但是Java并不使用const这个关键字,由于JVM是由C++编写的,因此,虽然Java并不使用const这个关键字,但却要保留下来。和const一样goto也是保留关键字!
关键字全部用小写表示(53个)
Strictly speaking,the literals true,false,and null are not keywords but literals;however,the distinction is academic.
true,false,and null是保留字但不是关键字,只是3个值,不能用来做关键字