Java Token
•Individual element in the program
•More than one token can appear can be appear
in a single line by separated by white spaces
Tokens:-
Keywords
Identifier
Operator
Special symbols
Literals
Token Explaination
Keywords
Belongs to the java language
which defined in standard meaning
Words to be lowercase and should used
for intended purpose.
Operators
An Operator in Java is a special symbol that signifies the
compiler to perform some specific mathematical or non-
mathematical operations on one or more operands.
Special symbol
Special symbols in java are a few characters which have
special meaning known to Java compiler and cannot be used for
any other purpose.
Identifier
are the user-defined names of variables, methods,
classes, arrays, packages, and interfaces.
it to refer the value associated with that identifier
in later statements
Identifier
Identifiers must begin with a letter, dollar sign or underscore.
Apart from the first character, an identifier can have any
combination of characters.
Identifiers in Java are case sensitive.
Java Identifiers can be of any length.
Identifier name cannot contain white spaces.
Any identifier name must not begin with a digit but can contain
digits within.
Most importantly, keywords can’t be used as identifiers in Java.
Identifier Ex
$myvariable //correct
_variable //correct
variable //correct
edu_identifier_name //correct
edu2019var //correct
Literals
Literals in Java are similar to normal variables but their
values cannot be changed once assigned. In other words, literals
are constant variables with fixed values.
Five type of literals:-
Integer
Floating Point
Character
String
Boolean
Comments
Comments are simple notes for the programmer to
remind themselves and other programs is meant to
Three types of comments
Single
Multiline
Documentation
Compile & Run
Statement
A statement is a complete instruction
terminated by semicolon.
Example:-
String name=“Raghu”
Block
A block a group of statements enclosed within curly
braces.
Example:-
{
Name=“Hai”
Message=“Welcome”
}
Control Statement
Control statement allows the programmers to
develop the flow of program execution based
upon on some conditions during run time
Selection Stm
Selection statement allow the program to chose
different path of execution based upon the
outcome of an conditional expression or the
state of variable.
if-else
switch
if-else
if statement can check the statement from simple to complex for
executing.
if statement handles a very simple situation and excutes only
when the condition is true otherwise the whole body is skipped.
Illustration is described the below figure
Syntax for if
if example
if –else statement
if-else example
if-else-if
Example
Nested if
Switch in real life
Definition
Syntax
Example
Facts
Compare