3. TOKENS
A token is the smallest elements of a program.
The different types of token in java are :-
1. Keyword
2. Indentifiers
3. Literals
4. Operators
5. Seperators
4. KEYWORDS
• Keywords is also known as Reserved words. These are predefined words by Java so they
cannot be used as a variable or object name or class name.
• Ex- int
for
Double
If
else
class
5. IDENTIFIERS
Identifiers in Java are symbolic names used for identification. They can be a class name, variable
name, method name, package name, constant name.
Rules:-
1. Indentifiers is the name assigned to an elements in a program
Examples: classes, variables, function, object & data member.
I. Identifiers may contain an alphabets, digit and two special symbols ($) & (_).
II. The first character of an indentifiers can only contain alphabet (a-z) (a-z).
III. No blanks spaces b/w the indentifiers.
IV. An identifier should not contain a number at the starting
7. EXAMPLES OF INVALID INDENTIFIER
Invalid identifiers:
Below are some examples of invalid identifiers:
•Test Variable ( We can not include a space in an identifier)
•123javatpoint ( The identifier should not begin with numbers)
•java+tpoint ( The plus (+) symbol cannot be used)
•a-javatpoint ( Hyphen symbol is not allowed)
•java_&_Tpoint ( ampersand symbol is not allowed)
•Java'tpoint (we can not use an apostrophe symbol in an identifier)
8. CASE 1-
SPACE IN WORDS
CASE 2-
FIRST LETTER IS NUMBER
CASE 3-
FIRST LETTER IS NOT A
DOLLAR OR UNDERSCORE
9. EXAMPLES OF VALID IDENTIFIER IN JAVA:
•TestVariable
•testvariable
•a
•i
•Test_Variable
•_testvariable
•$testvariable
•sum_of_array
•TESTVARIABLE
•jtp123
•JavaTpoint
•Javatpoint123
10. CASE 1- USE OF WORDS,
UNDERSCORE & NUMBER
CASE 2- NO SPACE B/W
DOLLAR AND WORD
CASE 3- WORDS WITHOUT
SPCE