Tokens
Tokens
This source code includes Java tokens such as class, token, public, static, void, main, (, ),
System, out, print.
Tokens
• A Java program is made up of small individual units or elements that have meaning. These are
known as Tokens.
• Tokens are the smallest elements that can be identified by the compiler.
Types of Tokens
Keywords
Identifiers
Literals
Operators
Punctuators
Separators
Keywords
Keywords are pre-defined words that are reserved by the Java Compiler for a specific purpose and used only in limited,
specific manner.
For example,
• abstract
• assert
• boolean
• break
• byte
• case
• catch
• Char
Types of Tokens
Keywords
Identifiers
Literals
Operators
Punctuators
Separators
Types of Tokens
Identifiers
Literals
Operators
Punctuators
Separators
Identifiers
• Identifiers are the names given to different components of a Java program like class, variables and methods.
• It can be a combination of letters and numbers or simply a sequence of letters.
• There are a few naming conventions for identifiers:-
An identifier must start with a letter(a-z or A-Z) or underscore(_) or dollar($).
An identifier does not start with a digit. However apart from the first character, it can have any combination of letters or
digits
An identifier can be of any length.
An identifier is case sensitive
An identifier cannot contain whitespaces.
An identifier cannot be a java keyword.
An identifier must not contain any special symbol apart from $ and _.
Types of Tokens
Identifiers
Literals
Operators
Punctuators
Separators
Types of Tokens
Literals
Operators
Punctuators
Separators
Literals
• Literals in Java are values that are assigned to a variable. They are used by programmers and can be of any data type.
• Literals are also called constants.
• Types of literals:-
• Integer Literals:10001, 27
• Floating point Literals: 2.5, 3.7, 555.678
• Character Literals: C, A, Z, \u0061
• String Literals: “Class 9 Cuckoos”, “St. Thomas School”
• Boolean Literals: True, False
• Null Literals
Types of Tokens
Literals
Operators
Punctuators
Separators
Types of Tokens
Operators
Punctuators
Separators
Operators
Operators are the Special symbols which are used to perform arithmetical or logical calculations on one or more
operands.
Types of Operators:
• Arithmetic Operators: +, -, *, /, %
• Assignment Operators: =, +=, -=, *=, /=, %=
• Relational Operators: >, <, >=, <=, ==, !=
• Unary Operators: ++, --
• Logical Operators: &&, ||, !
• Tenary Operators: ?, :
Types of Tokens
Operators
Punctuators
Separators
Types of Tokens
Punctuators
Separators
Punctuators
Punctuators are special characters in Java used as punctuation signs.
Some of the punctuators are:
‘?’Question Mark
‘:’Colon
‘;’Semicolon
‘.’Dot
Types of Tokens
Punctuators
Separators
Types of Tokens
Separators
Separators
Separators are the special characters used to separate the variables or characters in a Java Program. Some of the
separators are:
• Comma ,
• Brackets ( )
• Curly braces { }
• Square Braces [ ]