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

Generate Parenthesis | Intuition + Code | Recursion Tree | Backtracking | Java

Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…

2 months ago

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

1 year ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

1 year ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

1 year ago