标识与关键字 [英] Identifer versus keyword
问题描述
我在书中读到了OCJP for Java6这个带有断言的部分。我到达了一个部分,它概述了编译器如果将'assert'用作关键字或标识符,如何做出反应。
I read in the book for OCJP for Java6 the part with assertions. I reached the part where it gives me an overview of how the compiler reacts if the word 'assert' is used as keyword or as an identifier.
有什么区别关键字
和标识符
?任何人都可以给我一个简单的解释,另外还有一个或多个例子吗?
What is the difference between a Keyword
and an identifier
? Can anyone give me a simple explanation and additionally one or more examples for both?
推荐答案
术语关键字和标识符不是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.
这篇关于标识与关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!