Java Reference
In-Depth Information
Naming Variables
Variable names in Java must start with a letter, an underscore character (“_”), or a dollar
sign (“$”). They cannot start with a number. After the first character, variable names can
include any combination of letters or numbers.
NOTE
In addition, the Java language uses the Unicode character set,
which includes thousands of character sets to represent interna-
tional alphabets. Accented characters and other symbols can be
used in variable names as long as they have a Unicode character
number.
2
When naming a variable and using it in a program, it's important to remember that Java
is case sensitive—the capitalization of letters must be consistent. Because of this, a pro-
gram can have a variable named X and another named x (and Rose is not a rose is not a
ROSE ).
In programs in this topic and elsewhere, Java variables are given meaningful names that
include several words joined together. To make it easier to spot the words, the following
rule of thumb is used:
The first letter of the variable name is lowercase.
n
Each successive word in the variable name begins with a capital letter.
n
All other letters are lowercase.
n
The following variable declarations follow this rule of naming:
Button loadFile;
int localAreaCode;
boolean quitGame;
Variable Types
In addition to a name, a variable declaration must include the data type of information
being stored. The type can be any of the following:
One of the primitive data types
n
The name of a class or interface
n
An array
n
Search WWH ::




Custom Search