Categories: Java

Identifiers

Identifiers are fundamental building blocks of a program and are used as the general terminology for the names given to different parts of the program viz. variables, objects, classes, functions, arrays, etc.

Identifier forming rules of Java state the following:
  • Identifiers can have alphabets, digits, and underscore and dollar sign characters.
  • They must not be a keyword or boolean literal or null literal.
  • They must not begin with a digit.
  • Furthermore, they can be of any length.
  • Java is case-sensitive, i.e, upper-case letters and lower-case letters are treated differently.

The following are some valid identifiers:

MyFile    A_to_Z
MYFILE    $1_abc
_CHK      file341

The following are some invalid identifiers:

DATA-REC    contains special character(-)
29fgt       Starting with a digit
break       reserved keyword
My.File     contains special character
Identifier naming conventions:

While making identifiers name, certain conventions are followed:

  • The name of public methods and instance variables should begin with a lowercase letter.
  • For names having multiple words, the second and subsequent words’ beginning character is made capital to enhance readability.
  • Private and local variables should use lowercase letters.
  • The class names and interface names begin with an upper case letter.
  • The constants should be named using capital letters and underscore.

Note: also read about the Token and keywords

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory.…

1 day ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

3 weeks ago

Longest Substring with K Distinct Characters

Given an integer k and a string s, write a function to determine the length…

3 weeks ago

Staircase Climbing Ways

There is a staircase with N steps, and you can ascend either 1 step or…

4 weeks ago

Autocomplete System Implementation

Build an autocomplete system that, given a query string s and a set of possible…

4 weeks ago

Job Scheduler Implementation

Design a job scheduler that accepts a function f and an integer n. The scheduler…

4 weeks ago