Is lesson me hum seekhenge:
- Operators kya hote hain
- Arithmetic Operators
- Assignment Operators
- Logical Operators
- Relational Operators
- Unary Operators
- Order of Operations (BODMAS Rule)
Java me operators special symbols hote hain jo variables aur values par operations perform karte hain.
Example:
5 + 3
10 > 4
a = b
Arithmetic operators mathematical calculations ke liye use hote hain.
| Operator | Meaning |
|---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
% |
Modulus (remainder) |
public class ArithmeticExample {
public static void main(String[] args) {
int a = 10;
int b = 5;
System.out.println(a + b);
System.out.println(a - b);
System.out.println(a * b);
System.out.println(a / b);
System.out.println(a % b);
}
}15
5
50
2
0
Assignment operator ka use value assign karne ke liye hota hai.
| Operator | Example | Meaning |
|---|---|---|
= |
a = 10 | Assign value |
+= |
a += 5 | a = a + 5 |
-= |
a -= 5 | a = a - 5 |
*= |
a *= 2 | a = a * 2 |
/= |
a /= 2 | a = a / 2 |
public class AssignmentExample {
public static void main(String[] args) {
int a = 10;
a += 5;
System.out.println(a);
a *= 2;
System.out.println(a);
}
}Output
15
30
Relational operators comparison ke liye use hote hain.
Ye result true ya false return karte hain.
| Operator | Meaning |
|---|---|
== |
Equal |
!= |
Not Equal |
> |
Greater Than |
< |
Less Than |
>= |
Greater or Equal |
<= |
Less or Equal |
public class RelationalExample {
public static void main(String[] args) {
int a = 10;
int b = 5;
System.out.println(a > b);
System.out.println(a < b);
System.out.println(a == b);
System.out.println(a != b);
}
}Output
true
false
false
true
Logical operators multiple conditions check karne ke liye use hote hain.
| Operator | Meaning |
|---|---|
&& |
Logical AND |
| ` | |
! |
Logical NOT |
public class LogicalExample {
public static void main(String[] args) {
int age = 20;
boolean hasLicense = true;
System.out.println(age >= 18 && hasLicense);
System.out.println(age >= 18 || hasLicense);
System.out.println(!hasLicense);
}
}Output
true
true
false
Unary operator single operand par operation karta hai.
| Operator | Meaning |
|---|---|
+ |
Positive |
- |
Negative |
++ |
Increment |
-- |
Decrement |
! |
Logical NOT |
public class UnaryExample {
public static void main(String[] args) {
int a = 5;
a++;
System.out.println(a);
a--;
System.out.println(a);
}
}Output
6
5
Java expressions evaluate karte waqt BODMAS rule follow karta hai.
BODMAS ka matlab:
B → Brackets
O → Order (Power)
D → Division
M → Multiplication
A → Addition
S → Subtraction
public class OrderOfOperations {
public static void main (String[] args) {
System.out.println(10 - 5 * 4);
System.out.println(10 * 5 * 2 + 5 / 2 - 2); // BODMAS Rule Follow
System.out.println(10 / (4 / 2)); // BODMAS Rule Follow
}
}10 - 5 * 4
Step:
5 * 4 = 20
10 - 20 = -10
Output
-10
10 * 5 * 2 + 5 / 2 - 2
Step:
10 * 5 = 50
50 * 2 = 100
5 / 2 = 2
100 + 2 = 102
102 - 2 = 100
Output
100
10 / (4 / 2)
Step:
4 / 2 = 2
10 / 2 = 5
Output
5
- Operators values par operations perform karte hain
- Arithmetic operators mathematical operations ke liye use hote hain
- Relational operators comparison ke liye use hote hain
- Logical operators multiple conditions check karte hain
- Unary operators single operand par kaam karte hain
- Java expressions BODMAS rule follow karte hain
1️⃣ Java me operators kya hote hain?
2️⃣ Arithmetic operators ka use kya hai?
3️⃣ == aur = me kya difference hai?
4️⃣ Logical AND (&&) ka kya use hai?
5️⃣ BODMAS rule kya hota hai?
Is lesson me humne seekha:
✔ Arithmetic Operators
✔ Assignment Operators
✔ Relational Operators
✔ Logical Operators
✔ Unary Operators
✔ Order of Operations (BODMAS)
Operators Java programming ka fundamental concept hain aur almost har program me use hote hain.
Next lesson me hum seekhenge:
- Conditional Statements
- if
- if-else
- else-if
- Nested if