Java Reference
In-Depth Information
In Java, every value has a type.
You often want to store values so that you can use them at a later time. To remember
an object, you need to hold it in a variable. A variable is a storage location in the
computer's memory that has a type, a name, and a contents. For example, here we
declare three variables:
String greeting = "Hello, World!";
PrintStream printer = System.out;
int luckyNumber = 13;
The first variable is called greeting . It can be used to store String values, and it
is set to the value ÐHello, World!Ñ . The second variable stores a PrintStream
value, and the third stores an integer.
You use variables to store values that you want to use at a later time.
Variables can be used in place of the objects that they store:
printer.println(greeting); // Same as System.out.println("Hello,
World!")
printer.println(luckyNumber); // Same as System.out.println(13)
34
35
S YNTAX 2.1 Variable Definition
typeName variableNameÉ=Évalue;
or
typeName variableName;
Example:
String greeting = ÐHello, Dave!Ñ;
Purpose:
To define a new variable of a particular type and optionally supply an initial value
When you declare your own variables, you need to make two decisions.
Search WWH ::




Custom Search