tokens in Java

  • NSHIMIYUMWUNGELI Antoine Marie Zacharie
  • java
tokens in Java

Tokens are the various Java program elements which are identified by the compiler. A token is the smallest element of a program that is meaningful to the compiler. Tokens supported in Java include keywords, variables, constants, special characters, operations etc.

When you compile a program, the compiler scans the text in your source code and extracts individual tokens. While tokenizing the source file, the compiler recognizes and subsequently removes whitespaces (spaces, tabs, newline and form feeds) and the text enclosed within comments. Now let us consider a program

//Print Hello

Public class Hello


Public static void main(String args[])


System.out.println(“Hello Java”);



The source code contains tokens such as public, class, Hello, {, public, static, void, main, (, String, [], args, {, System, out, println, (, "Hello Java", }, }. The resulting tokens· are compiled into Java bytecodes that is capable of being run from within an interpreted java environment. Token are useful for compiler to detect errors. When tokens are not arranged in a particular sequence, the compiler generates an error message.

Tokens are the smallest unit of Program There is Five Types of Tokens

1) Reserve Word or Keywords
2) Identifier

3) Literals
4) Operators
5) Separators

Pour être informé des derniers articles, inscrivez vous :
uburenganzira bwose bw'uru rubuga bwihariwe na Nshimiyumwungeri Antoine Marie Zacharie © 2014 -  Hébergé par Overblog