Data Structures and Algorithms
with Object-Oriented Design Patterns in JavaA variable is a programming language abstraction that represents a storage location. A Java variable has the following attributes:
Consider the Java variable declaration statement:
int i = 57;This statement defines a variable and binds various attributes with that variable. The name of the variable is i, the type of the variable is int, and its initial value is 57.
Some attributes of a variable, such its name and type, are bound at compile time. This is called static binding. Other attributes of a variable, such as its value, may be bound at run time. This is called dynamic binding.
There are two kinds of Java variables--local variables and fields.
A local variable
is a variable declared inside a method.
A field
is a variable declared in some class.
(Classes are discussed in Section
).
The type of a Java variable
is either one of the primitive types
or it is a reference type.
Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.