4.2 标识符和关键字
- 标识符
- 所有的标识符都应该以字母(A-Z 或者a-z)、美元符($)或下划线(_)开始
- 首字符之后可以是字母(A-Z 或者a-z)、美元符($)、下划线(_)或数字(0-9)的任何字符组合
- 不能以关键字作为变量名或方法名
- 标识符是大小写敏感的
- 合法标识符举例:age,$salary,_value,__1_value
- 非法标识符举例:1231abc,-salary,#abc
- 可以使用中文命名,但是一般不建议这样去使用,也不建议使用拼音,很 Low
- 关键字
- Java所有的组成部分都需要名字
- 类名、变量名以及方法名都被称为标识符
/**
* 为防止报错,所有错误命名使用单行注释示范
*/
public class HelloWorld {
public static void main(String[] args) {
String AHW = "HelloWorld";
String aHW = "HelloWorld";
String $HW = "HelloWorld";
String _HW = "HelloWorld";
//String 1HW = "HelloWorld";
//String #HW = "HelloWorld";
//String *HW = "HelloWorld";
String AA = "HelloWorld";
String Aa = "HelloWorld";
String A$ = "HelloWorld";
String A_ = "HelloWorld";
String A1 = "HelloWorld";
//String A# = "HelloWorld";
//String A- = "HelloWorld";
//String A* = "HelloWorld";
//String class = "HelloWorld";
String Man = "PuYulin"; //大小写敏感
String man = "PuYulin";
String name = "PuYulin"; //可以使用中文、拼音命名,但是太 Low 了
String 名字 = "PuYulin";
String minzi = "PuYulin";
String mz = "PuYulin";
}
}