Introduction
Identifiers in the programming languages are used to name the objects, variables, and functions. Identifiers are the user-defined words useful to access the values associated with the identifiers. Different languages have their own ways of defining identifiers. Generally, identifiers must be different from the Keywords of a language.
You can also do a free certification of Basics of C++
Few Properties of Identifiers
- In a program, we must use all the unique identifiers only.
- Identifiers are case sensitive i.e. ‘val’ is different from ‘Val’.
- Identifiers must be different from keywords.
Some of the rules for naming identifiers in Java are
- All the identifiers must start with the alphabets or an underscore.
- Identifiers should be continuous i.e. there should be no space between the name.
‘numberOf People’ is not valid but ‘numberOfPeople’ is valid. - We can not name the identifier with a number at the starting.
Example of valid identifiers:-
- numberOfPeople
- _first
- First1
Example of InValid identifiers:-
- numberOf People //space in between
- 123first //number at the first position
- continue //Keyword
Consider the following code:-
import java.io.*; import java.util.*; public class Main { public static void main (String[] args){ Scanner sc = new Scanner(System.in); int numberOfPeople = sc.nextInt(); int NumberOfPeople = sc.nextInt(); int totalPeople = numberOfPeople + NumberOfPeople; System.out.println(totalPeople); } } |
In the above code, numberOfPeople , NumberOfPeople, and totalPeople are the identifiers where the first two identifiers are different because n and N are different and identifiers are case-sensitive.
Also, see Literals in C.Fibonacci Series in C++
Frequently Asked Questions
- What are Identifiers?
Identifiers in the programming languages are used to name the objects, variables, and functions. Identifiers are the user-defined words that are useful to access the values associated with the identifiers.
- What are the properties of Identifiers?
1. In a program, we must use all the unique identifiers only.
2. Identifiers are case sensitive i.e. ‘val’ is different from ‘Val’.
3. Identifiers must be different from keywords.