![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson | Search |
A program refers to a variable's value by its name. For example, when theMaxVariables
program displays the value of thelargestByte
variable, it simply uses the namelargestByte
.In Java, the following must hold true for a variable name:
- It must be a legal Java identifier comprised of a series of Unicode characters. Unicode is a character-coding system designed to support text written in diverse human languages. It allows for the codification of up to 65,536 characters, currently 34,168 have been assigned. This allows you to use characters in your Java programs from various alphabets, such as Japanese, Greek, Cyrillic, and Hebrew. This is important so that programmers can write code that is meaningful in their native languages.
- It must not be a keyword
, a boolean literal (
true
orfalse
), or the reserved wordnull
.- It must be unique within its scope.
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, such asisVisible
, the words are joined together and each word after the first begins with an uppercase letter.Rule #3 implies that variables may have the same name as another variable whose declaration appears in a different scope. This is true. In addition, in some situations, a variable may share names with another variable which is declared in a nested scope. Scope is covered in the next section.
![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson | Search |