Java Reference
In-Depth Information
Identifiers
A third category of tokens is identifiers. Identifiers are names of things, such as variables,
constants, and methods, that appear in programs. Some identifiers are predefined; others
are defined by the user. All identifiers must obey Java's rules for identifiers.
Identifier: A Java identifier consists of letters, digits, the underscore character (_), and the
dollar sign ( $ ) and must begin with a letter, underscore, or the dollar sign.
Identifiers can be made of only letters, digits, the underscore character (_), and the dollar
sign ( $ ); no other symbols are permitted to form an identifier.
2
Java is case sensitive—uppercase and lowercase letters are considered different. Thus,
the identifier NUMBER is not the same as the identifier number or the identifier Number .
Similarly, the identifiers X and x are different.
In Java, identifiers can be any length. Some predefined identifiers that you will encounter
frequently are print , println , and printf , which are used when generating output,
and nextInt , nextDouble , next , and nextLine , which are used to input data. Unlike
reserved words, predefined identifiers can be redefined, but it would be unwise to do so.
EXAMPLE 2-1
The following are legal identifiers in Java:
first
conversion
payRate
counter1
$Amount
Table 2-1 shows some illegal identifiers and explains why they are illegal.
TABLE 2-1 Examples of Illegal Identifiers
Illegal Identifier
Description
employee Salary
There can be no space between employee and Salary .
Hello!
The exclamation mark cannot be used in an identifier.
one+two
The symbol + cannot be used in an identifier.
2nd
An identifier cannot begin with a digit.
 
 
 
Search WWH ::




Custom Search