Operators in java जावा में ऑपरेटर
In Java, operators are special symbols used to perform operations on variables and values. Java supports the following types of operators:
जावा में, ऑपरेटर विशेष चिह्न होते हैं जो वेरिएबल्स और मानों पर संचालन (ऑपरेशन) करते हैं। जावा निम्न प्रकार के ऑपरेटरों का समर्थन करता है:
1️⃣ Arithmetic Operators (गणितीय ऑपरेटर)
Used for basic mathematical operations.
इनका उपयोग गणनाएँ करने के लिए किया जाता है।
Operator | Meaning | Example |
---|---|---|
+ |
Addition | a + b |
- |
Subtraction | a - b |
* |
Multiplication | a * b |
/ |
Division | a / b |
% |
Modulus | a % b |
🔸 Example:
int a = 10, b = 3;
System.out.println(a + b); // 13
System.out.println(a % b); // 1
2️⃣ Relational or Comparison Operators (तुलनात्मक ऑपरेटर)
Used to compare two values.
दो मानों की तुलना करने के लिए प्रयुक्त।
Operator | Meaning | Example |
---|---|---|
== |
Equal to | a == b |
!= |
Not equal to | a != b |
> |
Greater than | a > b |
< |
Less than | a < b |
>= |
Greater than or equal | a >= b |
<= |
Less than or equal | a <= b |
🔸 Example:
int x = 5, y = 10;
System.out.println(x > y); // false
3️⃣ Logical Operators (तार्किक ऑपरेटर)
Used for combining two or more conditions.
एक से अधिक शर्तों को जोड़ने के लिए प्रयुक्त।
Operator | Meaning | Example |
---|---|---|
&& |
Logical AND | (a > 5 && b < 10) |
` | ` | |
! |
Logical NOT | !(a > b) |
🔸 Example:
boolean a = true, b = false;
System.out.println(a && b); // false
4️⃣ Assignment Operators (सौंपने वाले ऑपरेटर)
Used to assign values to variables.
वेरिएबल्स को मान सौंपने के लिए।
Operator | Meaning | Example |
---|---|---|
= |
Assign | a = 5 |
+= |
Add and assign | a += 3 |
-= |
Subtract and assign | a -= 2 |
*= |
Multiply and assign | a *= 4 |
/= |
Divide and assign | a /= 2 |
%= |
Modulus and assign | a %= 3 |
5️⃣ Increment/Decrement Operators (वृद्धि/ह्रास ऑपरेटर)
Used to increase or decrease value by 1.
मान को 1 से बढ़ाने या घटाने के लिए।
Operator | Meaning | Example |
---|---|---|
++ |
Increment | a++ |
-- |
Decrement | a-- |
🔸 Example:
int a = 10;
a++;
System.out.println(a); // 11
6️⃣ Conditional (Ternary) Operator (शर्तीय ऑपरेटर)
Used as shorthand for if-else
.
if-else
का लघु रूप।
🔸 Syntax:
condition ? expression1 : expression2;
🔸 Example:
int a = 10, b = 20;
int max = (a > b) ? a : b;
System.out.println(max); // 20
7️⃣ Bitwise Operators (बिटवाइज़ ऑपरेटर)
Used to perform bit-level operations.
बिट स्तर के संचालन के लिए प्रयोग किया जाता है।
Operator | Meaning | Example |
---|---|---|
& |
Bitwise AND | a & b |
` | ` | Bitwise OR |
^ |
Bitwise XOR | a ^ b |
~ |
Bitwise Complement | ~a |
<< |
Left Shift | a << 2 |
>> |
Right Shift | a >> 2 |
>>> |
Unsigned Right Shift | a >>> 2 |
🔸 Example:
int a = 5, b = 3;
System.out.println(a & b); // 1
System.out.println(a << 1); // 10
8️⃣ instanceof
Operator
Used to test whether an object is an instance of a class or subclass.
किसी ऑब्जेक्ट के क्लास का हिस्सा होने की जांच करता है।
🔸 Example:
String str = "Java";
System.out.println(str instanceof String); // true
9️⃣ Type Casting Operators (डेटा प्रकार परिवर्तन)
Used to convert one data type to another.
एक डेटा प्रकार को दूसरे में बदलने के लिए।
🔸 Example:
double a = 10.5;
int b = (int) a; // Type casting from double to int
System.out.println(b); // 10
Conclusion (निष्कर्ष):
Operators are essential tools in Java that help perform various kinds of operations efficiently. Mastering them is crucial for writing effective code.
ऑपरेटर जावा प्रोग्रामिंग के महत्वपूर्ण उपकरण हैं। इन्हें समझना एक कुशल प्रोग्रामर बनने के लिए आवश्यक है।
Comments
Post a Comment