Identifiers
Java Identifiers
Every Java variable needs to have a unique name.
We refer to these distinct names as identifiers.
Identifiers can be more descriptive names like age, sum, or totalVolume, or they can be simple names like x and y.
Note: To write comprehensible and maintainable code, it is advised to use descriptive names:
Example
// Good
int minutesPerHour = 60;
// OK, but not so easy to understand what m actually is
int m = 60;
Here are the general guidelines for naming variables:
- Names can contain letters, digits, underscores, and dollar signs
- Names must begin with a letter
- Names should start with a lowercase letter, and cannot contain whitespace
- Names can also begin with $ and _ (but we will not use it in this tutorial)
- Names are case-sensitive (“myVar” and “myvar” are different variables)
- Reserved words (like Java keywords, such as int or boolean) cannot be used as names