home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book Home Java Enterprise in a Nutshell Search this book

2.3. Identifiers and Reserved Words

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
theta

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.

Table 2-1. Java Reserved Words

abstractdoifpackagesynchronized
booleandoubleimplementsprivatethis
breakelseimportprotectedthrow
byteextendsinstanceofpublicthrows
casefalseintreturntransient
catchfinalinterfaceshorttrue
charfinallylongstatictry
classfloatnativestrictfpvoid
constfornewsupervolatile
continuegotonullswitchwhile
default

Note that const and goto are reserved words, but aren't part of the Java language.



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.