Java Reference
In-Depth Information
Table 2.1
(continued)
byte
else
instanceof
return
transient
case
extends
int
short
try
catch
final
interface
static
void
char
finally
long
strictfp
volatile
class
float
native
super
while
const
for
new
switch
continue
goto
package
synchronized
assert
The keywords const and goto cannot be used in Java. They were added to
the list of keywords so they would generate compiler errors for developers
who were converting C and C++ code over to Java. The keyword assert is a
new Java keyword added to the J2SE in version 1.4.
There are three more reserved words in Java: true, false, and null. Techni-
cally, they are literal values and not keywords. However, they cannot be used
as identifiers, and they have a specific meaning to the Java compiler.
Take a look back at the HelloWorld example in Chapter 1. The keywords
used are public, class, static, and void. The other words in the HelloWorld class
are identifiers, which are discussed next. Notice that main is not a keyword,
even though main is a special name used to denote the method in which a Java
program starts.
Identifiers
Identifiers are those words in your Java code that you choose. For example, in
Lab 1.1, you wrote a class named Signature. Signature is not a Java keyword,
nor does it have any special meaning in Java. You had to name the class some-
thing, and Signature was chosen to make the code more readable because the
program displayed an email signature.
In Java, you will need to identify many elements in your code, including
class names, methods, fields, variables, and package names. The names you
choose are called identifiers and must adhere to the following rules:
An identifier cannot be a keyword or true, false, or null.
■■
An identifier can consist of letters, digits 0-9, the underscore, or the
dollar sign.
■■
An identifier must start with a letter, an underscore, or a dollar sign.
■■
Search WWH ::




Custom Search