Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
Assignments and Initializations
-
Initialize a variable by assigning a value to it.
-
You assign a variable this way:
-
variableName = value; where variableName is the name given when
declared, and value is either a constant or another variable.
-
You must use single =. This means assignment. = =, double equals,
is comparison.
-
If you attempt to use a variable before it has been initialized, the compiler
will give you an error.
-
Keeping the verbage straight:
-
Declare a variable: simply give a name and type for a variable.
-
Initialize a variable: give it an initial value
-
Assign a variable: give the variable a value at any time.
-
You can declare and initialize in the same step.
float hourlyRate = 8.75F;
-
float hourlyRate;
hourlyRate = 8.75F;
-
Why the F?
In Class Lab
Constants
Created by: Brandan
Jones January 4, 2002 (Updated January 14, 2003)