|
int
or String
), and variable is the name of the variable (such as x
or name
).
The equal sign is used to assign values to the variable.
To create several variables that store integers, look at the following example:
|
x
and y
) or more descriptive names (age
, sum
, and totalVolume
).
The general rules for constructing names for variables (unique identifiers) are
$
and _
,
myVar
and myvar
are different variables),
int
or String
) cannot be used as names.
Review: Identifier.java (checking identifier names) |
public class Identifier { public static void main( String[ ] args ) { int this = 2; // correct incorrect Integer that = 2; // correct incorrect short _under; // correct incorrect byte 1UND; // correct incorrect String str@ = "Hello"; // correct incorrect boolean Bool; // correct incorrect Float number; // correct incorrect } } |
Result: |