Understanding Tokens – Computer Sir Ki Class
  

Login
[lwa]



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

class AllTokens
{
public static void main(String[] args)
{
int a=10,b=20;
int c=a+b;
System.out.println("a+b="+c);
}
}

Test it !

Run Output

a+b=30

Code Understanding

class AllTokens
{
public static void main(String[] args)
{
int a=10,b=20;
int c=a+b;
System.out.println(“a+b=”+c);
}
}

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

Notes

  • 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



Share

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






Back