An identifier is any symbolic name that refers to something in a Java program. Class, method, parameter, and variable names are all identifiers. An identifier must begin with a letter, an underscore ( _ ), or a Unicode currency symbol (e.g., $, £, ¥). This initial letter can be followed by any number of letters, digits, underscores, or currency symbols. Remember that Java uses the Unicode character set, which contains quite a few letters and digits other than those in the ASCII character set. The following are legal identifiers:
i engine3 theCurrentTime the_current_time
Identifiers can include numbers, but cannot begin with a number. In addition, they cannot contain any punctuation characters other than underscores and currency characters. By convention, dollar signs and other currency characters are reserved for identifiers automatically generated by a compiler or some kind of code preprocessor. It is best to avoid these characters in your own identifiers.
Another important restriction on identifiers is that you cannot use any of the keywords and literals that are part of the Java language itself. These reserved words are listed in Table 2-1.
abstract | do | if | package | synchronized |
boolean | double | implements | private | this |
break | else | import | protected | throw |
byte | extends | instanceof | public | throws |
case | false | int | return | transient |
catch | final | interface | short | true |
char | finally | long | static | try |
class | float | native | strictfp | void |
const | for | new | super | volatile |
continue | goto | null | switch | while |
default |
Note that const and goto are reserved words, but aren't part of the Java language.
Copyright © 2001 O'Reilly & Associates. All rights reserved.
This HTML Help has been published using the chm2web software. |