Identifiers in Java
A name in java program is called Identifier. Which can be used for identification purpose. It can be method name / variable name / class name / label name.
Example :

In the above Example there are 5 Identifiers are present
Rules for Defining Java Identifiers :
- The only allowed characters in java Identifiers are
- Lower case Alphabets (a to z)
- Upper case Alphabets (A to Z)
- Numbers( 0 to 9)
- Special Symbols ($ and _)
If you are using any other character , immediately we get compile time error.
Example
- my_number // valid
- number# //invalid
2.Identifiers can’t starts with digit
Example
- numberl123 //valid
- 123number //invalid
3. Java Identifiers are case-sensitive.Of-course java language itself is treated as case sensitive programming language.
Example
4. There is No length limit for Java Identifiers. But it is not recommended to take too lengthy identifiers
5. We can’t use reserved words as Identifiers
Example:
int x=10; //valid
int if=20; //Invald
6. All predefined java class Names and Interface Names we can use as Identifiers
Example:
public class Test
{public static void main(String[] args)
{int String= 111;
System.out.println(String); // valid
int Rannable= 111;
System.out.println(Rannable); // valid}
}
Even though it is valid but it is a good programming practice, Because it reduces readability and creates confusion.
Which of the following are valid Identifiers in java
- total_number //valid
- total# //invalid
- 123total // invalid
- total123 //valid
- ca$h //valid
- _$_$_$_ //valid
- all@hands //invalid
- java2share //valid
- Integer //valid
- Int //valid
- int //invalid