Identifiers in Java (2023 Updated)

4.9/5 - (9 votes)

Let’s talk about the Identifiers In Java. Identifiers are the name by which we can able to identify something.

For a real-world example, all human beings are distinguished or identified because of their unique name(identity).

In Programming, It can be a variable name, class name, method name, interface name, and label name.

Example:

int value=30;

Here, value is a variable or identifier which identifies the integral value 30 inside the memory.

Identifiers in Basic Java Program?

Let’s look at the basic Java Program and see how many identifiers are present in it.

class Basic 
{
  public static void main(String[] args)
  {
    int a=100;
  }
}
Identifiers in Java(Basic Java Program how many identifiers are there)

Here in the basic java program, there are five identifiers present which are as follows:

  1. Name of the class i.e. Basic.
  2. Name of the method i.e. main.
  3. Predefined class name i.e. String.
  4. Name of the array i.e. args.
  5. Name of the variable i.e. a.

What are the rules for Identifiers in Java?

The following are the 7 rules for Identifiers in Java:

  1. The only allowed characters are alphabets [a-z and A-Z] , digits [0-9], (dollar)$, and _(underscore).
  2. The first letter should not be a digit.
  3. No space is allowed between the names of variables.
  4. There is no limit to the name of an Identifier, but it is highly recommended to use a name that enhances the readability of our program.
  5. We can use case-sensitive identifiers as java itself is a case-sensitive language. It decreases the readability of our program so not recommended to use.
  6. No reserved words are allowed for an identifier.
  7. We can use the predefined class name and interface name it’s perfectly valid but it is also not recommended to use as it decreases the readability of our program and creates confusion.

What are the valid and invalid identifiers in Java?

What are the valid and invalid identifiers in Java

FAQs (Identifiers in Java)

What are the 5 identifiers in Java code?

1. Name of the class i.e. Basic.
2. Name of the method i.e. main.
3. Predefined Class name i.e. String.
4. Name of the array i.e. args.
5. Name of the variable i.e. a.

This is all about Identifiers in Java.

Related Articles:

Have Questions? Let me know in the comments below.

I’ll try my best to answer all of them.

Share On:

Leave a Comment