Java Identifier

Identifier

An identifier is a user-defined name used to distinguish program components such as variables, constants, arrays, methods, and classes.

Identifier Rules

  • Identifiers can be written using uppercase letters, lowercase letters, digits, the underscore character(_), and the dollar sign character($).
  • They must not start with a digit, but digits may appear after a letter.
  • They cannot contain spaces between characters.
  • Because Java is case-sensitive, VALUE and Value are different identifiers.
  • Reserved words such as this, true, and null cannot be used as identifiers.
  • Since Java supports 16-bit Unicode, Korean can also be used as an identifier, although it is not recommended.
    • ASCII code: an 8-bit character code established by ANSI(American National Standards Institute) that encodes 256 characters.
    • Unicode: a character code extended to 16 bits by the Unicode consortium(Apple, IBM, MS, and others) as a standard character code for representing all characters worldwide.
    • Unicode currently encodes 34,168 characters and can encode up to 65,536 characters.

Identifier Conventions

  • By convention, class names start with uppercase letters, while names such as variables and methods start with lowercase letters.
  • When combining two words to make a name, capitalize the first letter of the combined word.
    • Camel case notation

Valid Examples

  • fileName (recommended)
  • file_name (not recommended)
  • _fileName (not recommended)
  • $fileName (not recommended)

Invalid Examples

  • user name: blank spaces(" “) cannot appear.
  • 3d_Studio: cannot start with a digit.
  • this: keywords cannot be used.
  • #arg: # cannot be used.