DEV Community

Cover image for Identifiers
Paul Ngugi
Paul Ngugi

Posted on

Identifiers

Identifiers are the names that identify the elements such as classes, methods, and variables in a program. All identifiers must obey the following rules:

  • An identifier is a sequence of characters that consists of letters, digits, underscores
    (_), and dollar signs ($).

  • An identifier must start with a letter, an underscore (_), or a dollar sign ($). It cannot
    start with a digit.

  • An identifier cannot be a reserved word.

  • An identifier cannot be true, false, or null.

  • An identifier can be of any length.

The Java compiler detects illegal identifiers and reports syntax errors. Since Java is case sensitive, area, Area, and AREA are all different identifiers.

Identifiers are for naming variables, methods, classes, and other items in a program. Descriptive identifiers make programs easy to read. Avoid using abbreviations for identifiers. Using complete words is more descriptive. For example, numberOfStudents is better than numStuds, numOfStuds, or numOfStudents. We use descriptive names for complete programs in the text. However, we will occasionally use variable names such as i, j, k, x, and y in the code snippets for brevity. These names also provide a generic tone to the code snippets.
Do not name identifiers with the $ character. By convention, the $ character should be used only in mechanically generated source code

Top comments (0)