标识符与关键字 [英] Identifer versus keyword

查看:40
本文介绍了标识符与关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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.

Keywordidentifier 有什么区别?谁能给我一个简单的解释,另外还有一个或多个例子?

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;

indexname 是此处的有效标识符.int 是关键字.

index and name are valid identifiers here. int is a keyword.

关键字不能用作标识符.

A keyword cannot be used as an identifier.

这篇关于标识符与关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆