The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Trail: Learning the Java Language
Lesson: Language Basics

## Variable Names

> A program refers to a variable's value by the variable's name. For example, when it displays the value of the `largestByte` variable, the `MaxVariablesDemo` program uses the name `largestByte`. A name, such as `largestByte`, 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.

> In the Java programming language, the following must hold true for a simple name:

> 1. It must be a legal identifier. An identifier is an unlimited series of Unicode characters that begins with a letter.
> 2. It must not be a keyword, a boolean literal (`true` or `false`), or the reserved word `null`.
> 3. It must be unique within its scope. A variable may have the same name as a variable whose declaration appears in a different scope. In some situations, a variable may share the same name as another variable if it is declared within a nested block of code. (We will cover this in the next section, 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, the words are joined together, and each word after the first begins with an uppercase letter, like this: `isVisible`. The underscore character (`_`) is acceptable anywhere in a name, but by convention 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-2001 Sun Microsystems, Inc. All rights reserved.