#1 Java Identifiers




In Java each entity will get some name as its identity, That name will be known as Identifier. It is given to classes, methods, interfaces and variables.

In order to be valid Identifier, It must follow some rules which are listed below.
  1. It starts with letter(a-z or A-Z), Connecting character (ex. _ ) or Currency character (ex. $). It can not start with numbers(0-9).
  2. After First character, It can contain any combination of letter, connecting character, currency character and digits.
  3. Java Keyword can not be used as Identifier. List of Java keyword given below.
  4. It is case sensitive. So javaFixer and javafixer are two different identifier

Invalid Identifier example:
  • 365javaFixer
  • java-Fixer 
  • package com.365javaFixer

Valid Identifier example:
  • javaFixer
  • _javaFixer
  • $java_fixer

List of Java Keyword:

Keyword: one of
        abstract    continue    for           new          switch
        assert      default     if            package      synchronized
        boolean     do          goto          private      this
        break       double      implements    protected    throw
        byte        else        import        public       throws
        case        enum        instanceof    return       transient
        catch       extends     int           short        try
        char        final       interface     static       void 
        class       finally     long          strictfp     volatile
        const       float       native        super        while           

Source: docs.oracle.com


Note: Identifiers containing a dollar sign ($) are generally unusual, although languages like BASIC make extensive use of them. Its probably best to avoid using dollar sign ($).