Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
A program refers to a variable's value by the variable's name. For example, when it displays the value of thelargestByte
variable, theMaxVariablesDemo
program uses the namelargestByte
. A name, such aslargestByte
, that's composed of a single identifier is called a simple name. Simple names are in contrast to qualified names, which a class uses to refer to a member variable that's in another object or class. This topic is covered further in the Using Objects section.In the Java programming language, the following must hold true for a simple name:
- It must be a legal identifier. Recall from the preceding section that an identifier is an unlimited series of Unicode characters that begins with a letter.
- It must not be a keyword, a boolean literal (
true
orfalse
), or the reserved wordnull
.- It must be unique within its scope. A variable can have the same name as a variable whose declaration appears in a different scope. In some situations, a variable can share names with another variable, which is declared in a nested scope. Scope is covered in the next section.
By Convention: Variable names begin with a lowercase letter and class names begin with an uppercase letter. If a variable name consists of more than one word, the words are joined together, and each word after the first begins with an uppercase letter (for example,isVisible
). The underscore character (_
) is acceptable anywhere in a name, but by convention it is used only to separate words in constants (because constants are all caps by convention and thus cannot be case-delimited).
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.