Understanding Tokens – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Code Learning #JAVA#3795    siteicon   siteicon  

Understanding Tokens

Demonstration of a program with presence of different types of tokens.

Learning Objectives

  • Identification of tokens in a Java program

Source Code

TC++ #3795

Source Code

Run Output


Code Understanding

class AllTokens
public static void main(String[] args)
int a=10,b=20;
int c=a+b;

The tokens in above program are marked in following colours

Red Colour = Keywords
Blue Colour = Identifiers
Magenta Colour = Literals
Green Colour = Operators
Black Colour = Separators/Punctuators


  • The words like main, String etc. look like things not given by the users. They are actually given by the users in the java development team and hence they are still called identifiers and not keywords.
  • Some textbooks consider white-spaces and comments also as other types of tokens.

Common Errors

  • Sometimes student marks words like System.out.println also as keywords. They are clearly the identifiers which come from java library classes/packages.

Suggested Filename(s): AllTokens.java


sunmitra| Created: 10-Mar-2018 | Updated: 10-Mar-2018|