Java Tokens

In this tutorial you will learn about the Java Tokens and its application with practical example.

Java Tokens

Token is basically smallest element that can identified by the compiler. Java expressions and statements are constructed using java tokens. A java program is basically made up of different types of tokens that can either be a keyword, an identifier, a constant, a string literal, or a symbol. In Java, we have five types of tokens as following –

  • Keywords
  • Identifiers
  • Constants
  • Separators
  • Operators

Keywords:- In Java, there are is a set of reserved words that you cannot use as an identifier. These words are known as “reserved words” or “Keywords”. Keywords are standard identifiers and their functions is predefined by the compiler. We cannot use keywords as variable names, class names, or method names, or as any other identifier.

Identifiers :- Identifier is basically used as variable names such as sum, total etc.

Constants :- Constants are expressions with a immutable value.

Separators :- Separator is a token used to separate two individual tokens used in a java program. Separators are also knows as punctuators. In Java, we have the brace { and }, parenthesis ( and ), and brackets [ and ], comma (,), semicolon (;), asterisk (*), colon (:), number sign #(hash) as punctuators.

Operators :- An operator is symbol that represents a specific mathematical or non-mathematical operation.

In this tutorial we have learn about the Java Tokens and its application with practical example. I hope you will like this tutorial.