0% found this document useful (0 votes)
51 views

TOKENS in Java

Tokens in Java include keywords, identifiers, literals, operators, and special symbols. Keywords are reserved words with special meaning, identifiers name variables and methods, literals assign constant values, operators perform math or logical operations, and special symbols like brackets and braces have predefined uses in Java code.

Uploaded by

Ann Maria Jose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

TOKENS in Java

Tokens in Java include keywords, identifiers, literals, operators, and special symbols. Keywords are reserved words with special meaning, identifiers name variables and methods, literals assign constant values, operators perform math or logical operations, and special symbols like brackets and braces have predefined uses in Java code.

Uploaded by

Ann Maria Jose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

TOKENS in java

• Tokens in Java are the small units of code which a


Java compiler uses for constructing those statements and
expressions. Java supports 5 types of tokens which are:
• Keywords
• Identifiers
• Literals
• Operators
• Special Symbols
Keywords

• Keywords in Java are predefined or reserved


words that have special meaning to the Java
compiler.
• Each keyword is assigned a special task or
function and cannot be changed by the user.
You cannot use keywords as variables or
identifiers as they are a part of Java syntax
itself.
• A keyword should always be written in
lowercase as Java is a case sensitive language.
Java supports various keywords,
Identifier

• Java Identifiers are the user-defined names of variables,


methods, classes, arrays, packages, and interfaces.
• 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.
Valid Identifiers Invalid Identifiers
• $myvariable //correct • edu variable //error
• _variable //correct • Edu_identifier //error
• variable //correct • &variable //error
• edu_identifier_name • 23identifier //error
//correct • switch //error
• edu2019var //correct • var/edu //error
• edureka's //error
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.
These are defined by users and can belong to any
data type. Java supports five types of literals which are
as follows:
• Integer
• Floating Point
• Character
• String
• Boolean
public class EduLiteral
{
public static void main(String[] args)
{
int edu1 = 112; // Int literal
float edu2 = 31.10; // Float literal
char edu3 = 'edu' // char literal
String edu4 = "Edureka"; // String literal
boolean edu5 = true; // Boolean literal

System.out.println(edu1); //112
System.out.println(edu2); //31.40
System.out.println(edu3); //edu
System.out.println(edu4); //Edureka
System.out.println(edu5); //true
}
}
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. Java
supports 8 types of operators.
Special symbols

• Special symbols in Java are a few characters


which have special meaning known to Java
compiler and cannot be used for any other
purpose.
• Brackets [] These are used as an array
element reference and also indicates single
and multidimensional subscripts
• Parentheses()These indicate a function call along
with function parameters
• Braces{}The opening and ending curly braces
indicate the beginning and end of a block of code
having more than one statement
• Comma ( , )This helps in separating more than
one statement in an expression
• Semi-Colon (;)This is used to invoke an
initialization list
• Period operator(.)

You might also like