There are four types of variables in Java:
- instance variable (non-static field): A field in a Java class that does not have a static keyword modifier
- class variable (static field): A field in a Java class with a static keyword modifier.
- local variable: A variable defined within a closed flower registration (as in a method).
- parameter: The variable passed to the method.
Variable naming
requires the name of the
- variable to be case sensitive, the name of the variable can be any valid identifier--can have any length of Unicode letters and numbers, You cannot use white space characters
- cannot start with a number, generally do not advocate the beginning of a $ or underscore, because some machines produce names that contain "$"
- cannot use keywords or reserved names
Naming suggestions
Generic variable name Use English words, if the variable contains more than one word, generally except the first word, the first letter of the following words are capitalized, such as
int Numgears=6//Note the spelling of the name
and the constant name (final keyword decoration) the words are all capitalized, and the words are separated by underscores such as
Static final int num_gears=6// Note the spelling of the name
Java Basics-Variables