15 Certified Facts on Identifier and Keyword In Java

Introduction to Identifier and Keyword In Java

A programming language is a combination of rules, symbols, and keywords. Rules are for syntax and semantics. Rules are defined in a simple, precise, to the point and formal language called metalanguage.

An Identifier is a meaningful name or token given to Java components(classes, methods, variables, objects, labels, packages, and interfaces) to identify it correctly.

Java is a combination of Identifier and keywords. Keywords are special words that express something in terms of java. Keywords are defined and reserved in java. However, Identifier is kind of mixed mode, user-defined and inbuilt.

How does metalanguage work?

The older computer-oriented metalanguage is the Backus Naur form(BNF) developed by John Backus and Peter Naur in 1960.BNF syntax definitions are full of letters, numbers, and special symbols.

The BNF definition of an identifier in Java is as follows:


Where:: signifies “is defined as”,| signifies ‘or’,<> signifies encasement of the word(not terminated words [still needs to be defined] apart from these everything is terminating symbols).

So as per BNF, an identifier is a letter or letter followed by a letter digit sequence. A letter-digit-sequence is created by a <letter or a digit> then comes letter-digit sequence.

A letter or digit is defined as either a <letter> or a <digit>.

A letter is defined with the underscore,$ sign or any uppercase or lowercase letters.

A digit is defined by the numeric 0 to 9.

See also  All About Class BitSet in Java

BNF is an extremely easy language but that simplicity gives long and difficult to read syntaxes.

There is another form of metalanguage called syntax template which shows java syntaxes. As per the syntax template, an identifier is either letter or a letter-digit combination.

  • The letter can be from [A-Z],[a-z] and digit can be from [0-9].
  • So an identifier in Java is of any combination of letters or sequence of letters[A-Z][a-z] digit[0-9],the underscore(_) and a dollar sign($).
  • They must begin with an underscore or a dollar sign followed by optional digits.
  • Since Java is case sensitive hence ‘no’ and ‘NO’ are two different entities.
  • Similarly, identifiers can not start with a digit. like 24Hours,8 Hours, etc.
  • No space is allowed inside identifiers like total no is an invalid identifier.
  • The hyphen (-) is treated as a minus sign. So it can not be used in an identifier.
  • Any other symbols are not allowed apart from the dollar ($) sign or the underscore(_) hence ?TOTAL_No or TotalNo? are not valid.
  • You can not use reserved keywords as an identifier.

With the above two rules, Java has come up with the identifier and keyword rules. let’s see them in-depth:

Let us look at the code:

public class HelloWorld{
public static void main(String []args){
int i=10;

Here public, static, void, int are keywords
HelloWorld-class name,identifier
main-method name,identifier
i=variable name,identifier

The rules for identifier:

  1. It should start with uppercase(class name) or lowercase(variable,method name)
  2. space is not allowed inside identifiers( get Ticket() is not valid so as Income Tax).They should be typically a single word.
  3. No keywords or reserved words can be used as an identifier. But can be part of Identifier(like double int is not valid but intinincome tax is valid).
  4. There no limitation of identifier length, it can start from 1 character to n characters as long as they can be identified, easily typed, descriptive, and easily readable.
  5. Identifier should not start with digit[0-9] like 123incomeTax is not valid
  6. Identifiers can contain [a-z],[A-Z],[0-9] and special symbol dollar($) and underscore ( _ ) are allowed.Like-&Ticket is not valid so as %deal123 and @Tax.
See also  How To Set Classpath in Java - 7 Important Steps To Follow

Below are the reserved keywords that can not be directly an identifier. However, they can be part of the identifier.


Below are the names of the methods in java belong to the Object class which is the superclass of all the classes in java.

So if we use them in our class, it is treated as an Override of those methods. So typically these become reserved methods. We should not define them to use for our purpose.

Method nameMethod nameMethod name

Further visit: Class NullPointerException in Java – 2 Important Points To Know

Below are a few best practices not rule:

  • Compound words or phrases are used following camel casing. When two or more words are used, the second and subsequent words are written with a leading uppercase letter.like-getTicket(),incomeTax
  • Names of all public methods and instance variable start with a leading lowercase letter.
  • For all private and local variables, we need to use all lowercase letters combined with the underscore and of two or more letters. like name_of_student.
  • All classes and interfaces start with a leading uppercase letter and each subsequent letter of words in uppercase like-HelloWorld.java or class HelloWorld
  • Variables representing constant use of all uppercase letters and underscore in between. like TOTAL, TEMP_MAX, etc
See also  ArrayList in Java: Detailed Topic in Just 5 Minutes

Share and Enjoy !

2 thoughts on “15 Certified Facts on Identifier and Keyword In Java

  1. Whoa! This blog looks exactly like my old one! It’s
    on a totally different subject but it has pretty much the same layout and design. Excellent choice of colors!

  2. Hi, Neat post. There’s a problem with your web site in internet explorer, would check this… IE still is the market leader and a large portion of people will miss your excellent writing due to this problem.

Leave a Reply

Your email address will not be published. Required fields are marked *