LIWA

Identifiers and Literals

ICSE Class 9 · Computer Applications · Chapter 3

What this chapter covers

Key points

Questions answered

Define a token. Name the five types of tokens in Java.
A token is the smallest individual unit of a Java program that has a meaning to the compiler. The five types are keywords, identifiers, literals, punctuators (separators) and operators.
Write the ASCII codes of 'M', 'm', '0' and the blank space.
'M' is the thirteenth letter, so its code is 65 + 12 = 77; 'm' is 77 + 32 = 109; '0' is 48; the blank space is 32.
Give two reasons why Java uses Unicode instead of ASCII.
ASCII has only 128 characters and covers English alone, while Unicode can represent the characters of virtually every writing system. This allows one Java program to be globalised and localised for users in many languages, and lets text be exchanged between computers without being garbled.
What is the output of `System.out.println("Roll\tName\n1\t\"Asha\"");`?
Two lines. The first is Roll, a tab gap, then Name. The second is 1, a tab gap, then "Asha" with the double quotation marks printed.
How many tokens are there in `char grade = 'B';`? Classify them.
Five: `char` (keyword), `grade` (identifier), `=` (operator), `'B'` (character literal) and `;` (punctuator).
Which of these are invalid identifiers, and why: `my name`, `_total`, `int`, `9lives`, `priceINR`?
`my name` contains a space; `int` is a keyword; `9lives` begins with a digit. `_total` and `priceINR` are valid.
Distinguish between `'A'` and `"A"`.
`'A'` is a character literal of type `char`, a single character stored in 2 bytes as code 65. `"A"` is a string literal, a `String` object that happens to contain one character.
What is the difference between a variable and a constant? Write a statement to declare a constant for the number of players in a cricket team.
The value of a variable can change while the program runs; the value of a constant, declared with `final`, cannot be changed after it is assigned. Statement: `final int PLAYERS = 11;`

Past board exam questions

ICSE 2027 sample paper · 1 mark

The character equivalent of the ASCII code 65 is ‘a’. State true or false. (a) True (b) False

Show answer
(b) False — ASCII code 65 is the uppercase letter ‘A’; ‘a’ is 97.

ICSE 2027 sample paper · 1 mark

Which of the following cannot be used as an identifier in Java?

  1. calculate
  2. switch
  3. age
  4. grade
Show answer
switch

ICSE 2027 sample paper · 1 mark

Which of the following is the correct order of the number of bytes occupied by int, char, double and boolean?

  1. 2, 8, 4, 1
  2. 4, 8, 1, 2
  3. 2, 1, 4, 8
  4. 4, 2, 8, 1
Show answer
4, 2, 8, 1

ICSE 2027 sample paper · 1 mark

What does the escape sequence \t represent in Java?

  1. alert bell
  2. tab space
  3. form feed
  4. carriage return
Show answer
tab space

ICSE 2027 sample paper · 1 mark

Find the ODD one out of the following: int, double, Scanner, char

  1. int
  2. char
  3. Scanner
  4. double
Show answer
Scanner