Character Set, ASCII, Unicode, Escape Sequences and Tokens in Java (ICSE Class 9)
Updated 18 October 2026 · Fact-checked
Java programs are made of characters (letters, digits, special characters, white space) coded by ASCII (A-Z 65 to 90, a-z 97 to 122, 0-9 48 to 57, space 32) and, more widely, by Unicode. Escape sequences such as \n \t \\ \" \' represent special characters. A token is the smallest unit the compiler recognises: keywords, identifiers, literals, punctuators and operators; identifiers follow naming rules.
Notice that one short statement breaks into five tokens, and each token belongs to exactly one type.
Illustration drawn for QuestionBuddy.
Understand Character Set, ASCII, Unicode, Escape Sequences and Tokens in Java
Character set. Letters A-Z and a-z, digits 0-9, special characters (such as + - * / % = < > ! & | ( ) { } [ ] ; , . and the underscore) and white space (blank, tab, new line).
ASCII. A code that gives each character a number from 0 to 127. A-Z are 65 to 90, a-z are 97 to 122, the digits 0-9 are 48 to 57 and the space is 32. A small letter's code is 32 more than its capital's ('a' - 'A' is 32). When a char is used in arithmetic, its code is used: 'A' + 1 is 66.
Unicode. A universal coding system that gives a unique number to the characters of virtually every writing system and to symbols. Java stores a char in 16 bits using Unicode, and its first 128 characters are the same as ASCII. Importance: one program can show text in many languages, data can be exchanged reliably between computers, and characters are handled in a consistent way.
Escape sequences. A backslash followed by a character, counted as a single character: \n new line, \t tab, \\ backslash, \" double quote, \' single quote.
Example: System.out.println("He said \"Hi\""); prints He said "Hi".
Tokens. The smallest units a compiler recognises.
1. Keywords: reserved words with a fixed meaning (class, int, double, if, else, for, while, new, void, public, static, import, return, final) that cannot be used as names.
2. Identifiers: names chosen by the programmer for variables, classes, methods and objects.
3. Literals: fixed values written in the program: integer (25), floating-point (3.14), character ('A'), string ("ICSE"), boolean (true, false) and null.
4. Punctuators (separators): ; , . ( ) { } [ ]
5. Operators: + - * / % = == < > && || ! ++ --
Rules for identifiers. Letters, digits, underscore and the dollar sign are allowed; the first character must not be a digit; no spaces or other special characters; it must not be a keyword; it is case sensitive and can be of any length. Conventionally class names begin with a capital letter and variables and methods with a small letter.
Neighbouring topics: variables, constants, data types and type conversion are on the next page of this chapter.
Character Set, ASCII, Unicode, Escape Sequences and Tokens in Java: key facts
- ASCII ranges
A-Z 65 to 90 a-z 97 to 122 0-9 48 to 57 space 32 - Small letter = capital + 32.
- Escape sequences
new line backslash n tab backslash t backslash two backslashes double quote backslash then quote - Each counts as one character.
- Five tokens
- Keywords
- identifiers
- literals
- punctuators
- operators
- Smallest units of a program.
- Identifier rules
- Letters, digits, underscore, dollar
- not starting with a digit
- no spaces
- not a keyword
- case sensitive
- Class name starts with a capital.
Character Set, ASCII, Unicode, Escape Sequences and Tokens in Java 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.
Unicode on a school certificate
Suppose a school prints each student's name on a certificate in English and also in the student's home language, such as Bengali or Marathi.
Why does the certificate program need Unicode and not only ASCII?
Try it first, then show the solutionSolution
- ASCII has only 128 codes, enough for English letters but not for Bengali or Marathi letters.
- Unicode gives a code to the characters of these scripts.
- So the same program can print every name correctly.
Answer: Unicode lets one program store and show text in many scripts with consistent codes.
Memory hook: One code system for all scripts.
Tricks to remember Character Set, ASCII, Unicode, Escape Sequences and Tokens in Java
Short memory aids. Say each one aloud once, then use it on a question the same day.
65, 97, 48, 32
A is 65, a is 97, 0 is 48, space is 32.
Use it when: ASCII values.
Backslash starts the magic
Every escape sequence starts with a backslash and counts as one character.
Use it when: Escape sequences.
KILPO
Keywords, Identifiers, Literals, Punctuators, Operators.
Use it when: Five kinds of tokens.
Character Set, ASCII, Unicode, Escape Sequences and Tokens in Java: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: ASCII value · 1 mark · MCQBoard level
The ASCII code of the capital letter A is:
(a) 97 (b) 65 (c) 48 (d) 32
Try it first, then show the solutionSolution
- Capital letters start at 65; 97 is a small a, 48 is the digit 0, 32 is space.
Answer: (b) 65
Example 2: Characters and codes · 3 marks · Short answerHarder board level
Find the output:
System.out.println((char) ('a' + 3) + " " + (int) 'Z' + " " + (char) 101);Try it first, then show the solutionSolution
- (char) ('a' + 3): 97 + 3 = 100, which is the character d. (1 mark)
- (int) 'Z' is 90. (1 mark)
- (char) 101 is e. The parts are joined with spaces: d 90 e. (1 mark)
Answer: d 90 e
Example 3: Escape sequences in one statement · 3 marks · Short answerHarder board level
Show the output of:
System.out.println("Name:\tRia\nClass:\t\"IX\"\nPath: C:\\data");Try it first, then show the solutionSolution
- \n starts a new line and \t gives a tab gap, so there are three lines. (1 mark)
- \" prints a double quote inside the text. (1 mark)
- \\ prints one backslash. Output: Name: (tab) Ria; Class: (tab) "IX"; Path: C:\data. (1 mark)
Answer: Name:<tab>Ria
Class:<tab>"IX"
Path: C:\data
Example 4: Case study: classify the tokens · 4 marks · Case-basedHOTS / competency
Consider the statement final int MAX = 100;
(i) List all the tokens and name the kind of each. (3)
(ii) What does final do to MAX? (1)
Try it first, then show the solutionSolution
- (i) final: keyword; int: keyword; MAX: identifier; =: operator; 100: integer literal; ;: punctuator.
- (ii) final makes MAX a constant, so its value cannot be changed after assignment.
Answer: (i) final (keyword), int (keyword), MAX (identifier), = (operator), 100 (literal), ; (punctuator) (ii) MAX becomes a constant
Example 5: Character arithmetic · 3 marks · Short answerHarder board level
Find the output:
char c = 'M';
c = (char) (c + 2);
int d = c - 'A';
System.out.println(c + " " + d);Try it first, then show the solutionSolution
- 'M' is 77, so c + 2 = 79, which is the character O. (1 mark)
- d = 79 - 65 = 14. (1 mark)
- Output: O 14. (1 mark)
Answer: O 14
Where students lose marks in Character Set, ASCII, Unicode, Escape Sequences and Tokens in Java
The slips examiners see most often, and what to write instead.
Mistake: Writing 0 for the code of the digit 0
The digit and the number are mixed.
Wrong working
ASCII of '0' is 0
Right working
ASCII of '0' is 48
Do this: Digits start at 48.
Usually costs: 1 mark
Mistake: Calling a hyphen valid in a name
Hyphens look like underscores.
Wrong working
net-pay is valid
Right working
net-pay is invalid; net_pay is valid
Do this: Only letters, digits, underscore and dollar.
Usually costs: 1 mark
Mistake: Single backslash in a path
Escape sequences are ignored.
Wrong working
"C:\data" written with a single backslash
Right working
Use two backslashes
Do this: A backslash must be escaped.
Usually costs: 1 mark
Exam tips
- Memorise 65, 97, 48 and 32.
- Count each escape sequence as one character.
- List all five kinds of tokens when asked.
- When a char appears in arithmetic, convert it to its code first.
Practice questions on Character Set, ASCII, Unicode, Escape Sequences and Tokens in Java
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 these is a valid identifier?
(a) 2nd_rank (b) rank_2 (c) rank 2 (d) rank-2Hint
No digit first, no space, no hyphen.
Answer
(b) rank_2
Q2 · 2 marks · Very short answerBoard level
Give the ASCII range of (i) small letters (ii) digits.
Hint
Remember the starting values.
Answer
(i) 97 to 122 (ii) 48 to 57
Q3 · 2 marks · Short answerHarder board level
Find the output:
System.out.println('a' + 1 + " " + (char) ('a' + 1));Hint
The char becomes an int in arithmetic.
Answer
98 b ('a' + 1 = 98 as numbers; the second part is the character with code 98)
Q4 · 3 marks · Short answerHarder board level
Write one println() statement that prints exactly: He said "Hi" and the path D:\files
Hint
Escape the quotes and the backslash.
Answer
System.out.println("He said \"Hi\" and the path D:\\files");
Q5 · 3 marks · Short answerHOTS / competency
Explain with an example why Unicode is needed even though ASCII already has codes for letters.
Hint
What does ASCII not cover?
Answer
ASCII has only 128 codes, enough for English letters, digits and common symbols but not for scripts such as Devanagari or Tamil. Unicode gives a unique number to the characters of virtually every script, so a program can store a name written in Hindi or Tamil and show it correctly.
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.ASCII code of a?Show answer
97
2.ASCII code of the space?Show answer
32
3.Which escape sequence is the tab?Show answer
Backslash t.
4.How many bits does a char take?Show answer
16 bits.
5.Is true a keyword or a literal?Show answer
A boolean literal.
6.Can an identifier start with a digit?Show answer
No.
Character Set, ASCII, Unicode, Escape Sequences and Tokens in Java: frequently asked questions
Is the dollar sign allowed in an identifier?
Yes, but it is rarely used.
Is Java case sensitive?
Yes. Marks and marks are different identifiers.
Are Unicode and ASCII the same?
The first 128 Unicode characters are the same as ASCII; Unicode has many more.