Java 基础知识总结 (一、标识符)

时间:2021-09-26 01:38:05

一、Identifiers: 标识符

  Names of class,method and variable     用于类名、方法名、变量名

  Begin with character,'_' or '$'        标识符不能以数字开头

  Case sensitive                大小写敏感

  No length limitation             长度不受限制

  标识符不能是java关键字,汉字也可以做标识符,当时不建议使用(涉及编码和跨平台问题)

  String 是java的一个类,类名是可以作为标识符的。

  Java中sizeof不是运算符,可以作为标识符。

  关键字、保留字(const,goto,true,false,null)不能作为标识符。

public class Identifiers {
public static void main(String[] args) {
String $abc = "abc1";
String _abc = "abc2";
// 编译错误,标识符不能以数字开头
// String 8abc="abc3";
String 中国 = "China";
String String = "jaya";
int Integer = 22;
// Java中没有sizeof运算符,所以sizeof可以作为标识符
String sizeof = "sizeof";
System.out.println(String);// jaya
System.out.println(Integer);//
}
}