更新时间:2023-11-10 17:22:58
术语关键字"和标识符"不是特定于 Java 的.
The terms "keyword" and "identifier" are not Java specific.
关键字是来自 Java 关键字列表 向编译器提供指令.由于关键字是保留的,程序员不能将它们用于变量或方法名称.
A keyword is a reserved word from the Java keyword list provide the compiler with instructions. As keywords are reserved, they cannot be used by the programmer for variable or method names.
示例:
final
class
this
synchronized
标识符是变量、方法、类、包和接口的名称.它们必须由字母、数字、下划线 _ 和美元符号 $ 组成.标识符只能以字母、下划线或美元符号开头.
Identifiers are the names of variables, methods, classes, packages and interfaces. They must be composed of letters, numbers, the underscore _ and the dollar sign $. Identifiers may only begin with a letter, the underscore or a dollar sign.
示例:
int index;
String name;
index
和 name
是此处的有效标识符.int
是关键字.
index
and name
are valid identifiers here. int
is a keyword.
关键字不能用作标识符.
A keyword cannot be used as an identifier.