Java Tokens | A java program is basically made up of a group of classes and methods.
A class is a container that contains a set of declaration statements and methods containing executable statements.
A statement consists of variables, constants, operators, keywords, comments, identifiers, punctuators, etc. When the program is run, comments are stripped and executable statements are executed.
The output is called translation unit. A translation unit is a sequence of tokens: symbols, numbers, and words.
What are tokens in Java?
Tokens are the various elements in the java program that are identified by Java compiler. A token is the smallest individual element (unit) in a program that is meaningful to the compiler.
In simple words, a java program is a group of tokens, comments, and white spaces. For example, consider the below java statements:
final double p = 3.14 // A constant. x = a + b; // An expression. v = Math.pow(10, 1); // An inbuilt java function.
Let us consider the first statement, which is made up of six tokens: “final”, “double”, “p”, “=”, “3.14”, and “;”.
Similarly, second statement consists of six tokens: “x”, “=”, “a”, “+”, “b”, and “;”.
Types of Tokens
Java language contains five types of tokens that are as follows:
- Reserved Keywords
- Identifiers
- Literals,
- Operators
- Separators
Hope that this tutorial has covered all important points in simple words related to tokens. I hope that you will have understood this simple topic.
In the next tutorial, we will know Java character set in simple words.
Thanks for reading!!!
Next ⇒ Java Character Set