β˜• Java Operators β€” Complete Deep Revision Guide

πŸ“– Operators Kya Hain?

int result = 10 + 5;
              ↑   ↑  ↑
          operand op operand

Operator = Symbol jo operation karta hai (+, -, >, &&)

Operand = Jis value par operation hota hai (10, 5)

πŸ”΅ Topic 1: Arithmetic Operators

Deep Explanation:

+  β†’ Addition
-  β†’ Subtraction
*  β†’ Multiplication
/  β†’ Division  (int/int = int, decimal cut!)
%  β†’ Modulus   (remainder - bacha hua)

Important: % (modulus) real life mein bohot use hota hai:

10 % 3 = 1  β†’ 10 ko 3 se divide karo, remainder 1
Even/Odd check: n % 2 == 0 β†’ even
πŸ“ Arithmetic1.java
public class Arithmetic1 {
    public static void main(String[] args) {

        int a = 17, b = 5;

        System.out.println("a + b = " + (a + b));  // 22
        System.out.println("a - b = " + (a - b));  // 12
        System.out.println("a * b = " + (a * b));  // 85
        System.out.println("a / b = " + (a / b));  // 3 (not 3.4!)
        System.out.println("a % b = " + (a % b));  // 2 (remainder)

        // int division vs double division
        double div = (double) a / b;
        System.out.println("exact division = " + div); // 3.4
    }
}
β–Ά OUTPUT
a + b = 22
a - b = 12
a * b = 85
a / b = 3
a % b = 2
exact division = 3.4
πŸ’‘ Short Explain: 17/5 = 3 kyunki int/int mein decimal cut hota hai. 17%5 = 2 kyunki 17 = 5Γ—3 + 2.
πŸ“ Arithmetic2.java
public class Arithmetic2 {
    public static void main(String[] args) {

        // Modulus ke real uses
        int n1 = 28;
        int n2 = 33;

        // Even ya Odd check
        if (n1 % 2 == 0)
            System.out.println(n1 + " is Even");
        else
            System.out.println(n1 + " is Odd");

        // Divisibility check
        if (n2 % 3 == 0)
            System.out.println(n2 + " is divisible by 3");
        else
            System.out.println(n2 + " is NOT divisible by 3");

        // Last digit nikalna
        int num = 12345;
        System.out.println("Last digit: " + num % 10); // 5

        // Clock/Circular problem
        int hour = 14 % 12;
        System.out.println("14:00 = " + hour + " PM"); // 2 PM
    }
}
β–Ά OUTPUT
28 is Even
33 is NOT divisible by 3
Last digit: 5
14:00 = 2 PM
πŸ’‘ % ka real use β€” even/odd, divisibility, last digit, aur circular (clock) problems mein.
πŸ“ Arithmetic3.java
public class Arithmetic3 {
    public static void main(String[] args) {

        // String mein + concatenation karta hai
        int a = 10, b = 20;

        System.out.println("Sum = " + a + b);       // "Sum = 1020" ❌ wrong!
        System.out.println("Sum = " + (a + b));     // "Sum = 30"  βœ… sahi

        // Explanation:
        // "Sum = " + 10 = "Sum = 10" (string)
        // "Sum = 10" + 20 = "Sum = 1020" (concatenation!)
        // () use karo toh pehle 10+20=30 hoga

        String name = "Rahul";
        int age = 20;
        System.out.println("Name: " + name + ", Age: " + age);
    }
}
β–Ά OUTPUT
Sum = 1020
Sum = 30
Name: Rahul, Age: 20
πŸ’‘ + string ke saath concatenation karta hai. "" + 10 + 20 = "1020" β€” isliye numbers ke around () lagao.
πŸ“ Arithmetic4.java
public class Arithmetic4 {
    public static void main(String[] args) {

        // Real world - Bill calculator
        int    items        = 5;
        double pricePerItem = 99.50;
        double total        = items * pricePerItem;
        double tax          = total * 0.18;   // 18% GST
        double finalBill    = total + tax;

        System.out.println("Items:      " + items);
        System.out.println("Price each: Rs." + pricePerItem);
        System.out.println("Total:      Rs." + total);
        System.out.println("GST (18%):  Rs." + tax);
        System.out.println("Final Bill: Rs." + finalBill);

        // Remainder use - pizza slices
        int totalSlices = 23;
        int people      = 4;
        System.out.println("\nEach person gets: " + totalSlices / people + " slices");
        System.out.println("Leftover slices:  " + totalSlices % people);
    }
}
β–Ά OUTPUT
Items: 5
Price each: Rs.99.5
Total: Rs.497.5
GST (18%): Rs.89.55
Final Bill: Rs.587.05

Each person gets: 5 slices
Leftover slices: 3

🟒 Topic 2: Assignment Operators

Deep Explanation:

=   β†’ simple assign       a = 10
+=  β†’ add and assign      a += 5  means  a = a + 5
-=  β†’ subtract assign     a -= 5  means  a = a - 5
*=  β†’ multiply assign     a *= 5  means  a = a * 5
/=  β†’ divide assign       a /= 5  means  a = a / 5
%=  β†’ modulus assign      a %= 5  means  a = a % 5

Shortcut operators hain β€” code short likhne ke liye.

πŸ“ Assignment1.java
public class Assignment1 {
    public static void main(String[] args) {

        int a = 20;
        System.out.println("Initial a = " + a);

        a += 5;   // a = a + 5 = 25
        System.out.println("After a += 5  β†’ " + a);

        a -= 3;   // a = a - 3 = 22
        System.out.println("After a -= 3  β†’ " + a);

        a *= 2;   // a = a * 2 = 44
        System.out.println("After a *= 2  β†’ " + a);

        a /= 4;   // a = a / 4 = 11
        System.out.println("After a /= 4  β†’ " + a);

        a %= 3;   // a = a % 3 = 2
        System.out.println("After a %= 3  β†’ " + a);
    }
}
β–Ά OUTPUT
Initial a = 20
After a += 5 β†’ 25
After a -= 3 β†’ 22
After a *= 2 β†’ 44
After a /= 4 β†’ 11
After a %= 3 β†’ 2
πŸ“ Assignment2.java
public class Assignment2 {
    public static void main(String[] args) {

        // Real use - score system
        int score = 0;
        System.out.println("Start Score: " + score);

        score += 10;  // level complete
        System.out.println("Level 1 done: " + score);

        score += 25;  // bonus
        System.out.println("Bonus earned: " + score);

        score -= 5;   // penalty
        System.out.println("Penalty applied: " + score);

        score *= 2;   // double points event
        System.out.println("Double points: " + score);

        // Shopping cart
        double cart = 0;
        cart += 299.0;  // shirt
        cart += 499.0;  // jeans
        cart -= 50.0;   // coupon discount
        System.out.println("\nCart Total: Rs." + cart);
    }
}
β–Ά OUTPUT
Start Score: 0
Level 1 done: 10
Bonus earned: 35
Penalty applied: 30
Double points: 60

Cart Total: Rs.748.0

🟑 Topic 3: Comparison (Relational) Operators

Deep Explanation:

==  β†’ equal to           (10 == 10 β†’ true)
!=  β†’ not equal to       (10 != 5  β†’ true)
>   β†’ greater than       (10 > 5   β†’ true)
<   β†’ less than          (5  < 10  β†’ true)
>=  β†’ greater or equal   (10 >= 10 β†’ true)
<=  β†’ less or equal      (5  <= 10 β†’ true)

Result hamesha boolean hota hai β€” true ya false

⚠️ Common Mistake:

=  β†’ assignment (value daalna)   a = 5
== β†’ comparison (value check)    a == 5
πŸ“ Comparison1.java
public class Comparison1 {
    public static void main(String[] args) {

        int a = 15, b = 10;

        System.out.println("a == b : " + (a == b));  // false
        System.out.println("a != b : " + (a != b));  // true
        System.out.println("a >  b : " + (a > b));   // true
        System.out.println("a <  b : " + (a < b));   // false
        System.out.println("a >= b : " + (a >= b));  // true
        System.out.println("a <= b : " + (a <= b));  // false

        // Comparison result boolean mein store kar sakte hain
        boolean isEqual   = (a == b);
        boolean isGreater = (a > b);
        System.out.println("isEqual:   " + isEqual);
        System.out.println("isGreater: " + isGreater);
    }
}
β–Ά OUTPUT
a == b : false
a != b : true
a > b : true
a < b : false
a >= b : true
a <= b : false
isEqual: false
isGreater: true
πŸ“ Comparison2.java
public class Comparison2 {
    public static void main(String[] args) {

        // Real use - eligibility checks
        int    age    = 20;
        int    marks  = 85;
        double salary = 25000.0;

        // Voting
        System.out.println("Can vote (>=18): " + (age >= 18));

        // Scholarship
        System.out.println("Scholarship (>80): " + (marks > 80));

        // Tax
        System.out.println("Pays tax (>20000): " + (salary > 20000));

        // Grade
        String grade;
        if (marks >= 90)      grade = "A+";
        else if (marks >= 75) grade = "A";
        else if (marks >= 60) grade = "B";
        else                   grade = "C";
        System.out.println("Grade: " + grade);
    }
}
β–Ά OUTPUT
Can vote (>=18): true
Scholarship (>80): true
Pays tax (>20000): true
Grade: A

πŸ”΄ Topic 4: Logical Operators

Deep Explanation:

&&  β†’ AND  β†’ dono true hone chahiye
||  β†’ OR   β†’ ek bhi true ho toh true
!   → NOT  → ulta kar do (true→false, false→true)

Truth Table:

A       B       A && B   A || B   !A
true    true    true     true     false
true    false   false    true     false
false   true    false    true     true
false   false   false    false    true
πŸ“ Logical1.java
public class Logical1 {
    public static void main(String[] args) {

        boolean a = true, b = false;

        System.out.println("a && b = " + (a && b));  // false
        System.out.println("a || b = " + (a || b));  // true
        System.out.println("!a     = " + (!a));       // false
        System.out.println("!b     = " + (!b));       // true

        System.out.println("true  && true  = " + (true  && true));
        System.out.println("true  && false = " + (true  && false));
        System.out.println("false || true  = " + (false || true));
        System.out.println("false || false = " + (false || false));
    }
}
β–Ά OUTPUT
a && b = false
a || b = true
!a = false
!b = true
true && true = true
true && false = false
false || true = true
false || false = false
πŸ“ Logical2.java
public class Logical2 {
    public static void main(String[] args) {

        int     age      = 22;
        int     marks    = 75;
        boolean hasId    = true;
        boolean isMember = false;

        // AND - dono conditions true honi chahiye
        if (age >= 18 && marks >= 60) {
            System.out.println("Eligible for admission");
        }

        // OR - ek bhi true ho
        if (hasId || isMember) {
            System.out.println("Entry allowed");
        }

        // NOT - condition ulti karo
        if (!isMember) {
            System.out.println("Not a member - pay Rs.100 extra");
        }

        // Combined
        if (age >= 18 && marks >= 60 && hasId) {
            System.out.println("All conditions met!");
        }
    }
}
β–Ά OUTPUT
Eligible for admission
Entry allowed
Not a member - pay Rs.100 extra
All conditions met!

⚑ Topic 5: Short-Circuit Operators MOST IMPORTANT!

Deep Explanation β€” Interview mein zaroor aata hai!

Short-Circuit matlab: Agar pehli condition se hi answer pata chal jaaye toh dusri condition evaluate hi nahi hoti!

&& (Short-Circuit AND):
  pehli condition FALSE β†’ dusri check hi nahi karega β†’ result FALSE
  pehli condition TRUE  β†’ dusri check karega

|| (Short-Circuit OR):
  pehli condition TRUE  β†’ dusri check hi nahi karega β†’ result TRUE
  pehli condition FALSE β†’ dusri check karega

Real Example:

int x = 0;
if (x != 0 && 10/x > 1) { }
            ↑
    x=0 hai toh pehli condition false
    10/0 division by zero hoga - BUT evaluate hi nahi hoga!
    Short circuit ne bachaya!
πŸ“ ShortCircuit1.java
public class ShortCircuit1 {
    public static void main(String[] args) {

        int x = 0;

        // Without short-circuit (& single) - DONO evaluate hote hain
        // if (x != 0 & 10/x > 1)  // ← ArithmeticException aayega!

        // With short-circuit (&& double) - SAFE!
        if (x != 0 && 10 / x > 1) {
            System.out.println("Condition true");
        } else {
            System.out.println("Short-circuit saved us! x=0 caught first");
        }

        // || short circuit
        int a = 5;
        if (a > 0 || 10 / 0 > 1) { // 10/0 evaluate hi nahi hoga!
            System.out.println("OR short-circuit: first was true, skipped second");
        }
    }
}
β–Ά OUTPUT
Short-circuit saved us! x=0 caught first
OR short-circuit: first was true, skipped second
πŸ’‘ && β€” pehli false toh ruk jao. || β€” pehli true toh ruk jao. Dusri condition ka code execute hi nahi hota!
πŸ“ ShortCircuit2.java
public class ShortCircuit2 {

    static int checkA() {
        System.out.println("checkA() called");
        return 5;
    }

    static int checkB() {
        System.out.println("checkB() called");
        return 10;
    }

    public static void main(String[] args) {

        System.out.println("--- && Test ---");
        // pehli condition false hai
        if (checkA() > 10 && checkB() > 5) {  // checkA()=5, 5>10=false
            System.out.println("Both true");
        } else {
            System.out.println("Result: false");
        }
        // checkB() called hi nahi hoga!

        System.out.println("\n--- || Test ---");
        // pehli condition true hai
        if (checkA() > 0 || checkB() > 5) {   // checkA()=5, 5>0=true
            System.out.println("Result: true");
        }
        // checkB() called hi nahi hoga!
    }
}
β–Ά OUTPUT
--- && Test ---
checkA() called
Result: false

--- || Test ---
checkA() called
Result: true
πŸ’‘ checkB() ka print nahi aaya β€” matlab wo method call hi nahi hua! Yahi short-circuit proof hai.
πŸ“ ShortCircuit3.java
public class ShortCircuit3 {
    public static void main(String[] args) {

        // Null check - real world use
        String name = null;

        // Without short-circuit - NullPointerException aayega!
        // if (name.length() > 0 && name.equals("Rahul")) { }

        // With short-circuit - SAFE!
        if (name != null && name.length() > 0) {
            System.out.println("Name is: " + name);
        } else {
            System.out.println("Name is null or empty - safely handled!");
        }

        // Single & vs && difference
        int count = 0;
        // & evaluates BOTH sides always
        // boolean r1 = (count != 0) & (10 / count > 1); // CRASH!
        // && evaluates second only if needed - SAFE
        boolean r2 = (count != 0) && (10 / count > 1);
        System.out.println("Short-circuit result: " + r2);
    }
}
β–Ά OUTPUT
Name is null or empty - safely handled!
Short-circuit result: false
πŸ’‘ name != null && β€” pehle null check karo, tab hi .length() call karo. Yeh real-world mein sabse common short-circuit use case hai!
πŸ“ ShortCircuit4.java
public class ShortCircuit4 {
    public static void main(String[] args) {

        // & aur | (non-short-circuit) - DONO sides hamesha evaluate
        int a = 5;
        System.out.println("--- Single & (no short-circuit) ---");
        boolean r1 = (a > 10) & (a++ > 3);  // a++ execute hoga!
        System.out.println("a after &  : " + a);  // 6 (a++ hua)

        a = 5; // reset
        System.out.println("--- Double && (short-circuit) ---");
        boolean r2 = (a > 10) && (a++ > 3); // a++ execute NAHI hoga!
        System.out.println("a after &&: " + a);  // 5 (a++ nahi hua!)

        System.out.println("\nConclusion:");
        System.out.println("& runs both sides always");
        System.out.println("&& skips right side if left is false");
    }
}
β–Ά OUTPUT
--- Single & (no short-circuit) ---
a after & : 6
--- Double && (short-circuit) ---
a after &&: 5

Conclusion:
& runs both sides always
&& skips right side if left is false

πŸ” Topic 6: Increment / Decrement Operators IMPORTANT!

Deep Explanation:

++  β†’ 1 badha do
--  β†’ 1 ghata do

2 Types:

Pre-increment  : ++a β†’ PEHLE badha, PHIR use karo
Post-increment : a++ β†’ PEHLE use karo, PHIR badha

Memory trick:

++a  β†’  ++ pehle hai  β†’ pehle kaam karo (increment) phir value do
a++  β†’  ++ baad mein  β†’ pehle value do phir kaam karo (increment)

Step by step:

int a = 5;
int x = ++a;  // a pehle 6 hua, phir x = 6  β†’  a=6, x=6

int a = 5;
int x = a++;  // x = 5 mila pehle, phir a = 6 hua  β†’  a=6, x=5
πŸ“ Increment1.java
public class Increment1 {
    public static void main(String[] args) {

        // Pre-increment: pehle badha, phir use
        int a = 5;
        int x = ++a;
        System.out.println("Pre-increment:");
        System.out.println("a = " + a);  // 6
        System.out.println("x = " + x);  // 6

        System.out.println();

        // Post-increment: pehle use, phir badha
        int b = 5;
        int y = b++;
        System.out.println("Post-increment:");
        System.out.println("b = " + b);  // 6
        System.out.println("y = " + y);  // 5 (purani value mili)
    }
}
β–Ά OUTPUT
Pre-increment:
a = 6
x = 6

Post-increment:
b = 6
y = 5
πŸ’‘ Dono mein value 6 ho jaati hai β€” difference sirf itna hai ki expression mein kaunsi value use hoti hai: nai (pre) ya purani (post).
πŸ“ Increment2.java
public class Increment2 {
    public static void main(String[] args) {

        // Step by step trace karo
        int a = 10;

        System.out.println("a   = " + a);        // 10
        System.out.println("a++ = " + a++);      // 10 (purani value print, phir 11)
        System.out.println("a   = " + a);        // 11 (ab 11 hai)
        System.out.println("++a = " + ++a);      // 12 (pehle 12, phir print)
        System.out.println("a   = " + a);        // 12

        System.out.println();

        // Pre-decrement vs Post-decrement
        int b = 10;
        System.out.println("b   = " + b);        // 10
        System.out.println("b-- = " + b--);      // 10 (purani value, phir 9)
        System.out.println("b   = " + b);        // 9
        System.out.println("--b = " + --b);      // 8 (pehle 8, phir print)
        System.out.println("b   = " + b);        // 8
    }
}
β–Ά OUTPUT
a = 10
a++ = 10
a = 11
++a = 12
a = 12

b = 10
b-- = 10
b = 9
--b = 8
b = 8
πŸ“ Increment3.java
public class Increment3 {
    public static void main(String[] args) {

        // Complex expressions - carefully trace karo
        int a      = 5;
        int result = a++ + ++a;
        // Step 1: a++ β†’ 5 use karo, a becomes 6
        // Step 2: ++a β†’ a becomes 7, 7 use karo
        // result = 5 + 7 = 12, a = 7
        System.out.println("result = " + result);  // 12
        System.out.println("a      = " + a);        // 7

        System.out.println();

        int b  = 3;
        int r2 = ++b * b++;
        // Step 1: ++b β†’ b becomes 4, use 4
        // Step 2: b++ β†’ use 4 (current b), then b becomes 5
        // r2 = 4 * 4 = 16, b = 5
        System.out.println("r2 = " + r2);  // 16
        System.out.println("b  = " + b);   // 5
    }
}
β–Ά OUTPUT
result = 12
a = 7

r2 = 16
b = 5
πŸ’‘ Complex expressions mein left se right evaluate hota hai. Pre pehle value badlata hai, post baad mein.
πŸ“ Increment4.java
public class Increment4 {
    public static void main(String[] args) {

        // Loop mein increment - most common use
        System.out.println("Post-increment loop (i=0 to 4):");
        for (int i = 0; i < 5; i++) {  // i++ most common
            System.out.print(i + " ");
        }

        System.out.println("\nPre-increment loop (same result here):");
        for (int i = 0; i < 5; ++i) {  // ++i same result in loop
            System.out.print(i + " ");
        }

        System.out.println("\n\nPre vs Post in loop condition:");
        int x = 0;
        while (x++ < 3) {   // post: check x first, then increment
            System.out.print(x + " ");
        }

        System.out.println();
        int y = 0;
        while (++y < 3) {   // pre: increment first, then check
            System.out.print(y + " ");
        }
    }
}
β–Ά OUTPUT
Post-increment loop (i=0 to 4):
0 1 2 3 4
Pre-increment loop (same result here):
0 1 2 3 4

Pre vs Post in loop condition:
1 2 3
1 2
πŸ’‘ Loop mein i++ aur ++i same result deta hai mostly. But condition mein difference aata hai β€” post mein ek extra iteration ho sakti hai.

πŸ”· Topic 7: Ternary Operator

Deep Explanation:

condition ? value_if_true : value_if_false

if-else ka short form hai:

// If-else way:
if (a > b) { max = a; } else { max = b; }

// Ternary way:
max = (a > b) ? a : b;
πŸ“ Ternary1.java
public class Ternary1 {
    public static void main(String[] args) {

        int a = 15, b = 10;

        // Max find karo
        int max = (a > b) ? a : b;
        System.out.println("Max = " + max);  // 15

        // Min find karo
        int min = (a < b) ? a : b;
        System.out.println("Min = " + min);  // 10

        // Even or Odd
        int    num  = 28;
        String type = (num % 2 == 0) ? "Even" : "Odd";
        System.out.println(num + " is " + type);

        // Pass or Fail
        int    marks  = 72;
        String result = (marks >= 35) ? "PASS" : "FAIL";
        System.out.println("Result: " + result);
    }
}
β–Ά OUTPUT
Max = 15
Min = 10
28 is Even
Result: PASS
πŸ“ Ternary2.java
public class Ternary2 {
    public static void main(String[] args) {

        // Nested ternary (3 conditions)
        int marks = 85;

        String grade = (marks >= 90) ? "A+" :
                        (marks >= 75) ? "A"  :
                        (marks >= 60) ? "B"  : "C";

        System.out.println("Marks: " + marks + " | Grade: " + grade);

        // Absolute value
        int num = -15;
        int abs = (num >= 0) ? num : -num;
        System.out.println("Absolute of " + num + " = " + abs);

        // Discount logic
        int    price      = 1200;
        double discount   = (price > 1000) ? 0.10 : 0.05;
        double finalPrice = price - (price * discount);
        System.out.println("Price: " + price + " | Final: " + finalPrice);
    }
}
β–Ά OUTPUT
Marks: 85 | Grade: A
Absolute of -15 = 15
Price: 1200 | Final: 1080.0

πŸ”Έ Topic 8: Bitwise Operators

Deep Explanation: Bitwise operators binary (0 and 1) level pe kaam karte hain:

&   β†’ Bitwise AND  β†’ dono 1 hone chahiye
|   β†’ Bitwise OR   β†’ ek 1 ho toh 1
^   β†’ Bitwise XOR  β†’ dono alag ho toh 1
~   β†’ Complement   β†’ 0β†’1, 1β†’0
<<  β†’ Left shift   β†’ 2 se multiply
>>  β†’ Right shift  β†’ 2 se divide

Example:

5 = 0101
3 = 0011
---------
5 & 3 = 0001 = 1
5 | 3 = 0111 = 7
5 ^ 3 = 0110 = 6
πŸ“ Bitwise1.java
public class Bitwise1 {
    public static void main(String[] args) {

        int a = 5;  // binary: 0101
        int b = 3;  // binary: 0011

        System.out.println("a = " + a + " (binary: 0101)");
        System.out.println("b = " + b + " (binary: 0011)");
        System.out.println();

        System.out.println("a & b  = " + (a & b));   // 0001 = 1
        System.out.println("a | b  = " + (a | b));   // 0111 = 7
        System.out.println("a ^ b  = " + (a ^ b));   // 0110 = 6
        System.out.println("~a     = " + (~a));       // -6
        System.out.println("a << 1 = " + (a << 1));  // 1010 = 10 (Γ—2)
        System.out.println("a >> 1 = " + (a >> 1));  // 0010 = 2  (Γ·2)
    }
}
β–Ά OUTPUT
a = 5 (binary: 0101)
b = 3 (binary: 0011)

a & b = 1
a | b = 7
a ^ b = 6
~a = -6
a << 1 = 10
a >> 1 = 2
πŸ“ Bitwise2.java
public class Bitwise2 {
    public static void main(String[] args) {

        // Shift = multiply/divide by 2 (fast)
        int num = 8;
        System.out.println("num       = " + num);
        System.out.println("num << 1  = " + (num << 1)); // Γ—2 = 16
        System.out.println("num << 2  = " + (num << 2)); // Γ—4 = 32
        System.out.println("num << 3  = " + (num << 3)); // Γ—8 = 64
        System.out.println("num >> 1  = " + (num >> 1)); // Γ·2 = 4
        System.out.println("num >> 2  = " + (num >> 2)); // Γ·4 = 2

        // Even/Odd using bitwise (faster than %)
        int x = 13;
        if ((x & 1) == 1)
            System.out.println(x + " is Odd  (bitwise check)");
        else
            System.out.println(x + " is Even (bitwise check)");

        int y = 20;
        if ((y & 1) == 0)
            System.out.println(y + " is Even (bitwise check)");
    }
}
β–Ά OUTPUT
num = 8
num << 1 = 16
num << 2 = 32
num << 3 = 64
num >> 1 = 4
num >> 2 = 2
13 is Odd (bitwise check)
20 is Even (bitwise check)

πŸ“‹ Complete Revision Summary

Operator TypeSymbolsKey Point
Arithmetic +  -  *  /  % int/int = int (decimal cut!)
Assignment =  +=  -=  *=  /=  %= a+=5 means a=a+5
Comparison ==  !=  >  <  >=  <= Result always boolean; = assign, == compare
Logical &&  ||  ! Result always boolean
⭐ Short-Circuit &&  || && β†’ left false? skip right  |  || β†’ left true? skip right  |  Saves from crash (null, divide by 0)
⭐ Increment/Dec ++  -- ++a β†’ pehle badha phir use (pre)  |  a++ β†’ pehle use phir badha (post)
Ternary ? : condition ? true_val : false_val β€” if-else ka short form
Bitwise &  |  ^  ~  <<  >> Binary level operations  |  << = Γ—2, >> = Γ·2

⚠️ Common Mistakes

MistakeWrong ❌Right βœ…
Assignment vs Comparisonif(a = 5)if(a == 5)
String + numbers"ans=" + a + b"ans=" + (a+b)
Int divisiondouble d = 5/2 β†’ 2.0(double)5/2 β†’ 2.5
Short-circuit ignorenull.length() > 0obj != null && obj.length() > 0
Pre vs Post confusionx = a++ (nai chahiye)x = ++a (nai value ke liye)
πŸ† Golden Rule File name = Class name exactly! Jaise class ShortCircuit1 hai toh file ShortCircuit1.java hogi!