Java Reference
In-Depth Information
Java is a case-sensitive language; that is, it distinguishes between uppercase and
lowercase letters in the spelling of identifiers. Hence, the following are three distinct
identifiers and could be used to name three distinct variables:
case-sensitive
rate RATE Rate
However, it is usually not a good idea to use two such variants in the same program,
since that might be confusing. Although it is not required by Java, variables are usually
spelled with their first letter in lowercase. The convention that has now become uni-
versal in Java programming is to spell variable names with a mix of upper- and lower-
case letters (and digits), to always start a variable name with a lowercase letter, and to
indicate “word” boundaries with an uppercase letter, as illustrated by the following
variable names:
topSpeed bankRate1 bankRate2 timeOfArrival
A Java identifier can theoretically be of any length, and the compiler will accept
even unreasonably long identifiers.
Names (Identifiers)
The name of something in a Java program, such as a variable, class, method, or object
name, must not start with a digit and may only contain letters, digits ( 0 through 9 ), and the
underscore character ( _ ). Uppercase and lowercase letters are considered to be different
characters. (The symbol $ is also allowed, but it is reserved for special purposes, and so you
should not use $ in a Java name.)
Names in a program are called identifiers .
Although it is not required by the Java language, the common practice, and the one followed
in this topic, is to start the names of classes with uppercase letters and to start the names
of variables, objects, and methods with lowercase letters. These names are usually spelled
using only letters and digits.
There is a special class of identifiers, called keywords or reserved words , that have
a predefined meaning in Java and that you cannot use as names for variables or any-
thing else. In the code displays of this topic, keywords are shown in a different color, as
illustrated by the keyword public . A complete list of keywords is given in Appendix 1.
Some predefined words, such as System and println , are not keywords. These pre-
defined words are not part of the core Java language and you are allowed to redefine
them. These predefined words are not keywords. However, they are defined in libraries
required by the Java language standard. Needless to say, using a predefined identifier
for anything other than its standard meaning can be confusing and dangerous, and
thus should be avoided. The safest and easiest practice is to treat all predefined identi-
fiers as if they were keywords.
keyword
Search WWH ::




Custom Search