Java Tokens

These are the fundamental building blocks of a program or the smallest unit of a program.
Java supports five types of tokens:

1. Keywords

These are the words which have their predefined definitions in the compiler and cannot be used as the names of the identifiers.There are 51 keywords and 2 reserved words in Java.

2. Identifiers

These are the various names given to different components of the program. These includes the names of variables, methods, class, etc. They must not begin with a digit but can contain digits, letters, underscore, currency symbols.

3. Literals

These provide a way to express specific values in a program.These are of following types:

Numeric Literals

These are of three types in Java.

  • Integer Literals
  • Floating Point Literals
  • Character Literals

Boolean Literals

These are of two types

  • true
  • false

String Literals

4. Operators

These are the special types of symbols used to perform certain operations. For example +, -, *, /, %

5. Seperators

These include tab, enter, space bar.

Now let us consider a program
//Printing Hello World public class Hello { public static void main(String args[]) { System.out.println(“Hello World”); } }

The source code contains tokens such as public, class, Hello, {, public, static, void, main, (, String, [], args, {, System, out, println, (, “Hello World”, }, }. 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.

This article needs improvement. You can help improve this article. You can also write similar articles and help the community.