Variables and Expressions in Java: ISC Class 11 Notes
Updated 15 October 2026 · Fact-checked
A variable is a named storage location for a value of a given type, and an expression combines variables, constants and operators to produce a value. ISC Class 11 Computer Science covers final named constants, arithmetic and logical expressions, operator precedence and associativity, assignment and its two sides, and variables that hold references to objects.
What Variables and Expressions is about
Programs compute with expressions: formulas built from variables, constants and operators. To predict what Java will compute, you must know the types involved, the order in which operators apply, and exactly what an assignment does.
The CISCE 2028 syllabus (Section B, topic 7) asks for: variables as names for values; named constants (final); expressions (arithmetic and logical) and their evaluation (operators, associativity, precedence); the assignment operation and the difference between the left-hand side and right-hand side of an assignment; variables have types; and variables denoting objects are references to those objects. Library functions for solving expressions may be used as required.
Three programs on this page (compiled and run) demonstrate operator precedence and increment operators, reference variables, and Math library functions in a quadratic-equation solver.
Weightage: Variables and Expressions is topic 7 of the ISC Class XI Computer Science syllabus, in Section B - Java. CISCE weights Section B at 30 of the 70 marks in Paper I (Theory). Class XI is examined by the school, so your school sets the paper within this weightage.Source: CISCE ISC Computer Science syllabus, examination year 2028, Class XI unit weightage
Key concepts
- Variables, types and named constants
A variable is a name for a memory location that holds a value of a particular type. The value can change while the program runs.
Declaration: type name; (int marks;). Initialisation: giving the first value (int marks = 87;). Java is strongly typed: a variable can hold only values compatible with its declared type, checked by the compiler.
Kinds of variables (by where they are declared): instance variables (data members of an object), class (static) variables (shared by all objects), local variables (inside methods; must be initialised before use) and parameters.
Named constants: declared with final; their value cannot change after it is assigned: final double PI = 3.14159; final int MAX_STUDENTS = 40;. Constants are written in CAPITALS by convention. Benefits: readability (GST_RATE instead of 0.18), safety (accidental change is a compile-time error) and easy maintenance (change the value in one place).
Worked example
What happens if a program contains final int LIMIT = 50; and later LIMIT = 60;? [1 mark]
Try it first, then show the solutionSolution
- A final variable cannot be reassigned; the compiler rejects the second assignment.
Answer: A compile-time error: cannot assign a value to final variable LIMIT.
- Arithmetic expressions and operators
Arithmetic operators: + (addition), − (subtraction), * (multiplication), / (division), % (remainder or modulus).
- Integer division drops the fraction: 17 / 5 = 3.
- % gives the remainder: 17 % 5 = 2; its sign follows the left operand: −17 % 5 = −2.
- + also joins strings: 3 + 4 + "Java" = "7Java" (left to right: 3 + 4 first), but "Java" + 3 + 4 = "Java34".
Unary operators: unary minus (−x), increment ++ and decrement −−.
- Prefix (++a): change first, then use the new value.
- Postfix (a++): use the current value, then change.
Compound assignment: +=, −=, *=, /=, %= (x += y means x = x + y, with an automatic cast to x's type).
Writing formulas as Java expressions: simple interest = p * r * t / 100; area of triangle = 0.5 * b * h; average of three = (a + b + c) / 3.0 (use 3.0 for a decimal result); distance = Math.sqrt(x * x + y * y).
Worked example
If x = 5, find x and y after int y = x++ * 2 + --x;. [2 marks]
Try it first, then show the solutionSolution
- x++ gives 5 (x becomes 6); 5 × 2 = 10.
- --x makes x 5 and gives 5; y = 10 + 5 = 15.
Answer: x = 5, y = 15.
- Relational and logical expressions
Relational operators compare values and give a boolean: < , <= , > , >= , == (equal to), != (not equal to).
Logical operators combine boolean values:
Operator Meaning True when && AND both operands are true \ \ OR at least one is true ! NOT the operand is false Short-circuit evaluation: && does not evaluate its right operand if the left is false; || does not evaluate its right operand if the left is true. This prevents errors such as division by zero: (z != 0) && (10 / z > 1) is safe when z is 0.
Common logical expressions: even number: n % 2 == 0; leap year: (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; within range 10 to 20: n >= 10 && n <= 20; vowel test: ch == 'a' || ch == 'e' || ...
= vs ==: = assigns; == compares. if (a = 5) does not compile in Java for an int a, which helps catch the mistake.
Worked example
Evaluate !(4 > 2 || 1 > 5) && true. [1 mark]
Try it first, then show the solutionSolution
- 4 > 2 is true, so the OR is true; ! gives false; false && true = false.
Answer: false.
- Precedence and associativity
Precedence decides which operator applies first; associativity decides the order among operators of the same precedence.
Level (high to low) Operators Associativity 1 postfix a++ a−− left to right 2 prefix ++a −−a, unary − +, !, (type) cast right to left 3 * / % left to right 4 + − left to right 5 < <= > >= left to right 6 == != left to right 7 && left to right 8 \ \ left to right 9 ?: (ternary) right to left 10 = += −= *= /= %= right to left Brackets override precedence. Use them to make intent clear.
The program below evaluates several expressions; note the left-to-right associativity of − and /, and the effect of prefix and postfix increment.
// Precedence, associativity, increment operators and short-circuit evaluation. public class Operators { public static void main(String[] args) { System.out.println("2 + 3 * 4 = " + (2 + 3 * 4)); // * before + System.out.println("(2 + 3) * 4 = " + ((2 + 3) * 4)); System.out.println("20 - 6 - 4 = " + (20 - 6 - 4)); // left to right System.out.println("100 / 10 / 5 = " + (100 / 10 / 5)); System.out.println("17 % 5 * 2 = " + (17 % 5 * 2)); System.out.println("-17 % 5 = " + (-17 % 5)); // sign follows the left operand int a = 5; int b = a++ + ++a; // 5 (then a = 6) + 7 (a becomes 7 first) System.out.println("a = " + a + ", b = " + b); int x = 10, y = 3; x += y; // x = 13 x *= 2; // x = 26 x %= 7; // x = 5 System.out.println("x = " + x); int p = 4; int q = p--; // q gets 4, then p becomes 3 System.out.println("p = " + p + ", q = " + q); int z = 0; boolean safe = (z != 0) && (10 / z > 1); // second part never runs: no division by zero System.out.println("safe = " + safe); int i = 2, j = 9; System.out.println(i < j && j % i == 1 || !(i == 2)); int k = 1; k = k++ + k; // 1 + 2 System.out.println("k = " + k); } }Output:
2 + 3 * 4 = 14 (2 + 3) * 4 = 20 20 - 6 - 4 = 10 100 / 10 / 5 = 2 17 % 5 * 2 = 4 -17 % 5 = -2 a = 7, b = 12 x = 5 p = 3, q = 4 safe = false true k = 3In b = a++ + ++a with a = 5: a++ gives 5 (a becomes 6), then ++a makes a 7 and gives 7, so b = 12.
Worked example
Evaluate 8 / 3 * 3 + 8 % 3 and 20 − 6 − 4. [2 marks]
Try it first, then show the solutionSolution
- 8 / 3 = 2 (int); 2 × 3 = 6; 8 % 3 = 2; 6 + 2 = 8.
- Left to right: (20 − 6) − 4 = 10, not 20 − (6 − 4) = 18.
Answer: 8 and 10.
- Assignment: left-hand side and right-hand side
The assignment variable = expression; works in two steps:
1. The right-hand side (RHS) is evaluated to a value (an r-value).
2. The value is stored in the location named by the left-hand side (LHS), which must be a variable (an l-value), not a constant or an expression.So x = x + 1; is meaningful: the RHS uses the old value of x; the LHS names the location to update. 5 = x; and a + b = c; are errors because the LHS is not a storage location.
Type compatibility: the RHS type must be assignable to the LHS type (widening is automatic; narrowing needs a cast).
Chained assignment is right-associative: a = b = c = 0; sets c, then b, then a.
Swapping two values needs a temporary variable (or arithmetic): t = p; p = q; q = t;.
Worked example
After int p = 6, q = 4; p = p + q; q = p − q; p = p − q;, what are p and q? [2 marks]
Try it first, then show the solutionSolution
- p = 10; q = 10 − 4 = 6; p = 10 − 6 = 4.
- The values have been swapped without a temporary variable.
Answer: p = 4, q = 6.
- Variables denoting objects are references; library functions
A variable of a class type holds a reference to an object, not the object itself.
- int n = m; copies the value; changing n does not change m.
- References r2 = r1; copies the reference: r1 and r2 now name the same object (aliasing); a change through r2 is seen through r1.
- r1 == r2 compares references (same object?), not contents.
// Variables that denote objects hold references: two variables can refer to the same object. public class References { int count; References(int c) { count = c; } public static void main(String[] args) { int m = 10; int n = m; // copies the value n = n + 5; System.out.println("m = " + m + ", n = " + n); References r1 = new References(10); References r2 = r1; // copies the reference: both name the SAME object r2.count = r2.count + 5; System.out.println("r1.count = " + r1.count + ", r2.count = " + r2.count); System.out.println("r1 == r2 ? " + (r1 == r2)); References r3 = new References(15); System.out.println("r1 == r3 ? " + (r1 == r3) + " (same value, different objects)"); final double GST_RATE = 0.18; // named constant: cannot be reassigned double price = 500; System.out.println("price with GST = " + (price + price * GST_RATE)); } }Output:
m = 10, n = 15 r1.count = 15, r2.count = 15 r1 == r2 ? true r1 == r3 ? false (same value, different objects) price with GST = 590.0Library functions (java.lang.Math, no import needed): Math.sqrt(x), Math.pow(a, b), Math.abs(x), Math.max(a, b), Math.min(a, b), Math.round(x), Math.ceil(x), Math.floor(x), Math.cbrt(x), Math.random(), Math.PI. They make formulas short and accurate.
// Library functions in expressions: roots of ax^2 + bx + c = 0 using Math.sqrt, // and a few other Math methods. public class Quadratic { static void roots(double a, double b, double c) { double d = b * b - 4 * a * c; // discriminant if (d >= 0) { double r1 = (-b + Math.sqrt(d)) / (2 * a); double r2 = (-b - Math.sqrt(d)) / (2 * a); System.out.println("a=" + a + " b=" + b + " c=" + c + ": roots " + r1 + " and " + r2); } else System.out.println("a=" + a + " b=" + b + " c=" + c + ": no real roots (d = " + d + ")"); } public static void main(String[] args) { roots(1, -5, 6); roots(2, 4, -6); roots(1, 2, 5); System.out.println("Math.pow(2, 10) = " + Math.pow(2, 10)); System.out.println("Math.abs(-7.5) = " + Math.abs(-7.5)); System.out.println("Math.max(12, 19) = " + Math.max(12, 19)); System.out.println("Math.ceil(4.1) = " + Math.ceil(4.1) + ", Math.floor(4.9) = " + Math.floor(4.9)); System.out.println("Math.round(-2.5) = " + Math.round(-2.5)); double r = 7; System.out.println("area of circle r=7: " + Math.round(Math.PI * r * r * 100) / 100.0); } }Output:
a=1.0 b=-5.0 c=6.0: roots 3.0 and 2.0 a=2.0 b=4.0 c=-6.0: roots 1.0 and -3.0 a=1.0 b=2.0 c=5.0: no real roots (d = -16.0) Math.pow(2, 10) = 1024.0 Math.abs(-7.5) = 7.5 Math.max(12, 19) = 19 Math.ceil(4.1) = 5.0, Math.floor(4.9) = 4.0 Math.round(-2.5) = -2 area of circle r=7: 153.94Worked example
Write a Java expression for the hypotenuse of a right triangle with sides a and b, and evaluate it for a = 3, b = 4. [1 mark]
Try it first, then show the solutionSolution
- Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)) = √25 = 5.0.
Answer: Math.sqrt(a * a + b * b) (or with Math.pow) gives 5.0.
Variables and Expressions 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.
Named constants
Suppose a shop's billing program uses the number 0.18 for GST in 40 places, and the rate changes.
Why would final double GST_RATE = 0.18; have helped?
Try it first, then show the solutionSolution
- All 40 places would refer to GST_RATE, so only one line changes.
- final also stops anyone from changing the rate accidentally in the middle of the program.
Answer: One change in one place, clearer code, and protection against accidental modification.
Memory hook: Name the number once, use it everywhere.
Aliasing
Imagine you and your sister share one online shopping cart (one account) on two phones. You add a book; she sees it in her cart too.
How is this like two reference variables in Java?
Try it first, then show the solutionSolution
- Both phones show the same cart object, not two copies.
- Like r2 = r1, a change through one reference is visible through the other.
Answer: Two references to one object: changes through either are seen by both.
Memory hook: Two names, one object.
Short-circuit safety
Suppose a program computes average marks per student as total / count, but a new class has count = 0.
How can a condition avoid a crash?
Try it first, then show the solutionSolution
- Check count != 0 first: if (count != 0 && total / count > 50).
- If count is 0, && stops at once and the division is never done.
Answer: Put the safety test first in an && expression: short-circuiting skips the division.
Memory hook: Guard first, divide later.
Topics in this chapter
Variables and Expressions: syntax and key facts
- Integer division and remainder
- a = (a / b) * b + a % b (for ints)
- 17 = 3 × 5 + 2.
- Increment
- Prefix ++a: change then use; postfix a++: use then change
- Compound assignment
- x op= y means x = (type of x) (x op y)
- Common Java formulas
- SI = p * r * t / 100; average = (a + b + c) / 3.0; root = (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a)
- Precedence (short)
- postfix > prefix, unary, ! > * / % > + - > relational > == != > && > || > ?: > assignment
Variables and Expressions: diagrams to practise
Practise each one on paper: draw it from the checklist, then tick off every label.
Expression tree
Show the order of evaluation of an expression.
Draw
- For 2 + 3 * 4 - 6 / 2: root '−'; its left child '+' (children 2 and '*' with children 3, 4); its right child '/' (children 6, 2).
- Evaluate from the leaves up: 3 * 4 = 12; 2 + 12 = 14; 6 / 2 = 3; 14 − 3 = 11.
Label
- operators as nodes
- operands as leaves
- bottom-up evaluation
Watch out: Higher-precedence operators sit lower in the tree, so they are evaluated first.
Value vs reference copy
Explain that object variables are references.
Draw
- Left: boxes m = 10 and n = 10 (separate copies); after n = n + 5, n = 15, m still 10.
- Right: boxes r1 and r2 both with arrows to one object box 'count = 10'; after r2.count += 5, the single box shows 15.
Label
- value copy
- reference copy
- same object
Watch out: One object box with two arrows is the key picture for aliasing.
How the school exam asks Variables and Expressions
The question patterns to expect, and the method that works for each.
| Question type | How it is asked | Method |
|---|---|---|
| Output and evaluation (1-2 marks) | Evaluate expressions with mixed operators, increments, integer division, string joining. | Apply precedence and associativity step by step; write intermediate values. |
| Writing expressions (2-5 marks) | Convert mathematical formulas into Java expressions using Math functions; write logical conditions. | Use brackets generously; use 2.0 or a cast where a decimal result is needed. |
| Programs (5-10 marks) | Compute results from formulas (roots, interest, conversions) with constants and library methods. | Declare constants with final; check special cases (negative discriminant, zero divisor). |
Tricks to remember Variables and Expressions
Short memory aids. Say each one aloud once, then use it on a question the same day.
Please My Dear Aunt Sally... in Java: U-M-A-R-E-L-A
Unary, Multiplicative, Additive, Relational, Equality, Logical (&& then ||), Assignment.
Use it when: Precedence order.
Pre-change, post-use
++a changes before use; a++ uses before change.
Use it when: Increment operators.
RHS first, LHS last
Compute the right side completely, then store it on the left.
Use it when: Assignment.
Strings are sticky
Once a String appears in a + chain (left to right), everything after it is joined as text.
Use it when: String concatenation.
Variables and Expressions: exam-level solved questions
Ordered from exam level to HOTS. Cover the solution, write your own, then compare step by step.
Example 1: Modulus · 1 mark · MCQExam level
The value of 17 % 5 * 2 is:
(a) 1
(b) 4
(c) 2
(d) 7
Try it first, then show the solutionSolution
- % and * have equal precedence, left to right: 17 % 5 = 2; 2 × 2 = 4.
Answer: (b) 4.
Example 2: Short circuit · 1 mark · Assertion-reasonHarder exam level
Assertion: The expression (z != 0) && (10 / z > 1) does not throw an exception when z is 0.
Reason: The && operator does not evaluate its right operand when its left operand is false.
(a) Both Assertion and Reason are true and Reason is the correct explanation of Assertion.
(b) Both Assertion and Reason are true but Reason is not the correct explanation of Assertion.
(c) Assertion is true but Reason is false.
(d) Both Assertion and Reason are false.
Try it first, then show the solutionSolution
- z != 0 is false, so 10 / z is never evaluated (the program printed safe = false): the Reason explains the Assertion.
Answer: (a)
Example 3: String joining · 2 marks · Short answerExam level
Give the output of System.out.println(3 + 4 + "Java" + 3 + 4); and explain.
Try it first, then show the solutionSolution
- Left to right: 3 + 4 = 7 (both ints); 7 + "Java" = "7Java".
- "7Java" + 3 = "7Java3"; + 4 = "7Java34".
Answer: 7Java34.
Example 4: Increments in one expression · 5 marks · Short answerHarder exam level
Find the final values: (i) int a = 5; int b = a++ + ++a; (ii) int k = 1; k = k++ + k; (iii) int s = 4; s = s++ + s++;
Try it first, then show the solutionSolution
- (i) a++ → 5 (a = 6); ++a → 7 (a = 7); b = 12, a = 7.
- (ii) k++ → 1 (k = 2); + k → 2; sum 3 assigned to k: k = 3.
- (iii) s++ → 4 (s = 5); s++ → 5 (s = 6); sum 9 assigned to s: s = 9 (the increments are overwritten by the assignment).
- Compiled checks printed a = 7, b = 12; k = 3; 9.
Answer: (i) a = 7, b = 12; (ii) k = 3; (iii) s = 9.
Example 5: Formulas as Java expressions · 5 marks · Short answerHOTS / competency
Write Java expressions for (i) simple interest for principal p, rate r % and time t; (ii) the area of a triangle with sides a, b, c (Heron's formula); (iii) the number of 40-seat buses needed for n students. Evaluate (i) for p = 25,000, r = 8.5, t = 3 and (iii) for n = 127.
Try it first, then show the solutionSolution
- (i) p * r * t / 100 → 25000 × 8.5 × 3 / 100 = 6375.0.
- (ii) s = (a + b + c) / 2.0; area = Math.sqrt(s * (s - a) * (s - b) * (s - c)).
- (iii) (int) Math.ceil(n / 40.0) (40.0 avoids integer division).
- For n = 127: 127 / 40.0 = 3.175 → ceil 4.0 → 4 buses.
- Compiled check printed 6375.0 and 4.
Answer: (i) p * r * t / 100 = 6375.0; (ii) Math.sqrt(s * (s − a) * (s − b) * (s − c)) with s = (a + b + c) / 2.0; (iii) (int) Math.ceil(n / 40.0) = 4.
Example 6: Quadratic roots program · 10 marks · Long answerHOTS / competency
Write a method void roots(double a, double b, double c) that prints the real roots of ax² + bx + c = 0, or a message when there are none, using library functions. Show the output for (1, −5, 6), (2, 4, −6) and (1, 2, 5).
Try it first, then show the solutionSolution
- d = b * b − 4 * a * c (discriminant).
- If d ≥ 0: r1 = (−b + Math.sqrt(d)) / (2 * a); r2 = (−b − Math.sqrt(d)) / (2 * a); print both.
- Brackets around (2 * a) are essential; without them the division happens before the multiplication.
- Else print 'no real roots' with the value of d.
- Output (compiled Quadratic program): roots 3.0 and 2.0; roots 1.0 and −3.0; no real roots (d = −16.0).
Answer: See the compiled Quadratic program in the references-and-library section: (1, −5, 6) → 3.0 and 2.0; (2, 4, −6) → 1.0 and −3.0; (1, 2, 5) → no real roots (d = −16.0).
Case-study practice (Section D style)
Read the situation, then answer every part. In a school exam set on the board pattern this is a 5-mark question split into 2 + 1 + 2 marks.
Electricity bill calculator
Suppose a student writes a bill calculator: the first 100 units cost ₹4.50 each and units above 100 cost ₹6.00 each, plus a fixed charge of ₹80. The code is: final double RATE1 = 4.50, RATE2 = 6.00; final int FIXED = 80; int units = 160; double bill = FIXED + Math.min(units, 100) * RATE1 + Math.max(units - 100, 0) * RATE2;
(i) · 2 marks
Evaluate bill for 160 units, showing the order of operations.
Answer
Answer: Math.min(160, 100) = 100 → 100 × 4.50 = 450.0; Math.max(60, 0) = 60 → 60 × 6.00 = 360.0; bill = 80 + 450.0 + 360.0 = 890.0.
1 mark products, 1 mark total.
(ii) · 1 mark
Why are RATE1, RATE2 and FIXED declared final?
Answer
Answer: They are named constants: they cannot be changed accidentally, make the formula readable, and can be updated in one place if tariffs change.
1 mark.
(iii) · 2 marks
What is the bill for 75 units?
Answer
Answer: Math.min(75, 100) = 75 → 337.5; Math.max(−25, 0) = 0 → 0; bill = 80 + 337.5 = 417.5.
2 marks.
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.
String joining output (2 marks) (2 marks)
| Step | Marks |
|---|---|
| 3 + 4 evaluated as numbers first | 1 |
| Remaining operands joined as text | 1 |
Formulas as Java expressions (5 marks) (5 marks)
| Step | Marks |
|---|---|
| Simple interest expression and value | 1 |
| Heron's formula with s using 2.0 | 2 |
| Bus expression with ceil and 40.0 | 1 |
| Value for n = 127 | 1 |
Quadratic roots method (10 marks) (10 marks)
| Step | Marks |
|---|---|
| Discriminant expression | 2 |
| Both roots with correct brackets and Math.sqrt | 3 |
| No-real-roots branch | 2 |
| Calls and correct output for three cases | 3 |
Where students lose marks in Variables and Expressions
The slips examiners see most often, and what to write instead.
Mistake: Writing -b + Math.sqrt(d) / 2 * a
Without brackets, / and * apply before +, and / 2 * a multiplies by a instead of dividing.
Do this: (-b + Math.sqrt(d)) / (2 * a).
Usually costs: 1-2 marks.
Mistake: Using = for comparison
= assigns; == compares.
Do this: In conditions, use == (or equals for Strings).
Usually costs: 1 mark.
Mistake: Forgetting integer division in averages
(a + b + c) / 3 drops the fraction when all are ints.
Do this: Divide by 3.0.
Usually costs: 1 mark.
Mistake: Thinking r2 = r1 copies the object
It copies only the reference; both refer to one object.
Do this: Create a new object if a separate copy is needed.
Usually costs: 1 mark.
Practice questions on Variables and Expressions
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 · MCQExam level
Which operator has the highest precedence?
(a) &&
(b) *
(c) ==
(d) =Hint
Multiplicative beats relational and logical.
Answer
(b) *.
Q2 · 1 mark · Very short answerExam level
What is a named constant in Java?
Hint
final.
Answer
A variable declared with final, whose value cannot be changed once assigned (for example final double PI = 3.14159;).
Q3 · 2 marks · Short answerExam level
Evaluate: (i) int a = 8, b = 3; a / b * b + a % b; (ii) char c = 'A'; c += 5; (iii) double d = 15 / 4 + 15 % 4 / 2.0;
Hint
Integer division where both are ints.
Answer
(i) 8; (ii) c = 'F'; (iii) 3 + 3 / 2.0 = 3 + 1.5 = 4.5.
Q4 · 2 marks · Short answerHarder exam level
Explain the difference between the LHS and RHS of an assignment with x = x * 2 + 1;.
Hint
Value vs location.
Answer
The RHS is an expression evaluated using the current value of x (if x is 4, x * 2 + 1 = 9). The LHS must be a variable (an l-value) naming the location where the result is stored, so x becomes 9. The same name means 'value' on the right and 'location' on the left.
Q5 · 2 marks · Short answerHarder exam level
Write a Java expression to check that a character ch is a vowel (lower case), and one to check that year y is a leap year.
Hint
|| chains; leap rule.
Answer
ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'; (y % 4 == 0 && y % 100 != 0) || y % 400 == 0.
Q6 · 2 marks · Short answerHarder exam level
Give the output: int m = 10; m -= 3 * 2; System.out.println(m); System.out.println(Math.cbrt(27) + " " + Math.min(-3, -7));
Hint
Compound assignment evaluates the RHS first.
Answer
4 (m = 10 − 6), then '3.0 -7'.
Q7 · 5 marks · Short answerHOTS / competency
Suppose class Box has a field int w. After Box b1 = new Box(); b1.w = 5; Box b2 = b1; b2.w = 9; Box b3 = new Box(); b3.w = 9;, what are b1.w, b1 == b2 and b2 == b3? Explain.
Hint
References.
Answer
b1.w = 9, because b2 refers to the same object as b1 and changed it. b1 == b2 is true (same object). b2 == b3 is false: b3 is a different object, even though its w is also 9; == compares references, not contents.
Q8 · 2 marks · Short answerHOTS / competency
Write a program segment to convert a temperature t in Fahrenheit to Celsius rounded to one decimal place, and give the result for t = 100.
Hint
(F − 32) × 5 / 9.
Answer
double c = (t - 32) * 5 / 9.0; c = Math.round(c * 10) / 10.0; For t = 100: (68 × 5) / 9 = 37.777... → 37.8.
Q9 · 5 marks · Short answerHOTS / competency
Rewrite with brackets to show the order of evaluation and find the value: 2 + 3 * 4 - 6 / 2 % 4 + 7.
Hint
*, /, % left to right before + and −.
Answer
((2 + (3 * 4)) − ((6 / 2) % 4)) + 7 = (2 + 12) − (3 % 4) + 7 = 14 − 3 + 7 = 18.
Q10 · 10 marks · Long answerHOTS / competency
Write a class Interest with final double RATE = 8.5; a method double compound(double p, int years) using Math.pow, and main() printing the compound amount for p = 50,000 over 3 years (rounded to two decimals).
Hint
A = p(1 + r/100)ⁿ.
Answer
class Interest { static final double RATE = 8.5; static double compound(double p, int years) { return p * Math.pow(1 + RATE / 100, years); } public static void main(String[] args) { double a = compound(50000, 3); System.out.println(Math.round(a * 100) / 100.0); } } A = 50,000 × 1.085³ = 50,000 × 1.277289125 = 63,864.46.
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.Keyword for a named constant?Show answer
final.
2.17 % 5?Show answer
2.
3.Prefix vs postfix ++?Show answer
Prefix changes then uses; postfix uses then changes.
4.Associativity of = ?Show answer
Right to left.
5.What does r2 = r1 copy for objects?Show answer
The reference, not the object.
6.Does && always evaluate both sides?Show answer
No; it stops if the left side is false.
Best order to study it
- Variables, types, declaration and initialisation.
- Named constants with final.
- Arithmetic operators, increments, compound assignment.
- Relational and logical operators; short-circuiting.
- Precedence and associativity; LHS vs RHS.
- References and library (Math) functions.
Quick revision checklist
The night before the exam: can you do each of these without looking?
- Variable = named typed storage; final = constant.
- / with ints truncates; % gives the remainder (sign of left operand).
- ++a: change then use; a++: use then change.
- &&, || short-circuit; = assigns, == compares.
- Precedence: unary > * / % > + − > relational > equality > && > || > ?: > assignment.
- Object variables are references; Math.sqrt, pow, abs, max, min, round, ceil, floor.
Variables and Expressions: frequently asked questions
Why does 3 + 4 + "Java" give "7Java" but "Java" + 3 + 4 give "Java34"?
+ is evaluated left to right. In the first, 3 + 4 is numeric addition before the String appears; in the second, "Java" + 3 already produces a String, so 4 is joined as text.
Is it good style to write k = k++ + k?
No. It is legal and has a defined result in Java (3 when k starts at 1), but such expressions are confusing. They are useful practice for tracing precedence and increment rules; in real programs, write one change per statement.
Do I need to import java.lang.Math?
No. Classes in java.lang, such as Math, String and the wrapper classes, are available automatically.
Based on: CISCE ISC 2028 Computer Science syllabus (Classes XI and XII); CISCE Regulations for the ISC Examination Year 2028 (Class XI internal examination)