Tokens in Java
Token is a smallest unit of java which is very important without token, we cannot write any java program.
Token is classified into 4 types:
Keywords
Identifiers
Separators
Literals
Keywords:
Keywords are predefined words
Keywords has it's own task
They are reserved words
We can use keywords, but we can't modify it.
Keywords are written in lowercase.
They are 50+ keywords. (around 67 )
E.g. public, class, static, void, etc.
Identifiers:
A name given by a programmer to the components of java
E.g. program name, class name, variable name, etc.
Rules to follow while writing Identifier:
Identifiers should not start with the numbers; but we can see the number in between the identifier or in the end of the identifier; which is known as alphanumeric.
We cannot use any special character except dollar($) and underscore(_)
Character space is not allowed in identifier
We cannot write keyword as an identifier
Separators:
Separators are used to separate the set of instruction. E.g. {}, [], (), :, ;
Literals:
Literals are the value/ data which we use in java program to perform a task
Literals are classified into
Primitive Literal
Non- Primitive Literal
Primitive Literal:
The primitive literal is classified into following types
e.g.
Number Value:
Integer e.g. 100, 5008
Float e.g. 10.55, 12.9, 15.3
Character Value:
Anything which is enclosed in a single quote
e.g. 'c', '1', 't', '@'
Boolean Value:
It is used for condition making.
Non - Primitive Literal:
The address or reference of an object is known as non-primitive literal/ non-primitive value.
e.g. String
Any value which is enclosed in a double quotes
Doesn't have a size limit.