Java Tokens, Identifiers, Literals and Escape Sequences (ICSE Class 10)
Updated 17 October 2026 · Fact-checked
A token is the smallest unit of a Java program that has a meaning for the compiler. There are five kinds: keywords, identifiers, literals, punctuators and operators. An identifier is a name chosen by the programmer; it may use letters, digits, _ and $ but must not start with a digit or be a keyword. Escape sequences such as \n, \t, \\, \" and \' print special characters.
The compiler splits int total = 5; into five tokens: one keyword, one identifier, one operator, one literal and one punctuator.
Illustration drawn for QuestionBuddy.
Understand Tokens, Identifiers, Literals and Escape Sequences
Character set. The characters a language accepts: letters, digits, special symbols (like + - * / ; { }) and white space. Computers store characters as numbers. ASCII (American Standard Code for Information Interchange) gives each character a code: 'A' to 'Z' are 65 to 90, 'a' to 'z' are 97 to 122, and '0' to '9' are 48 to 57. Unicode is a larger code that covers characters of many languages; Java's char type uses Unicode, so Java can handle letters of any language.
Tokens. The compiler breaks the program into tokens. The five types in the syllabus:
1. Keywords: reserved words with a fixed meaning (class, int, public, static, if, new). They cannot be used as names.
2. Identifiers: names given to variables, methods, classes. Rules: made of letters, digits, underscore (_) and dollar ($); must not begin with a digit; no spaces or other symbols; cannot be a keyword; case sensitive (total and Total are different).
3. Literals: fixed values written in the program: integer (25), floating (3.14), character ('x' in single quotes), string ("hello" in double quotes) and boolean (true, false).
4. Punctuators (separators): symbols such as ; , ( ) { } [ ] that separate or group parts.
5. Operators: symbols that act on operands (+ - = == &&).
In int total = 5 + 3; the tokens are: int (keyword), total (identifier), = and + (operators), 5 and 3 (literals), ; (punctuator).
Escape sequences. A backslash followed by one character stands for a special character inside a string or char literal. The syllabus lists five:
\nnew line,\thorizontal tab,\\a backslash,\"a double quote,\'a single quote.
Each counts as one character even though two symbols are typed. Text like "C:\Java" is an error because \J is not a valid escape; write "C:\\Java".
Characters are numbers. 'A' + 1 is the int 66, not the character B. To get the character, convert: (char)('A' + 1) is 'B'.
Tokens, Identifiers, Literals and Escape Sequences: key facts
- Five types of tokens
- Keywords
- Identifiers
- Literals
- Punctuators
- Operators
- Classify every symbol of a statement into one of these.
- Identifier rules
- Letters, digits, underscore and dollar sign only
- Must not start with a digit
- No spaces
- Not a keyword
- Case sensitive
- A hyphen is not allowed: it is the minus operator.
- Escape sequences in the syllabus
- \n new line
- \t tab
- \\ backslash
- \" double quote
- \' single quote
- Each is one character.
- ASCII anchors
- 'A' = 65
- 'Z' = 90
- 'a' = 97
- 'z' = 122
- '0' = 48
- '9' = 57
- Lower case is 32 more than upper case.
How to answer Tokens, Identifiers, Literals and Escape Sequences questions
Use this routine for token and identifier questions.
- 1Split the statement at every symbol and word, left to right.
- 2Mark each piece: word reserved by Java (keyword), programmer name (identifier), fixed value (literal), ; , ( ) { } (punctuator), symbol that computes (operator).
- 3For a name, check in order: first character not a digit, only letters digits _ $, no spaces, not a keyword.
- 4For escape sequences, replace each by its single character and then print the line breaks and tabs in order.
- 5For char arithmetic, convert characters to their ASCII numbers first, calculate as int, then convert back with (char) if a character is wanted.
Tokens, Identifiers, Literals and Escape Sequences in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Tokens as words of a sentence
Suppose a teacher splits the sentence "Riya scored 90 marks." into words, a number and the full stop to check each part.
Match the parts to the five kinds of tokens in the statement int marks = 90;
Try it first, then show the solutionSolution
- int is a reserved word: keyword. marks is a name chosen by the programmer: identifier.
- = is an operator, 90 is a fixed value (literal), and ; ends the statement (punctuator).
Answer: int: keyword; marks: identifier; =: operator; 90: literal; ;: punctuator.
Memory hook: Every symbol in a statement belongs to exactly one token type.
ASCII as roll numbers for characters
Imagine a school gives each letter a roll number: A has 65, B has 66 and so on, while a has 97.
What is the roll number of the letter that comes 3 places after A, and what is that letter?
Try it first, then show the solutionSolution
- 65 + 3 = 68.
- The character with code 68 is D.
Answer: 68, the letter D.
Memory hook: Characters are numbers underneath.
Tricks to remember Tokens, Identifiers, Literals and Escape Sequences
Short memory aids. Say each one aloud once, then use it on a question the same day.
KILPO
Keywords, Identifiers, Literals, Punctuators, Operators: KILPO.
Use it when: Recalling the five token types.
Not 1st digit, no gaps
A name never starts with a digit and never has a gap or hyphen.
Use it when: Valid or invalid identifier items.
A65 a97 zero48
A is 65, a is 97 and the digit zero is 48.
Use it when: Character arithmetic.
Tokens, Identifiers, Literals and Escape Sequences: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Classify the tokens · 3 marks · Short answerBoard level
Name the type of each token in:
double area = 3.5 * r;Try it first, then show the solutionSolution
- double is a keyword and area is an identifier. (1 mark)
- = and * are operators. (1 mark)
- 3.5 is a floating literal, r is an identifier and ; is a punctuator. (1 mark)
Answer: double: keyword; area: identifier; =: operator; 3.5: literal; *: operator; r: identifier; ;: punctuator.
Example 2: Valid identifiers · 4 marks · Short answerHarder board level
Which of these are valid Java identifiers? Give a reason for each invalid one: marks1, 2ndTerm, total_marks, class, my name, $cost, Roll-No, _x.
Try it first, then show the solutionSolution
- Valid: marks1, total_marks, $cost, _x (letters, digits, underscore or dollar sign, not starting with a digit). (2 marks)
- Invalid: 2ndTerm starts with a digit; class is a keyword. (1 mark)
- Invalid: my name has a space; Roll-No contains a hyphen (minus operator). (1 mark)
Answer: Valid: marks1, total_marks, $cost, _x. Invalid: 2ndTerm (digit first), class (keyword), my name (space), Roll-No (hyphen).
Example 3: Escape sequences in output · 3 marks · Short answerHarder board level
Write the exact output (show a tab as [tab]):
System.out.println("Name:\t\"Ravi\"");
System.out.println("C:\\data\nEnd");Try it first, then show the solutionSolution
- First line: Name: then \t gives a tab, then \" prints a double quote, Ravi, and \" prints another quote. (1 mark)
- Second line text: C: then \\ prints one backslash, then data, then \n starts a new line. (1 mark)
- The remaining text End is printed on the next line, and println finishes that line. (1 mark)
Answer: Name:[tab]"Ravi"
C:\data
End
Example 4: Case study: characters as numbers · 4 marks · Case-basedHOTS / competency
A student runs these statements with char ch = 'd'; and records the output of each. (ASCII code of d is 100; a is 97, b is 98.)
(i) System.out.println(ch + 1);
(ii) System.out.println((char)(ch + 1));
(iii) System.out.println("" + ch + 1);
(iv) System.out.println('a' + 'b');
State the output of each statement and explain any difference.
Try it first, then show the solutionSolution
- (i) ch + 1 is int arithmetic: 100 + 1 = 101.
- (ii) The int 101 is cast to char, which is e.
- (iii) The empty string makes + join text: "d" then "1" gives d1.
- (iv) Two chars added are treated as ints: 97 + 98 = 195.
Answer: (i) 101 (ii) e (iii) d1 (iv) 195. Arithmetic on chars gives int; a string on the left makes + concatenate.
Example 5: Kinds of literals · 3 marks · Short answerHarder board level
Name the type of each literal: 25, 3.14, 'x', "x", true, 5.0f.
Try it first, then show the solutionSolution
- 25 is an integer literal; 3.14 is a floating-point literal. (1 mark)
- 'x' is a character literal (single quotes); "x" is a string literal (double quotes). (1 mark)
- true is a boolean literal; 5.0f is a floating-point literal of type float because of the suffix f. (1 mark)
Answer: 25: integer; 3.14: floating (double); 'x': character; "x": string; true: boolean; 5.0f: float.
Where students lose marks in Tokens, Identifiers, Literals and Escape Sequences
The slips examiners see most often, and what to write instead.
Mistake: Calling a name with a hyphen or a space valid
Only letters, digits, _ and $ are allowed; a hyphen is the minus operator.
Wrong working
Roll-No is a valid identifier.
Right working
Roll-No is invalid; Roll_No is valid.
Do this: Scan for symbols other than _ and $.
Usually costs: 1 mark
Mistake: Writing "C:\Java" for a path in a string
\J is not an escape sequence; the compiler reports an error. A backslash must be doubled.
Wrong working
System.out.println("C:\Java");
Right working
System.out.println("C:\\Java"); prints C:\Java
Do this: Double every backslash you want to print.
Usually costs: 1 mark
Mistake: Printing 'A' + 1 as B
Adding an int to a char gives an int; the cast (char) is needed to get a character.
Wrong working
System.out.println('A' + 1); gives B
Right working
System.out.println('A' + 1); gives 66; System.out.println((char)('A' + 1)); gives B
Do this: Look for the (char) cast before writing a letter.
Usually costs: 1 mark
Exam tips
- Learn the five escape sequences by heart: \n \t \\ \" \'; the syllabus lists only these.
- For a classification question, write every symbol of the statement, including ; and =.
- Remember that Java is case sensitive: Total and total are two identifiers.
- A string literal uses double quotes; a character literal uses single quotes.
Practice questions on Tokens, Identifiers, Literals and Escape Sequences
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
Which of the following is a valid identifier in Java?
(a) 3rd (b) int (c) total$ (d) a-bHint
Check the first character, keywords and symbols.
Answer
(c) total$
Q2 · 1 mark · Very short answerBoard level
Write the escape sequence that moves the cursor to a new line.
Hint
Backslash and a letter.
Answer
\n
Q3 · 2 marks · Short answerHarder board level
Write the output (show the line breaks):
System.out.println("He said \"Hi\""); System.out.println("C:\\Java");Hint
Each escape is one character.
Answer
He said "Hi"
C:\JavaQ4 · 2 marks · Short answerHarder board level
Write the output of:
System.out.println((char)('A' + 5)); System.out.println('A' + 5);(ASCII code of A is 65.)
Hint
Which line has the (char) cast?
Answer
F
70Q5 · 1 mark · Assertion-reasonHOTS / competency
Assertion (A): The word class cannot be used as the name of a variable in Java.
Reason (R): class is a keyword and keywords have a fixed meaning for the compiler.
(a) Both A and R are true and R is the correct explanation of A. (b) Both A and R are true but R is not the correct explanation of A. (c) A is true but R is false. (d) A is false but R is true.Hint
Is class a keyword?
Answer
(a) Both are true and R explains A.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.Name the five types of tokens.Show answer
Keywords, identifiers, literals, punctuators and operators.
2.What is the ASCII code of capital A?Show answer
65
3.Which escape sequence prints a tab?Show answer
\t
4.Can an identifier start with a digit?Show answer
No.
5.What is Unicode?Show answer
A character code covering the letters of many languages; Java char uses it.
6.How many characters does \n count as?Show answer
One.
Tokens, Identifiers, Literals and Escape Sequences: frequently asked questions
What is the difference between ASCII and Unicode?
ASCII is a smaller code for English letters, digits and symbols; Unicode is a larger code covering many languages. The ASCII values are the first part of Unicode.
Is true a keyword or a literal?
true and false are boolean literals in Java.
Why is main not a keyword?
main is the name of a method with a special role for the JVM; it is an identifier, not a reserved word. Words like class, int and public are keywords.