Identifiers and Literals
ICSE Class 9 · Computer Applications · Chapter 3
What this chapter covers
- Character set of Java
- ASCII codes
- Unicode and its importance
- Escape sequences
- Tokens
- Keywords
- Identifiers
- Literals
- Punctuators and operators
- Constants and variables
- Data types
- Type conversion
Key points
- The character set of Java is the set of characters allowed in a program: letters, digits, special symbols and white space. Java is case-sensitive.
- ASCII codes: A–Z are 65–90, a–z are 97–122, digits 0–9 are 48–57 and the blank space is 32. A lowercase letter's code is 32 more than its capital.
- Unicode gives a unique code to the characters of virtually every script; its first 128 codes equal ASCII. Java stores each `char` in 16 bits as a Unicode value, which supports globalisation, localisation, data exchange and character handling.
- An escape sequence is a backslash followed by a character that stands for one special character: `\n` new line, `\t` tab, `\\` backslash, `\"` double quote, `\'` single quote.
- A token is the smallest meaningful unit of a program. The five types are keywords, identifiers, literals, punctuators and operators.
- Keywords are reserved lowercase words with fixed meanings and cannot be used as names.
- Identifiers are programmer-given names: letters, digits, underscore and the dollar sign only; no leading digit, no spaces, no keywords; case-sensitive.
- Literals are fixed values written in the code: integer, floating-point, character, string, boolean and null.
- A variable is a named memory location whose value can change; a constant is declared with `final` and cannot change.
- The eight primitive types and sizes: `byte` 8 bits (1 byte), `short` 16 (2), `int` 32 (4), `long` 64 (8), `float` 32 (4), `double` 64 (8), `char` 16 (2), and `boolean`, which holds 1 bit of information and is commonly stored in 1 byte.
- Non-primitive (reference) types such as `String`, arrays and classes store the address of an object, not the value itself.
- Implicit conversion is automatic widening from a smaller to a larger type with no data loss; in mixed expressions the result takes the largest type, and `byte`, `short` and `char` are promoted to at least `int`.
- Explicit conversion (type casting) uses `(type)` before a value, is needed for narrowing, and truncates fractions: `(int) 9.99` is 9.
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?
- calculate
- switch
- age
- 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?
- 2, 8, 4, 1
- 4, 8, 1, 2
- 2, 1, 4, 8
- 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?
- alert bell
- tab space
- form feed
- carriage return
Show answer
tab space
ICSE 2027 sample paper · 1 mark
Find the ODD one out of the following: int, double, Scanner, char
- int
- char
- Scanner
- double
Show answer
Scanner