Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
1.1.
Few Properties of Identifiers
1.2.
Some of the rules for naming identifiers in Java are
2.
Frequently Asked Questions
3.
Key Takeaways
Last Updated: Jul 2, 2024

Identifiers

Author Nishant Rana
0 upvote

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

  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.

Some of the rules for naming identifiers in Java are

  1. All the identifiers must start with the alphabets or an underscore.
  2. Identifiers should be continuous i.e. there should be no space between the name.
    numberOf People’ is not valid but ‘numberOfPeople’ is valid.
  3. We can not name the identifier with a number at the starting.
     

Example of valid identifiers:-

  1. numberOfPeople
  2. _first
  3. First1


Example of InValid identifiers:-

  1. numberOf People   //space in between
  2. 123first                   //number at the first position
  3. 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

  1. 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.
     
  2. 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.

Key Takeaways

In this blog, we have covered the following things:

  1. We first discussed what are identifiers.
  2. Then we discussed the properties of identifiers.

 

If you want to learn more about Programming Language and want to practice some questions which require you to take your basic knowledge on Programming Languages a notch higher, then you can visit our here

Until then, All the best for your future endeavors, and Keep Coding.


Live masterclass