Java Tokens:- A java Program is made up of Classes and Methods and in the Methods are the Container of the various Statements And a Statement is made up of Variables, Constants, operators etc .
Tokens are the various Java program elements which are identified by the compiler and separated by delimiters. The delimiters are not part of the tokens. A token is the smallest element of a program that is meaningful to the compiler. The compiler breaks lines into chunks of text called tokens. 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
• Reserve Word or Keywords: Keywords are the pre-defined identifiers reserved by Java for a specific purpose and used only in a limited, specific manner.
• Identifier: A Java identifier is the symbolic name that a programmer gives to various programming elements such as a variables method, class, array, etc.
• Literals: A literal is a constant value that can be classified as integer literals, string literals, and boolean literals.
• Operators: An operator is a special symbol that tells the compiler to perform a specific mathematical or logical operation on one or more operands where an operand can be an expression.
• Separators: Separators are the lines that are used to virtual group related items together.