Back to Tutorials
TutorialsICSEClass 9Computer Applications

ICSE Class 9 Computer Applications Notes: Values, Data Types and Operators in Java

Easy-to-revise ICSE Class 9 Computer Applications notes on Java tokens, primitive data types, type conversion, and arithmetic, relational, logical, increment and ternary operators, with solved output questions and practice exercises.

Trushna Tejwani22 October 202614 min read
ICSE Class 9 Computer Applications Notes: Values, Data Types and Operators in Java

Values, Data Types and Operators is one of the highest-scoring chapters in the ICSE Class 9 Computer Applications syllabus. Almost every exam has output-based questions from it. These notes cover the full chapter in a revision-friendly format, with examples you can run in BlueJ.

1. Character Set and Tokens

Java uses the Unicode character set, so it can represent letters from almost every language. The smallest individual unit of a Java program is called a token. There are five types of tokens:

  • Keywords: reserved words with a special meaning, such as int, class, if, while and new. They cannot be used as names.
  • Identifiers: names given to variables, methods and classes, such as marks, total and Student.
  • Literals: constant values, such as 25, 3.14, 'A', "Hello" and true.
  • Operators: symbols that perform operations, such as +, >, && and =.
  • Separators (Punctuators): ; , ( ) { } [ ] .

Rules for Naming Identifiers

  1. An identifier can contain letters, digits, the underscore (_) and the dollar sign ($).
  2. It cannot start with a digit.
  3. It cannot be a keyword.
  4. It is case-sensitive, so Total and total are different.
  5. Spaces are not allowed.

2. Types of Literals

  • Integer literals: 45, -300, 0
  • Real (floating-point) literals: 3.14, -0.5, 2.0e3
  • Character literals: a single character in single quotes, such as 'A', '9' or '\n'
  • String literals: characters in double quotes, such as "ICSE" or "2027"
  • Boolean literals: true and false
  • Null literal: null

3. Primitive Data Types

Bar chart of Java primitive data type sizes in bytes

Java has 8 primitive data types. Learn the sizes and default values. They are asked about very often.

Data Type   Size      Default   Range / Example
---------   -------   -------   ---------------------------
byte        1 byte    0         -128 to 127
short       2 bytes   0         -32768 to 32767
int         4 bytes   0         about ±2.1 billion
long        8 bytes   0L        very large integers
float       4 bytes   0.0f      3.14f
double      8 bytes   0.0d      3.14159265
char        2 bytes   '\u0000'  'A' (Unicode)
boolean     1 bit*    false     true / false

*The exact storage of a boolean depends on the JVM. Most ICSE textbooks state it as 1 bit or 1 byte, so follow your textbook.

Non-primitive (reference) data types include classes, arrays and interfaces. String is a class, so it is a non-primitive type.

4. Variables and Declaration

A variable is a named memory location whose value can change while the program runs.

int age = 14;          // declaration + initialisation
double price;          // declaration only
price = 99.50;         // assignment
char grade = 'A';
boolean passed = true;
final double PI = 3.14159;   // constant: cannot be changed

5. Type Conversion

Java widening and narrowing type conversion order

Implicit Conversion (Widening / Coercion)

Java does this automatically when a smaller type is converted to a larger type, so no data is lost.

byte → short → int → long → float → double

int a = 10;
double d = a;        // d becomes 10.0
char ch = 'A';
int code = ch;       // code becomes 65

Explicit Conversion (Narrowing / Type Casting)

The programmer forces a larger type into a smaller one. Data may be lost.

double x = 9.87;
int y = (int) x;     // y becomes 9 (the decimal part is dropped)
int n = 66;
char c = (char) n;   // c becomes 'B'

6. Operators in Java

Arithmetic Operators

+, -, *, / and % (modulus gives the remainder).

System.out.println(17 / 5);     // 3   (integer division)
System.out.println(17 % 5);     // 2
System.out.println(17.0 / 5);   // 3.4
System.out.println(-17 % 5);    // -2  (the sign follows the dividend)

Relational Operators

<, >, <=, >=, == and !=. They always return a boolean value.

Logical Operators

  • && (AND): true only if both conditions are true
  • || (OR): true if at least one condition is true
  • ! (NOT): reverses the result
int m = 75;
System.out.println(m > 50 && m < 90);   // true
System.out.println(m < 50 || m == 75);  // true
System.out.println(!(m > 50));          // false

Assignment and Shorthand Operators

=, +=, -=, *=, /= and %=. For example, a += 5 means a = a + 5.

Increment and Decrement Operators

  • Prefix (++a): change first, then use the value.
  • Postfix (a++): use the value first, then change it.
int a = 5, b;
b = a++;   // b = 5, a = 6
b = ++a;   // a = 7, b = 7

Ternary (Conditional) Operator

condition ? value1 : value2

int a = 12, b = 20;
int max = (a > b) ? a : b;   // max = 20
String result = (a % 2 == 0) ? "Even" : "Odd";   // "Even"

7. Operator Precedence (Highest to Lowest)

  1. () brackets
  2. ++ -- (postfix), then ++ -- ! (prefix and unary)
  3. * / %
  4. + -
  5. < > <= >=
  6. == !=
  7. &&
  8. ||
  9. ?: (ternary)
  10. = += -= and the other assignment operators

8. Solved Output Questions

Q1. int x = 4; x = x++ + ++x * 2; System.out.println(x);

Answer: x++ gives 4 (x becomes 5), then ++x gives 6. So x = 4 + 6 × 2 = 16.

Q2. System.out.println(10 + 20 + "ICSE" + 10 + 20);

Answer: 30ICSE1020. The two numbers before the string are added first. Once the expression becomes a String, the remaining + signs join text.

Q3. char ch = 'a'; System.out.println((char)(ch - 32));

Answer: A. 'a' is 97, and 97 − 32 = 65, which is 'A'.

Q4. int p = 7, q = 2; double r = p / q; System.out.println(r);

Answer: 3.0. p / q is integer division and gives 3, which is then widened to 3.0.

Q5. boolean f = (5 > 3) && (2 > 4) || !(1 == 1); System.out.println(f);

Answer: false. This is (true && false) || false, which is false || false.

9. Practice Questions

  1. Name the primitive data type that uses 8 bytes to store a decimal value.
  2. Give the output: System.out.println(25 % 7 + 25 / 7);
  3. Which is valid: int 1num;, int num_1; or int num-1;?
  4. Write a Java expression for: a² + 2ab + b²
  5. What is the value of y? int a = 3; int y = a++ * 2 + --a;
  6. Distinguish between implicit and explicit type conversion, with one example of each.

Answers: 1. double 2. 4 + 3 = 7 3. int num_1; 4. a * a + 2 * a * b + b * b 5. a++ gives 3 (a becomes 4), --a gives 3, so y = 3 × 2 + 3 = 9 6. See section 5 above.

Revision tip: type every example from this page into BlueJ and predict the output before you run it. This builds the speed you need in the exam.

Next, continue with Input in Java (Scanner class) and Conditional Constructs in our ICSE Class 9 tutorials.