Variables
You must explicitly declare all variables before using them. The basic form of a variable declaration is this:
type name;
For example:
int x;
String lastName;
double radius;
Note that variable declarations end with semicolons because a variable declaration is a type of statement.
Variable names follow the same rules as other Java identifiers. In short, a variable name can be any combination of letters and numerals but must start with a letter.
Most programmers prefer to start variable names with lowercase letters and then use camel case to capitalize the first letter of individual words within the name. firstName
and sales TaxRate
, for example, are typical variable names.
int x, y, z;