Java Identifiers

Identifiers in Java
In the real life situation, every entity has a name, likewise, a programmer needs to choose names for the things you will refer to in your programs. Programming languages use special names called identifiers to name such programming entities as variables, constants, methods, classes, and packages these are provided by the programmer. The following are the rules for naming identifiers:


 * 1) An identifier is a sequence of characters that consists of letters, digits, underscores (_), and dollar signs ($).
 * 2) An identifier must start with a letter, an underscore (_), or a dollar sign ($). It cannot start with a digit.
 * 3) An identifier cannot be a reserved (key) word.
 * 4) An identifier should not contain spaces.
 * 5) An identifier can be of any length.

For example, $2, SurfaceArea, area, radius, and showLoginMessageDialog are legal identifiers, whereas 2G and e+4 are illegal identifiers because they do not follow the rules. The Java compiler detects illegal identifiers and reports syntax errors.

Since Java is case-sensitive, X and x are different identifiers. Identifiers are used for naming variables, constants, methods, classes, and packages. Descriptive identifiers make programs easy to read. Besides choosing descriptive names for identifiers, there are naming conventions for different kinds of identifiers.

Do not name identifiers with the $ character. By convention, the $ character should be used only in mechanically generated source code.