Page 63 - CA_Blue( J )_Class9
P. 63
4.4 TOKENS
A Java program is composed of individual units called tokens. Tokens are the smallest elements of a Java program
that have meaning to the Java compiler and serve as the fundamental building blocks of the program.
Every Java expression and statement is constructed using tokens. During compilation, the Java compiler reads the
source code, identifies each token, and then translates these tokens into Java bytecode, which the Java Virtual
Machine (JVM) executes based on the program's logic.Java tokens help the compiler detect syntax errors by
allowing it to check for invalid or misplaced tokens, making them essential for ensuring code correctness.
Program 11 Write a program to demonstrate the use of Token.
1 class eg_of_token
2 {
3 public static void main()
4 {
5 System.out.println("This is a program to explain \"Token\".");
6 }
7 }
Here, This source code includes Java tokens such as class, token, {, public, static, void, main, (, ), {, System, out,
println, (,“,This is a program to explain \"Token\".,”,},}.
You will get the following output:
Definition
Java token is the atomic part of a java program that has a meaning for the compiler and is used
to execute the program efficiently.
There are various types of Tokens that are used by the Java Compiler: Keywords, Identifiers, Literals, Operators and
Special Symbols such as Punctuators, Separators.
4.4.1 Keywords
Keywords are pre-defined words that are reserved by the Java compiler for a specific purpose and used only in a
limited, specific manner. It cannot be used as a variable name as it will assign a new meaning to the keyword. This
will be treated as an error by the compiler. They are also known as reserved words. List of keywords used in java
given below.
Assert double implements protected throw
boolean else import public throws
break enum instanceof return transient
Values and Types 61

