Skip to content
Computer ApplicationsICSE Class 9 · Chapter 3

Identifiers and Literals ICSE Class 9: Tokens, Data Types and Type Conversion

Updated 15 October 2026 · Fact-checked

Identifiers are the names a programmer gives to classes, variables and methods; literals are fixed values written directly in a program, such as 25, 3.5, 'A', "Hi" or true. ICSE Class 9 tests Java's character set, ASCII and Unicode, escape sequences, the five kinds of tokens, variables and constants, data types with sizes, and implicit and explicit type conversion.

What Identifiers and Literals is about

Every Java statement is built from small pieces: characters form tokens (keywords, names, values, symbols), tokens form statements, and statements form a program. To write correct programs you must know which characters Java accepts, how names may be formed, how values are written, how much memory each type of value needs, and how Java converts one type into another.

The CISCE syllabus asks for: the character set, ASCII codes (of A-Z, a-z, 0-9 and the white space), Unicode and its importance, escape sequences (\n, \t, \\, \", \'), tokens and their types (keywords, identifiers, literals, punctuators, operators), constants and variables, primitive and non-primitive data types with sizes in bits and bytes, and implicit and explicit type conversion.

Learn the ASCII ranges exactly: A-Z are 65-90, a-z are 97-122, 0-9 are 48-57 and the space is 32. Many output questions depend on them.

Weightage: CISCE publishes no chapter weightage and no question-paper layout for ICSE Class 9 Computer Applications. Class IX is examined by your school: one 100-mark theory paper of 2 hours, plus 100 marks of internal assessment (at least 15 programming assignments and a written project on ethical computing). This is topic 3 of the 2028 syllabus.Source: CISCE ICSE 2028 Computer Applications syllabus, Class IX

Key concepts

Character set, ASCII and Unicode

Character set: the characters Java accepts in a program:

  • Letters: A-Z and a-z.
  • Digits: 0-9.
  • Special characters: + - * / % = < > ! & | ^ ~ ? : ; , . ' " ( ) { } [ ] _ @ # and others (including the dollar sign).
  • White space: blank space, tab, new line.

ASCII (American Standard Code for Information Interchange): a code that gives each character a number from 0 to 127.

  • A-Z: 65 to 90 (A = 65, Z = 90).
  • a-z: 97 to 122 (a = 97, z = 122).
  • 0-9: 48 to 57 (the digit '0' = 48, '9' = 57).
  • Space: 32.

A lowercase letter's code is 32 more than its uppercase letter's code ('a' − 'A' = 32).

Unicode: a universal coding system that gives a unique number to every character of virtually every writing system in the world (Latin, Devanagari, Bengali, Tamil, Chinese, Arabic and more), as well as symbols. Java stores characters (char) in Unicode, using 16 bits (2 bytes). The first 128 Unicode characters are the same as ASCII.
Importance of Unicode in Java: globalisation and localisation (one program can show text in Hindi, Tamil or Japanese); reliable data exchange between computers and countries; consistent character handling (sorting, comparing) in any language.

Worked example

(2 marks) Give the output: System.out.println((int) 'A' + " " + (int) 'a' + " " + (int) '0' + " " + (int) ' ');

Try it first, then show the solutionSolution
  1. Codes: 'A' = 65, 'a' = 97 - 1 mark.
  2. '0' = 48, space = 32; joined with spaces - 1 mark.

Answer: 65 97 48 32

Escape sequences

An escape sequence is a backslash (\) followed by a character, used inside character or string literals to represent characters that cannot be typed directly or have a special meaning. It counts as a single character.

The five in the syllabus:

  • \n: new line (moves the cursor to the next line).
  • \t: horizontal tab (moves to the next tab stop).
  • \\: prints a backslash.
  • \": prints a double quote inside a string.
  • \': prints a single quote (needed inside a char literal: '\'').

As run in this study guide:
System.out.println("Name\tClass\nRiya\tIX");
System.out.println("He said, \"Java\'s fun\"");
System.out.println("C:\\BlueJ\\Projects");
Output:
Name Class
Riya IX
He said, "Java's fun"
C:\BlueJ\Projects
(The gaps are tab characters.)

Worked example

(2 marks) Write a single println() statement to print:
Teacher said "Well done"
and then the next line.

Try it first, then show the solutionSolution
  1. Use \" for each double quote inside the string - 1 mark.
  2. Statement: System.out.println("Teacher said \"Well done\""); - 1 mark.

Answer: System.out.println("Teacher said \"Well done\"");

Tokens: keywords, identifiers, literals, punctuators, operators

A token is the smallest individual unit of a program that the compiler recognises.

1. Keywords (reserved words): words with a fixed meaning in Java that cannot be used as names. Examples: class, int, double, char, boolean, if, else, for, while, do, switch, case, break, new, void, public, static, import, return.

2. Identifiers: names given by the programmer to variables, classes, methods and objects. Rules:

  • may contain letters, digits, underscore (_) and the dollar sign;
  • must not begin with a digit;
  • must not contain spaces or other special characters;
  • must not be a keyword (or the literals true, false, null);
  • are case sensitive (marks and Marks are different);
  • can be of any length.

Valid: totalMarks, _rate, area2, rollNo. Invalid: 2area (starts with a digit), total marks (space), class (keyword), net-pay (hyphen).
Conventions: class names start with a capital letter (Student); variables and methods start with a small letter (rollNo, findArea).

3. Literals (constants): fixed values written in the program:

  • integer literals: 25, -7, 0, 100L (long);
  • floating-point (real) literals: 3.14, -0.5, 2.5f (float), 1.2e3;
  • character literals: one character in single quotes: 'A', '7', '\n';
  • string literals: characters in double quotes: "ICSE", "" (empty);
  • boolean literals: true, false;
  • null literal: null.

4. Punctuators (separators): ; , . ( ) { } [ ]

5. Operators: symbols that perform operations: + - * / % = == < > && || ! ++ --

Worked example

(2 marks) State whether each identifier is valid; give a reason if invalid: (i) _total (ii) 3rdTerm (iii) net pay (iv) price_2

Try it first, then show the solutionSolution
  1. (i) valid; (ii) invalid: begins with a digit - 1 mark.
  2. (iii) invalid: contains a space; (iv) valid - 1 mark.

Answer: (i) Valid. (ii) Invalid: cannot begin with a digit. (iii) Invalid: contains a space. (iv) Valid (letters, underscore and digit, not first).

Variables, constants and data types

Variable: a named memory location that stores a value which can change while the program runs. Declared with a type: int marks = 85;
Constant: a named value that cannot be changed once assigned, declared with the keyword final: final double RATE = 8.5; Trying to change RATE gives a compile-time error. Literals are also constants.

Primitive data types (built into Java; size fixed):

  • byte: 8 bits (1 byte); −128 to 127.
  • short: 16 bits (2 bytes); −32,768 to 32,767.
  • int: 32 bits (4 bytes); about −2.1 billion to 2.1 billion (2,147,483,647 maximum).
  • long: 64 bits (8 bytes); very large whole numbers.
  • float: 32 bits (4 bytes); decimal numbers, about 6-7 significant digits; literal needs f (2.5f).
  • double: 64 bits (8 bytes); decimal numbers, about 15 significant digits; the default for decimal literals.
  • char: 16 bits (2 bytes); one Unicode character.
  • boolean: true or false; Java does not fix its size (textbooks often describe it as 1 bit).

Non-primitive (reference) data types: built from primitives, store a reference to an object: classes (including String and Scanner), arrays and interfaces. Example: String name = "Riya";

Default values of data members: 0 for numeric types, 0.0 for float and double, '\u0000' for char, false for boolean, null for references.

Worked example

(2 marks) State the size in bits and bytes of: (i) char (ii) long (iii) float (iv) short.

Try it first, then show the solutionSolution
  1. char 16 bits = 2 bytes; long 64 bits = 8 bytes - 1 mark.
  2. float 32 bits = 4 bytes; short 16 bits = 2 bytes - 1 mark.

Answer: (i) char: 16 bits (2 bytes). (ii) long: 64 bits (8 bytes). (iii) float: 32 bits (4 bytes). (iv) short: 16 bits (2 bytes).

Implicit type conversion (type promotion)

Implicit (automatic, widening) conversion is done by Java itself when a value of a smaller type is used where a larger type is expected. The value is not cut down (the one exception: a very large int or long converted to float may lose its last digits of precision, e.g. 123456789 becomes 1.23456792E8).
Order: byte → short → int → long → float → double; and char → int.

Examples (as run in this study guide):

  • int i = 7; double d = i; prints 7.0
  • 'A' + 1 → char promoted to int: 66
  • char ch = 'M'; int code = ch + 0; prints 77
  • 'A' + 'B' → both promoted to int: 65 + 66 = 131 (not "AB")
  • "" + 'A' + 'B' → string joining: AB

In an expression with mixed types, every operand is promoted to the largest type present before the operation: 5 / 2.0 gives 2.5 because 5 is promoted to double.
Integer division: when both operands are integers, the result is an integer and the fraction is dropped: 5 / 2 gives 2.

Worked example

(2 marks) Give the output: System.out.println('A' + 'B'); System.out.println("" + 'A' + 'B');

Try it first, then show the solutionSolution
  1. 'A' + 'B': both chars promoted to int: 65 + 66 = 131 - 1 mark.
  2. "" + 'A' makes a String, then 'B' is joined: AB - 1 mark.

Answer: 131
AB

Explicit type conversion (type casting)

Explicit conversion (type casting, narrowing) is requested by the programmer by writing the target type in brackets before the value: (type) value. It is needed to convert a larger type into a smaller one, and data may be lost.

Examples (as run in this study guide):

  • (int) 7.9 gives 7 (the fraction is cut off, not rounded).
  • (char) 98 gives 'b'.
  • (char) ('A' + 2) gives 'C'.
  • (double) 5 / 2 gives 2.5 (5 becomes 5.0 before dividing).
  • (double) (5 / 2) gives 2.0 (5 / 2 is 2 first, then converted).
  • (byte) 130 gives −126, because 130 does not fit in a byte (range −128 to 127) and wraps around.

Overflow without a cast: if int over = 2147483647; over = over + 1; then over becomes −2147483648, because int cannot hold a larger value. Using long avoids this: a long holding 2147483647 plus 1 gives 2147483648.

Implicit vs explicit:
1. Implicit is done automatically; explicit is written by the programmer.
2. Implicit converts smaller to larger (widening); explicit usually larger to smaller (narrowing).
3. Implicit loses no data; explicit may lose data.

Worked example

(2 marks) Give the output: System.out.println(5 / 2 + " " + 5 / 2.0 + " " + (double) 5 / 2 + " " + (double) (5 / 2));

Try it first, then show the solutionSolution
  1. 5 / 2 = 2 (integer division); 5 / 2.0 = 2.5 - 1 mark.
  2. (double) 5 / 2 = 2.5; (double) (5 / 2) = 2.0 - 1 mark.

Answer: 2 2.5 2.5 2.0

Identifiers and Literals in real life

Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

Unicode

Suppose a railway booking app made in India must show station names in English, Hindi and Tamil on the same screen.

Why would ASCII alone fail, and what does Java use instead?

Try it first, then show the solutionSolution
  1. ASCII has only 128 codes, enough for English letters, digits and symbols.
  2. Hindi and Tamil letters need many more codes.
  3. Java's char uses 16-bit Unicode, which has codes for characters of virtually all scripts.

Answer: ASCII cannot represent Devanagari or Tamil characters. Java stores text in Unicode, so the same program can display all three scripts correctly.

Memory hook: ASCII for English, Unicode for the world.

Choosing a data type

Imagine designing a school app that stores a student's age, the school's total fee collection in a year, a grade letter and whether fees are paid.

Choose suitable data types.

Try it first, then show the solutionSolution
  1. Age is a small whole number: byte or int.
  2. Total fee collection may be a very large number with paise: double (or long in paise).
  3. Grade letter: char; fees paid or not: boolean.

Answer: age: byte (or int); totalFees: double; grade: char; feesPaid: boolean.

Memory hook: Fit the box to the thing you store.

Overflow

Suppose an odometer in an old car shows only five digits and rolls from 99999 back to 00000.

Which Java behaviour does this resemble?

Try it first, then show the solutionSolution
  1. The odometer has a fixed number of digits.
  2. A Java int has a fixed 32 bits with a maximum of 2,147,483,647.
  3. Adding 1 to the maximum wraps round to the most negative value.

Answer: Integer overflow: int over = 2147483647; over = over + 1; makes over −2147483648, just as the odometer rolls over; a larger type such as long avoids it.

Memory hook: Fixed boxes roll over.

Topics in this chapter

Identifiers and Literals: syntax and key facts

ASCII ranges
A-Z: 65-90; a-z: 97-122; 0-9: 48-57; space: 32
lowercase = uppercase + 32.
Escape sequences
\n new line; \t tab; \\ backslash; \" double quote; \' single quote
Each counts as one character.
Sizes
byte 8 bits (1 B); short 16 (2 B); int 32 (4 B); long 64 (8 B); float 32 (4 B); double 64 (8 B); char 16 (2 B)
boolean: true/false.
Widening order
  1. 1.byte
  2. 2.short
  3. 3.int
  4. 4.long
  5. 5.float
  6. 6.double; char
  7. 7.int
Implicit; no data lost.
Cast
(type) value, e.g. (int) 7.9 = 7; (char) 98 = 'b'
Explicit; may lose data.

How the school exam asks Identifiers and Literals

The question patterns to expect, and the method that works for each.

Question typeHow it is askedMethod
MCQ and assertion-reason (1 mark)Size of a type; valid identifier; ASCII value; which is a keyword; type of a literal.Learn sizes, rules and the four ASCII ranges by heart.
Output (2 marks)char arithmetic, casting, integer division, escape sequences in println().Decide int vs char vs String at each + from left to right.
Short answer (2 marks)Implicit vs explicit conversion; primitive vs non-primitive; importance of Unicode; types of tokens.Two contrasting points with examples.
Program (15 marks)Use char codes and casting to convert letters and show codes in a table.Declare with correct types; use (char) and (int) casts; \t for columns.

Tricks to remember Identifiers and Literals

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • 65, 97, 48, 32

    Capital A sits at 65, small a is 32 places later at 97, the digit 0 is at 48, and the space is at 32 (the same gap as between cases).

    Use it when: ASCII anchors.

  • KILPO

    Tokens: Keywords, Identifiers, Literals, Punctuators, Operators.

    Use it when: Five token types.

  • 1-2-4-8 and 2-4-8

    byte 1, short 2, int 4, long 8 bytes; char 2, float 4, double 8 bytes.

    Use it when: Sizes.

Identifiers and Literals: exam-level solved questions

Ordered from exam level to HOTS. Cover the solution, write your own, then compare step by step.

Example 1: Size of char · 1 mark · MCQExam level

The size of the char data type in Java is:
(a) 8 bits
(b) 16 bits
(c) 32 bits
(d) 64 bits

Try it first, then show the solutionSolution
  1. Java chars are Unicode characters.
  2. They use 2 bytes = 16 bits.

Answer: (b) 16 bits

Example 2: Assertion and reason: casting · 1 mark · Assertion-reasonHarder exam level

Assertion (A): (int) 7.9 gives 8.
Reason (R): Explicit conversion from double to int drops the fractional part.
(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

Try it first, then show the solutionSolution
  1. Casting truncates, it does not round: (int) 7.9 = 7, so A is false.
  2. R is true.

Answer: (d) A is false but R is true

Example 3: char arithmetic output · 2 marks · Short answerHarder exam level

Give the output:
System.out.println('A' + 1);
System.out.println((char) ('A' + 2));
System.out.println((char) 98);
char c = 'D';
c++;
System.out.println(c);
System.out.println('a' - 'A');

Try it first, then show the solutionSolution
  1. 'A' + 1 = 66 (int); (char) 67 = C; (char) 98 = b.
  2. c++ keeps the char type: E; 'a' − 'A' = 97 − 65 = 32.

Answer: 66
C
b
E
32

Example 4: Identify the literals · 2 marks · Very short answerExam level

Classify the literals: 45L, 'x', "45", 3.0f, false, 2.5e2

Try it first, then show the solutionSolution
  1. 45L: integer (long); 'x': character; "45": string.
  2. 3.0f: floating-point (float); false: boolean; 2.5e2: floating-point (double, value 250.0).

Answer: 45L integer (long) literal; 'x' character literal; "45" string literal; 3.0f floating-point (float) literal; false boolean literal; 2.5e2 floating-point (double) literal.

Example 5: Overflow and long · 2 marks · Short answerHOTS / competency

Give the output and explain:
long big = 2147483647;
int over = 2147483647;
over = over + 1;
System.out.println(big + 1);
System.out.println(over);

Try it first, then show the solutionSolution
  1. big + 1 is a long calculation: 2147483648.
  2. over + 1 exceeds the int maximum and wraps to the minimum: −2147483648.

Answer: 2147483648
-2147483648
A long can hold the larger value, but an int cannot go beyond 2,147,483,647, so it overflows and wraps round to −2,147,483,648.

Example 6: Escape sequences output · 2 marks · Very short answerHarder exam level

Give the output:
System.out.println("He said, \"Java\'s fun\"");
System.out.println("C:\\BlueJ\\Projects");

Try it first, then show the solutionSolution
  1. \" prints " and \' prints '.
  2. \\ prints a single backslash.

Answer: He said, "Java's fun"
C:\BlueJ\Projects

Example 7: Character codes program · 15 marks · Long answerHarder exam level

Write a program that stores the character 'G' and prints, using \t for columns: a heading Character, Code; the character and its code; its lowercase form and code (obtained by adding 32 and casting); the next letter; the average of the codes of 'A' and 'B' as a decimal; and the whole part of that average using a cast.

Try it first, then show the solutionSolution
  1. class CodeConvert
    {
    public static void main(String args[])
    {
    char up = 'G';
    int code = up; // implicit: char to int
    char low = (char) (up + 32); // explicit: int to char
    char next = (char) (code + 1);
  2. double avg = (double) ('A' + 'B') / 2;
    int whole = (int) avg;
  3. System.out.println("Character\tCode");
    System.out.println(up + "\t\t" + code);
    System.out.println(low + "\t\t" + (int) low);
    System.out.println("Next letter: " + next);
    System.out.println("Average code of A and B: " + avg);
    System.out.println("Whole part: " + whole);
    }
    }
  4. Trace: 'G' = 71; 71 + 32 = 103 = 'g'; 72 = 'H'; (65 + 66) = 131 cast to double 131.0 / 2 = 65.5; (int) 65.5 = 65.

Answer: Output (as run; gaps are tabs):
Character Code
G 71
g 103
Next letter: H
Average code of A and B: 65.5
Whole part: 65

Case-study practice (Section B style)

Read the situation, then answer every part. In a school exam set on the board pattern this is a 7-mark question split into 2 + 2 + 3 marks.

Debugging a marks program

Imagine Arjun writes:
int 1stTest = 18;
int second test = 17;
final int MAX = 20;
MAX = 25;
double avg = (18 + 17) / 2;
System.out.println("Average is " + avg);

  1. (i) · 2 marks

    Identify the errors in the first two declarations and correct them.

    Answer

    Answer: 1stTest begins with a digit; second test contains a space. Correct: int firstTest = 18; int secondTest = 17;

    1 mark each.

  2. (ii) · 2 marks

    Why does MAX = 25; give an error?

    Answer

    Answer: MAX is declared final, so it is a constant; its value cannot be changed after it is assigned, and the compiler reports an error.

    1 mark final, 1 mark cannot change.

  3. (iii) · 3 marks

    After fixing the errors, the program prints 'Average is 17.0' instead of 17.5. Explain and correct the statement.

    Answer

    Answer: (18 + 17) / 2 is integer division: 35 / 2 = 17; only then is 17 converted to 17.0 for avg. Correct: double avg = (18 + 17) / 2.0; or double avg = (double) (18 + 17) / 2; which gives 17.5.

    1 mark integer division, 1 mark implicit conversion after division, 1 mark correction.

Where the marks are

How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.

Distinguish between implicit and explicit type conversion with an example each. (2 marks) (2 marks)

StepMarks
Implicit: automatic widening by Java, no data loss, e.g. double d = 7; gives 7.0.1
Explicit: cast written by the programmer, may lose data, e.g. (int) 7.9 gives 7.1

Program: character codes table with casting. (15 marks) (15 marks)

StepMarks
Class and main() correctly written.2
Variables declared with correct types (char, int, double).3
Implicit char-to-int and explicit (char) casts for lowercase and next letter.4
Average with (double) cast and whole part with (int) cast.3
Output with \t and correct labels.3

Where students lose marks in Identifiers and Literals

The slips examiners see most often, and what to write instead.

  • Mistake: Treating 'A' + 'B' as "AB"

    Thinking + always joins text.

    Wrong working

    System.out.println('A' + 'B'); prints AB

    Right working

    Two chars are added as numbers: 131. Only if a String is involved does + join.

    Do this: Check from left to right whether a String has appeared yet.

    Usually costs: 1 mark.

  • Mistake: Rounding when casting

    Everyday rounding habit.

    Wrong working

    (int) 7.9 = 8

    Right working

    (int) 7.9 = 7 (fraction dropped).

    Do this: Casting to int truncates towards zero.

    Usually costs: 1 mark.

  • Mistake: Wrong ASCII values

    Ranges not memorised.

    Do this: A 65, a 97, 0 48, space 32; count on from these.

    Usually costs: 1 mark per value.

  • Mistake: Integer division in averages

    Forgetting both operands are int.

    Wrong working

    double avg = (18 + 17) / 2; gives 17.0

    Right working

    double avg = (18 + 17) / 2.0; gives 17.5

    Do this: Make one operand double before dividing.

    Usually costs: 1 to 2 marks.

Practice questions on Identifiers and Literals

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQExam level

    The ASCII value of 'z' is:
    (a) 90
    (b) 122
    (c) 97
    (d) 126

    Hint

    a = 97.

    Answer

    (b) 122

  2. Q2 · 1 mark · MCQExam level

    Which of these is NOT a primitive data type?
    (a) char
    (b) boolean
    (c) String
    (d) long

    Hint

    It is a class.

    Answer

    (c) String

  3. Q3 · 1 mark · MCQHarder exam level

    Which of these is a valid identifier?
    (a) final
    (b) roll-no
    (c) _roll2
    (d) 2roll

    Hint

    Keyword, hyphen, digit first.

    Answer

    (c) _roll2

  4. Q4 · 2 marks · Very short answerHOTS / competency

    Give the output: System.out.println((byte) 130);

    Hint

    byte range −128 to 127.

    Answer

    -126 (130 is outside the byte range and wraps: 130 − 256 = −126).

  5. Q5 · 2 marks · Very short answerExam level

    State two differences between primitive and non-primitive data types.

    Hint

    Built-in; value vs reference.

    Answer

    (1) Primitive types are built into Java (int, char); non-primitive types are created from them (classes, arrays). (2) A primitive variable stores the value itself with a fixed size; a non-primitive variable stores a reference to an object.

  6. Q6 · 2 marks · Very short answerHarder exam level

    Why is Unicode essential in Java? Give two reasons.

    Hint

    Global use.

    Answer

    (1) It can represent characters of virtually every language, so programs can be localised for users worldwide. (2) It gives every character one standard code, so text is exchanged and handled consistently between computers.

  7. Q7 · 2 marks · Very short answerHarder exam level

    Give the output: char ch = 'M'; int code = ch + 0; System.out.println(code); final double RATE = 8.5; System.out.println(RATE * 2);

    Hint

    M = 65 + 12.

    Answer

    77
    17.0

  8. Q8 · 2 marks · Very short answerHarder exam level

    Write statements to (i) print the character whose ASCII code is 100, and (ii) print the ASCII code of '#' (do not work it out; let Java do it).

    Hint

    Cast both ways.

    Answer

    (i) System.out.println((char) 100); (prints d)
    (ii) System.out.println((int) '#');

  9. Q9 · 15 marks · Long answerHarder exam level

    Write a program that stores a lowercase letter 'k', converts it to uppercase using its code, and prints both letters with their ASCII codes, separated by tabs.

    Hint

    Subtract 32 and cast.

    Answer

    class ToUpper
    {
    public static void main(String args[])
    {
    char low = 'k';
    char up = (char) (low - 32);
    System.out.println(low + "\t" + (int) low);
    System.out.println(up + "\t" + (int) up);
    }
    }
    Output (as run; gaps are tabs):
    k 107
    K 75

  10. Q10 · 2 marks · Short answerHOTS / competency

    A student writes float price = 49.99; and gets a compile-time error. Explain why and give two ways to fix it.

    Hint

    Default type of decimal literals.

    Answer

    A decimal literal such as 49.99 is a double by default, and Java will not implicitly narrow double to float because data could be lost. Fix: float price = 49.99f; or float price = (float) 49.99; (or declare price as double).

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. 1.ASCII value of '0'?Show answer

    48

  2. 2.Escape sequence for a tab?Show answer

    \t

  3. 3.Size of double in bytes?Show answer

    8 bytes (64 bits).

  4. 4.Keyword used to declare a constant?Show answer

    final

  5. 5.Another name for explicit conversion?Show answer

    Type casting.

  6. 6.Can an identifier begin with an underscore?Show answer

    Yes (for example _total); it cannot begin with a digit.

Best order to study it

  1. Learn the character set and the four ASCII ranges; learn why Unicode matters.
  2. Learn the five escape sequences and practise println() outputs.
  3. Learn the five token types and the rules for identifiers.
  4. Learn variables, constants (final) and the eight primitive types with sizes.
  5. Practise implicit and explicit conversion outputs, including integer division and overflow.

Quick revision checklist

The night before the exam: can you do each of these without looking?

  • ASCII: A-Z 65-90, a-z 97-122, 0-9 48-57, space 32; Java char uses 16-bit Unicode.
  • Escapes: \n \t \\ \" \'.
  • Tokens: keywords, identifiers, literals, punctuators, operators.
  • Identifiers: letters, digits, underscore and dollar sign; no digit first, no space, no keyword; case sensitive.
  • byte 1, short 2, int 4, long 8, float 4, double 8, char 2 bytes; String is non-primitive.
  • Implicit: widening, automatic; explicit: (type) cast, may lose data; 5 / 2 = 2.

Identifiers and Literals: frequently asked questions

Are true, false and null keywords?

Strictly they are literals, not keywords, but like keywords they cannot be used as identifiers.

Do I need ASCII codes of symbols such as # or @?

No. The syllabus lists only A-Z, a-z, 0-9 and the white space. For other symbols, a question will give the code or ask Java to print it.

What is the size of boolean?

Java does not fix it; it stores only true or false. Textbooks often state 1 bit; if asked, say it holds one of two values and its size is not precisely defined by Java.

Based on: CISCE ICSE 2028 Computer Applications (86) syllabus (Classes IX and X); CISCE Regulations for ICSE Examination Year 2028