Agar Java ek bhasha hai, toh operators uske verbs hain — the words that actually do things. Every ICSE Computer Applications paper leans on them: Section A ke output-prediction questions se lekar Section B ke programs tak, operators har jagah hain. Good news? There are only a handful of them, and once you know three-four golden rules, the trickiest questions become free marks. Chaliye, aaram se, ek-ek karke.
Arithmetic Operators
Paanch operators: + (add), - (subtract), * (multiply), / (divide), % (modulus — remainder). Chaar toh school-maths hain; asli kahani / aur % mein hai.
/ throws away the decimal part (no rounding — truncation). If EITHER side is a double, you get a decimal answer.System.out.println(7 / 2); System.out.println(7.0 / 2);
Output:
3 3.5
7/2 mein dono int hain → 3.5 nahi, sirf 3 (decimal cut). 7.0 ne poore expression ko double bana diya → 3.5.
System.out.println(7 % 2); System.out.println(-7 % 2); System.out.println(7 % -2);
Output:
1 -1 1
Yaad rakhne ka easy tareeka: result ka sign LEFT operand ka sign hota hai. −7%2 → −1, par 7%−2 → 1.
19/4 = 4.75 in an output question. Dono operands int hain, isliye answer 4 hai. Yeh ICSE ka sabse favourite trap hai — har saal aata hai.Assignment & Shorthand Operators
= assignment hai (comparison nahi!). Shorthand forms kaam chhota kar deti hain: a += 5 ka matlab a = a + 5. Same for -=, *=, /=, %=.
int a = 8; a *= 2 + 3; System.out.println(a);
Output:
40
Dhyan se: a *= 2+3 means a = a * (2+3) = 8×5 = 40, not 8×2+3 = 19. Shorthand operator poore right side par lagta hai — jaise ek invisible bracket ho.
b += 5 on a byte) automatically type-cast bhi karte hain — b = b + 5 byte ke liye error deta par b += 5 chal jaata hai. 1-mark theory question ke liye ready raho.Increment and Decrement (++ / −−)
Yeh unary operators variable ko 1 se badhate/ghatate hain. Asli khel PRE vs POST ka hai:
++x(pre): pehle badhao, phir value use karox++(post): pehle value use karo, phir badhao
int x = 5; int y = x++ + ++x; System.out.println(x + " " + y);
Output:
7 12
Step-by-step: x++ deta hai 5 (phir x=6). ++x pehle x=7 karta hai, deta hai 7. So y = 5+7 = 12, x = 7.
int a = 2; int r = a++ * 3 + --a; System.out.println(a + " " + r);
Output:
2 8
a++*3 → 2×3=6 (a becomes 3). --a → a wapas 2, deta hai 2. r = 6+2 = 8, a = 2.
++/-- ke baad variable ki nayi value ek margin mein likhte jao — ICSE examiner isi habit ko full marks deta hai.Relational Operators
Comparison ke liye: >, <, >=, <=, == (equal), != (not equal). Result hamesha boolean hota hai — true ya false, bas.
= assigns, == compares. if(a = 5) Java mein compile hi nahi hota (booleans ke alawa) — aur theory mein iska difference likhna 1 easy mark hai.Logical Operators & Short-Circuiting
Conditions jodne ke liye: && (AND — dono true), || (OR — koi ek true), ! (NOT — ulta). Inka secret weapon: short-circuit evaluation.
System.out.println(5 > 3 && 2 > 4); System.out.println(5 > 3 || 2 > 4); System.out.println(!(5 > 3));
Output:
false true false
boolean flag = false; int cnt = 0;
if (flag && (++cnt > 0)) { }
System.out.println(cnt);Output:
0
Kyunki flag false tha, Java ne ++cnt ko dekha tak nahi — AND ka left side false ho toh right side skip. Isliye cnt 0 hi raha. Same trick || ke saath: left true → right skip.
The Ternary Operator
Ek line ka if-else: condition ? valueIfTrue : valueIfFalse. Java ka single operator jo TEEN operands leta hai.
int big = 17, sm = 8; System.out.println(big > sm ? big : sm);
Output:
17
int n = 7; System.out.println((n % 2 == 0) ? "Even" : "Odd");
Output:
Odd
Precedence & Associativity
Ek expression mein kaun pehle chalega? Simplified ladder (top = first): ++/--/! → * / % → + - → relational → && → || → ternary → =. Same level par (jaise * aur /) → left to right (associativity).
System.out.println(10 + 3 * 2); System.out.println((10 + 3) * 2); System.out.println(8 / 2 * 4); System.out.println(10 - 4 + 2);
Output:
16 26 16 8
8/2*4: division pehle nahi — dono same level hain, left-to-right → 4×4=16. 10-4+2 → 6+2=8, not 4.
8/2*4 ko 8/(2×4)=1 padhna — galat! Brackets ke bina Java kabhi right side pehle nahi karta jab operators same level ke hon.Type Conversion in Expressions
Mixed-type expression mein chhota type automatically bade mein promote ho jaata hai (implicit conversion): byte→short→int→long→float→double, aur char→int. Zabardasti karne ke liye cast lagao: (int)7.9.
System.out.println('A' + 1);
System.out.println((char)('A' + 1));
System.out.println((int)'a');Output:
66 B 97
'A' ka Unicode 65 hai. ‘A’+1 arithmetic hai → 66. Wapas letter chahiye toh cast karo → ‘B’. Small ‘a’ = 97 — yeh teen values (65, 97, 48 for ‘0’) yaad kar lo, ICSE mein har doosre saal aati hain.
double d = 5; System.out.println(d / 2); int i = (int)7.9; System.out.println(i); System.out.println(9 / 2.0);
Output:
2.5 7 4.5
(int)7.9 rounds nahi karta — truncate karta hai → 7.
Dry-Run Bank — Output Questions
ICSE Section A ka signature move: “What will be the output?” Neeche ke har snippet ko pehle KHUD solve karo, phir answer kholo.
int k = 10; System.out.println(k++ + k++); System.out.println(k);
Show Answer
Output:
21 12
k++ → 10 (k=11), k++ → 11 (k=12). Sum 21, phir k=12.
int p = 5; int q = ++p + p++; System.out.println(p + " " + q);
Show Answer
Output:
7 12
++p → 6, p++ → 6 (phir 7). q=12, p=7.
System.out.println(100 / 8 * 8 + 100 % 8);
Show Answer
Output:
100
100/8=12 → 12×8=96 → +4 = 100. (Yeh identity har number ke liye chalti hai!)
int x = 4; int y = x-- - --x; System.out.println(x + " " + y);
Show Answer
Output:
2 2
x– → 4 (x=3), –x → 2. y=4−2=2, x=2.
Practice Worksheet
System.out.println(19/4); and System.out.println(19.0/4);Show Answer
4 aur 4.75 — pehla integer division (truncation), doosre mein 19.0 ne expression ko double bana diya.
17 % 5 and -17 % 5Show Answer
2 aur −2 — modulus ka sign left operand se aata hai.
int a=8; a *= 2+3; — What is a?Show Answer
40 — shorthand means a = a × (2+3), poora right side pehle.
int x=4; int y = x-- - --x; — x and y?Show Answer
x=2, y=2 — x– deta 4 (x=3), –x deta 2, y=4−2=2.
System.out.println('Z'+1); and System.out.println((char)('Z'+1));Show Answer
91 aur [ — ‘Z’=90; +1 arithmetic; cast se character milta hai (91 = ‘[‘).
5+2>6 && 3<1Show Answer
false — 7>6 true, par 3<1 false; AND needs both.
Show Answer
System.out.println(marks >= 33 ? "Pass" : "Fail");
b += 5 compile for a byte b, but b = b + 5 does not? (1-mark theory)Show Answer
Kyunki shorthand operators result ko automatically left side ke type mein cast kar dete hain; b+5 int ban jaata hai jo byte mein bina cast ke nahi ja sakta.
Aage kya? Isi foundation par conditionals khade hote hain — pehle Java Basics & OOP Concepts aur Values & Data Types revise kar lo agar operators ke types mein confusion ho. Poora section: ICSE Class 10 hub.
Kaizen: Roz sirf 3 dry-run questions khud se solve karo — do hafte mein output questions aapke liye free marks ban jayenge. 小さな改善, har din. 🌱
