Operators in Java: Java में, Operator symbols या keyword होते हैं जिनका उपयोग variables या values पर operations करने के लिए किया जाता है. Java में विभिन्न प्रकार के Operator हैं जिन्हें उनकी कार्यक्षमता के आधार पर कई समूहों में बांटा जा सकता है:

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operator
  • Conditional operator
  • Instanceof operator
  • Unary operators
  • Special Operator
Operators in Java in Hindi
Operators in Java in Hindi

Arithmetic Operators in Java

Arithmetic Operators का उपयोग numerical values पर बेसिक Arithmetic operations परफॉर्म करने के लिए किया जाता है. Java में मूल Arithmetic Operator हैं:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulus (%)
  • Increment (++)
  • Decrement (–)

Example of Arithmetic Operators in Java:

//Addition (+)
int a = 5;
int b = 10;
int sum = a + b; // sum will be 15

//Subtraction (-)
int a = 10;
int b = 5;
int diff = a - b; // diff will be 5

//Multiplication (*)
int a = 5;
int b = 2;
int product = a * b; // product will be 10

//Division (/)
int a = 10;
int b = 2;
int quotient = a / b; // quotient will be 5

//Modulo (%)
int a = 10;
int b = 3;
int remainder = a % b; // remainder will be 1

//increment (++)
int a = 10;
int increase = a++; // increase will be 11

//Decrement (--)
int a = 10;
int decrease = a--; // decrease will be 9

Relational Operators in Java

Relational Operators का उपयोग दो values की compare करने और boolean result (true or false) return करने के लिए किया जाता है. Java में Relational Operator हैं:

  • Equal to (==)
  • Not equal to (!=)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)

Example of Relational Operators:

//Equal to (==)
int x = 5;
int y = 7;
boolean result = x == y; // result is false

//Not equal to (!=)
int x = 5;
int y = 7;
boolean result = x != y; // result is true

//Greater than (>)
int x = 5;
int y = 7;
boolean result = y > x; // result is true

//Less than (<)
int x = 5;
int y = 7;
boolean result = x < y; // result is true

//Greater than or equal to (>=)
int x = 5;
int y = 7;
boolean result = y >= x; // result is true

//Less than or equal to (<=)
int x = 5;
int y = 7;
boolean result = x <= y; // result is true

Logical Operators in Java

Logical Operators का उपयोग मेल दो या दो से अधिक boolean expressions और एक boolean result return करने के लिए किया जाता है. Java में Logical Operator हैं:

  • Logical AND (&&)
  • Logical OR (||)
  • Logical NOT (!)

Example of Logical Operators in Java:

//AND operator (&&)
int x = 5;
int y = 10;
if (x > 0 && y > 0) {
    System.out.println("Both x and y are positive");
}
/*This code checks if both x and y are greater than 0, and if so, prints the message "Both x and y are positive"*/

//OR operator (||)
int x = 5;
int y = -10;
if (x > 0 || y > 0) {
    System.out.println("At least one of x and y is positive");
}
/*This code checks if either x or y (or both) are greater than 0, and if so, prints the message "At least one of x and y is positive".*/

//NOT operator (!)
boolean isSunny = true;
if (!isSunny) {
    System.out.println("It's not sunny today");
} else {
    System.out.println("It's sunny today");
}
/*This code checks if the isSunny variable is false (using the NOT operator), and if so, prints the message "It's not sunny today". Otherwise, it prints "It's sunny today".*/

Bitwise Operators in Java

Bitwise Operators का उपयोग बाइनरी नंबरों के अलग-अलग बिट्स पर operations perform करने के लिए किया जाता है. Java में Bitwise Operator हैं:

  • Bitwise AND (&)
  • Bitwise OR (|)
  • Bitwise XOR (^)
  • Bitwise complement (~)
  • Left shift (<<)
  • Right shift (>>)
  • Unsigned right shift (>>>)

Example of Bitwise Operators:

//Bitwise AND ( & )
int a = 12; // 1100 in binary
int b = 25; // 11001 in binary

int result = a & b; // perform bitwise AND operation

System.out.println(result); // output: 8 (1000 in binary)

//Bitwise OR ( | )
int a = 12; // 1100 in binary
int b = 25; // 11001 in binary

int result = a | b; // perform bitwise OR operation

System.out.println(result); // output: 29 (11101 in binary)

//Bitwise XOR ( ^ )
int a = 12; // 1100 in binary
int b = 25; // 11001 in binary

int result = a ^ b; // perform bitwise XOR operation

System.out.println(result); // output: 21 (10101 in binary)

//Bitwise Complement ( ~ )
int a = 12; // 1100 in binary

int result = ~a; // perform bitwise complement operation

System.out.println(result); // output: -13 (11111111111111111111111111110011 in binary)

Assignment Operators in Java

Assignment Operators का उपयोग किसी variable को value assign करने के लिए किया जाता है. Java में मूल Assignment Operator है:

  • Assignment (=)

Java में कई Compound Assignment Operator भी हैं जो एक Arithmetic या Bitwise Operator को basic Assignment Operator के साथ जोड़ते हैं, जैसे:

  • Addition assignment (+=)
  • Subtraction assignment (-=)
  • Multiplication assignment (*=)
  • Division assignment (/=)
  • Modulus assignment (%=)
  • Bitwise AND assignment (& =)
  • Bitwise OR assignment (|=)
  • Bitwise XOR assignment (^=)
  • Left shift assignment (<<=)
  • Right shift assignment (>>=)
  • Unsigned right shift assignment (>>>=)

Example of Assignment Operators in Java:

//Simple Assignment Operator (=)
int x = 10;
String name = "John";

//Addition Assignment Operator (+=)
int x = 10;
x += 5; // x is now 15

//Subtraction Assignment Operator (-=)
int x = 10;
x -= 3; // x is now 7

//Multiplication Assignment Operator (*=)
int x = 10;
x *= 2; // x is now 20

//Division Assignment Operator (/=)
int x = 10;
x /= 2; // x is now 5

//Modulus Assignment Operator (%=)
int x = 10;
x %= 3; // x is now 1

//Left Shift Assignment Operator (<<=)
int x = 10;
x <<= 2; // x is now 40

//Right Shift Assignment Operator (>>=)
int x = 10;
x >>= 1; // x is now 5

//Bitwise AND Assignment Operator (&=)
int x = 10;
x &= 3; // x is now 2

//Bitwise OR Assignment Operator (|=)
int x = 10;
x |= 3; // x is now 11

//Bitwise XOR Assignment Operator (^=)
int x = 10;
x ^= 3; // x is now 9

//Logical AND Assignment Operator (&&=)
int x = 10;
// This line of code will not compile
x &&= true; // invalid operator

//Logical OR Assignment Operator (||=)
int x = 10;
// This line of code will not compile
x ||= true; // invalid operator

Conditional Operator in Java

Conditional operator (?:) को ternary operator के रूप में भी जाना जाता है. यह if-else Statement को एक लाइन में लिखने का shorthand तरीका है.

Example of Conditional Operator in Java:

int x = 10;
int y = 20;

int max = (x > y) ? x : y;

System.out.println("The maximum value is " + max);

Instanceof Operators in Java

Instanceof operator का उपयोग यह जांचने के लिए किया जाता है कि कोई Object किसी particular Class या interface का instance है या नहीं. instanceof Operator के लिए Syntax निम्नानुसार है:
object instanceof Class

Example:

class Animal { }
class Dog extends Animal { }
class Cat extends Animal { }

public class InstanceOfExample {
    public static void main(String[] args) {
        Animal animal = new Animal();
        Dog dog = new Dog();
        Cat cat = new Cat();
        
        System.out.println(dog instanceof Animal); // true
        System.out.println(cat instanceof Animal); // true
        System.out.println(animal instanceof Dog); // false
    }
}

Expression एक boolean value True return करती है, यदि Object specified Class या interface का एक instance है, otherwise false return करती है.

Unary Operators in Java

Unary Operator ऐसे Operator होते हैं जो एक ही ऑपरेंड पर काम करते हैं. Java में Unary Operator हैं:

  • Unary plus (+)
  • Unary minus (-)
  • Logical complement (!)
  • Bitwise complement (~)
  • Prefix increment (++)
  • Prefix decrement (–)
  • Cast operator ((type))

Example of Unary Operators in Java:

//Increment Operator (++)
int x = 5;
x++; // x is now 6

//Decrement Operator (--)
int x = 5;
x--; // x is now 4

//Unary Plus Operator (+)
int x = 5;
int y = +x; // y is 5

//Unary Minus Operator (-)
int x = 5;
int y = -x; // y is -5

//Logical Complement Operator (!)
boolean x = true;
boolean y = !x; // y is false

//Bitwise Complement Operator (~)
int x = 5; // 0000 0101
int y = ~x; // 1111 1010 (the two's complement representation of -6)

//Type Cast Operator
double x = 5.5;
int y = (int) x; // y is 5

Special Operators in Java

Java के दो Special Operator हैं जिनका उपयोग कुछ स्थितियों में किया जाता है:

  • Dot operator (.) का उपयोग किसी Class या Object के members तक पहुँचने के लिए किया जाता है.
  • New Operator का उपयोग class का एक नया instance बनाने के लिए किया जाता है.

Example of Dot operator (.):

//example of Dot operator (.)
public class Person {
   private String name;
   private int age;

   public Person(String name, int age) {
      this.name = name;
      this.age = age;
   }

   public String getName() {
      return this.name;
   }

   public int getAge() {
      return this.age;
   }
}

public class Main {
   public static void main(String[] args) {
      Person person = new Person("John Doe", 30);
      System.out.println(person.getName());
      System.out.println(person.getAge());
   }
}

Output

John Doe
30

Example of new Operators in Java:

// Create a new instance of the String class
String myString = new String("Hello, world!");

// Create a new instance of the Random class
Random myRandom = new Random();

// Create a new instance of a custom class called MyClass
MyClass myObject = new MyClass();

Java में Operators का उपयोग values और variables में manipulate करने, program flow को control करने और conditions के आधार पर निर्णय लेने के लिए किया जाता है. विभिन्न प्रकार के Operators को समझना और वे कैसे काम करते हैं, Java programming सीखने का एक essential part है.

ये सब कोड देखकर आपको डरने की कोई जरुरत नहीं है. ये सिर्फ एक example है. आगे आपको सभी कोड के बारे में विस्तार से बताया जाएगा आप हमारे साथ बने रहें.

तो उम्मीद करता हूँ कि आपको हमारा यह पोस्ट “Operators in Java in Hindi” अच्छा लगा होगा. इससे जुड़े हुए और भी पोस्ट आपको देखने को मिलेंगे जो आपको Java सिखने में मदद करेगी. 

आप इसे अपने दोस्तों के साथ शेयर करें और हमें आप FacebookPage, Linkedin, Instagram, और Twitter पर follow कर सकते हैं जहाँ से आपको नए पोस्ट के बारे में पता सबसे पहले चलेगा. हमारे साथ बने रहने के लिए आपका धन्यावाद. जय हिन्द.

  • Java Operators
    Java में, Operator symbols या keyword होते हैं जिनका उपयोग variables या values पर operations करने के लिए किया जाता है.
  • Java Unicode System
    आज की globalized दुनिया में, programming languages के लिए कई languages और character sets का support करना आवश्यक है.
  • Java Virtual Machine (JVM)
    JVM (Java Virtual Machine) एक Abstract machine है जो विभिन्न Hardware और Operating System पर चलने के लिए Java Applications के लिए एक Runtime Environment प्रदान करती है.
  • History Of Java in Hindi
    Java को 1990 के दशक के मध्य में पोर्टेबिलिटी, सुरक्षा और सरलता पर ध्यान देने के साथ सन माइक्रोसिस्टम्स (Sun Microsystems) द्वारा विकसित किया गया था. यह तब से enterprise और web development के लिए एक लोकप्रिय Language बन गई है.
  • Java Data Types
    Java सिखने के इस पोस्ट में हम Java Data Types के बारे में जानेगे कि java में Data Types आखिर किस काम के लिए इस्तेमाल में आता है और इससे जुड़े और भी बहुत कुछ सिखने और जानने को मिलेगा.
  • Java Identifiers
    Java सिखने के इस पोस्ट में हम Java Identifiers के बारे में बात करेंगे और जानेगे कि आखिर ये होता क्या है और इसका java में किस रूप में इस्तेमाल होता है.
  • Java Variable Declaration
    Java सिखने के इस पोस्ट में हम Java Variable Declaration के बारे में जानेंगे. डिक्लेरेशन का मतलब variables को create करने से है.
  • Java Variables
    Java सिखने के इस पोस्ट में हम Java Variables के बारे में समझेंगे और ये भी जानेगे कि इसे कैसे बनाया जाता है.
  • Java Syntax
    इस पोस्ट में हम Java Syntax के बारे में विस्तार से बात करेंगे और जानेगे कि ये कोड सब काम क्या करता है.
  • Hello World Java Program
    इस पोस्ट में हम Hello World को Java Program के माध्यम से बनायेंगे और run करेंगे. ये सबसे बेसिक कोड होता है java का जिससे आप java के बेसिक rules को जानेंगे. Also Read: Java Introduction Also Read: Installation of Java Hello World Java Program Java में, प्रत्येक एप्लिकेशन एक class name से शुरू होता… Read more: Hello World Java Program

Leave a Reply