Java Identifiers

In programming languages, identifiers are used for identification purposes. In Java, an identifier can be a class name, method name, variable name, or label. For example :

public class Test
    public static void main(String[] args)
        int a = 20;

In the above java code, we have 5 identifiers namely :

  • Test : class name.
  • main : method name.
  • String : predefined class name.
  • args : variable name.
  • a :  variable name.

Rules for defining Java Identifiers

There are sure standards for characterizing a legitimate java identifier. These principles should be followed, else we get incorporate time mistake. These standards are additionally substantial for different dialects like C,C++.

  • The solitary permitted characters for identifiers are altogether alphanumeric characters([A-Z],[a-z],[0-9]), ‘$'(dollar sign) and ‘_’ (underscore).For model “[email protected]” is certifiably not a substantial java identifier as it contain ‘@’ unique character.
  • Identifiers should not start with digits([0-9]). For instance “123geeks” is a not a substantial java identifier.
  • Java identifiers are case-touchy.
  • There is no restriction on the length of the identifier however it is fitting to utilize an ideal length of 4 – 15 letters in particular.
  • Reserved Words can’t be utilized as an identifier. For instance “int while = 20;” is an invalid proclamation as while is a held word. There are 53 reserved words in Java.

Examples of valid identifiers :


Examples of invalid identifiers :

My Variable  // contains a space
123geeks   // Begins with a digit
a+c // plus sign is not an alphanumeric character
variable-2 // hyphen is not an alphanumeric character
sum_&_difference // ampersand is not an alphanumeric character

Reserved Words

Any programming language saves a few words to speak to functionalities characterized by that language. These words are called held words.They can be quickly classified into two sections : keywords(50) and literals(3). Catchphrases characterize functionalities and literals characterize a worth. Identifiers are utilized by image tables in different dissecting phases(like lexical, language structure, semantic) of a compiler design.

Note: The watchwords const and goto are saved, despite the fact that they are not as of now utilized. Instead of const, the last catchphrase is utilized. A few watchwords like strictfp are remembered for later versions of Java.

This article is contributed by Gaurav Miglani. On the off chance that you like GeeksforGeeks and might want to contribute, you can likewise compose an article using or mail your article to [email protected] See your article showing up on the GeeksforGeeks principle page and help different Geeks.

It would be ideal if you compose remarks in the event that you discover anything mistaken, or you need to share more information about the theme examined previously.

Consideration peruser! Try not to quit adapting now. Get hold of the multitude of important Java Foundation and Collections ideas with the Fundamentals of Java and Java Collections Course at an understudy amicable cost and become industry prepared.