This page describes how field variables and arrays are initialized.
Java automatically initializes
field variables [1] and the elements of arrays to the default values shown in the following table:
Java does not initialize non-array
local variables[2] (also referred to as
automatic variables) .
The Java compiler generates error messages when it detects attempts to use uninitialized local variables.
The
Initializer program shows how automatic initialization works.
"Local variables are sometimes called stack, temporary, automatic, or method variables, but the rules for these variables are the same regardless of what you call them."
"Local variables" are called
automatic.
Local variables automatically cease to exist when the execution of the block in which they are declared completes.
{
int x;
}
// x automatically vanishes here.
In computer programming, an
automatic variable is a lexically-scoped variable which is allocated and de-allocated automatically when program flow enters and leaves the variable's scope.
The term
local variable is usually synonymous with
automatic variable[3], since these are the same thing in many programming languages.