Header Ads

Operators in Java

 Operators in Java

Operators are symbols or special characters that perform various operations on operands (variables, values, or expressions) in Java programming. They allow you to manipulate and combine data to perform calculations, comparisons, assignments, and other operations. Java supports a wide range of operators, which can be categorized into different types based on their functionality.

1. Arithmetic Operators:

Arithmetic operators are used to perform basic arithmetic operations such as addition, subtraction, multiplication, division, and modulus (remainder). The common arithmetic operators in Java include:

- Addition (+): Adds two operands.

- Subtraction (-): Subtracts the second operand from the first operand.

- Multiplication (*): Multiplies two operands.

- Division (/): Divides the first operand by the second operand.

- Modulus (%): Returns the remainder of the division operation.


2. Relational Operators:

Relational operators are used to compare values and determine the relationship between operands. These operators return a boolean value (true or false) based on the comparison result. Common relational operators in Java include:

- Equal to (==): Checks if two operands are equal.

- Not equal to (!=): Checks if two operands are not equal.

- Greater than (>): Checks if the left operand is greater than the right operand.

- Less than (<): Checks if the left operand is less than the right operand.

- Greater than or equal to (>=): Checks if the left operand is greater than or equal to the right operand.

- Less than or equal to (<=): Checks if the left operand is less than or equal to the right operand.


3. Logical Operators:

Logical operators are used to perform logical operations on boolean values. They allow you to combine multiple conditions and evaluate the overall result. Common logical operators in Java include:

- Logical AND (&&): Returns true if both operands are true.

- Logical OR (||): Returns true if either of the operands is true.

- Logical NOT (!): Negates the boolean value of the operand.


4. Assignment Operators:

Assignment operators are used to assign values to variables. They combine the assignment operation with other operations. Common assignment operators in Java include:

- Assignment (=): Assigns the value of the right operand to the left operand.

- Addition assignment (+=): Adds the right operand to the left operand and assigns the result to the left operand.

- Subtraction assignment (-=): Subtracts the right operand from the left operand and assigns the result to the left operand.

- Multiplication assignment (*=): Multiplies the left operand by the right operand and assigns the result to the left operand.

- Division assignment (/=): Divides the left operand by the right operand and assigns the result to the left operand.

These are just a few examples of the operators available in Java. Java also supports other types of operators such as bitwise operators, ternary operator, and more. Understanding and using operators effectively is essential for performing calculations, making decisions, and manipulating data in Java programs.

हिंदी:

ऑपरेटर जावा प्रोग्रामिंग में प्रयोग होने वाले चिन्ह या विशेष वर्ण होते हैं, जो ऑपरेंड (चर, मान या अभिव्यक्ति) पर विभिन्न परिचालनों को कार्यान्वित करते हैं। ये आपको डेटा को संशोधित और संयोजित करने के लिए, गणनाओं, तुलनाओं, कार्यान्वयन और अन्य परिचालनों को कार्यान्वित करने की अनुमति देते हैं। जावा में कई प्रकार के ऑपरेटर समर्थित किए गए हैं, जो उनके कार्यान्वयन की क्षमता के आधार पर विभाजित किए जा सकते हैं।

1. अंकगणितीय ऑपरेटर:

अंकगणितीय ऑपरेटर बुनियादी अंकगणितीय परिचालनों को कार्यान्वित करने के लिए प्रयोग होते हैं, जैसे जोड़, घटाव, गुणा, भाग और शेष (शेषभाग)। जावा में सामान्य अंकगणितीय ऑपरेटर शामिल हैं:

- जोड़ (+): दो ऑपरेंड को जोड़ता है।

- घटाव (-): पहले ऑपरेंड से दूसरे ऑपरेंड को कम करता है।

- गुणा (*): दो ऑपरेंडों को गुणा करता है।

- भाग (/): पहले ऑपरेंड को दूसरे ऑपरेंड से भाग करता है।

- शेषभाग (%): भाग कार्यान्वयन के शेष को लौटाता है।


2. संबंधीय ऑपरेटर:

संबंधीय ऑपरेटरों का उपयोग मानों की तुलना करने और ऑपरेंड के बीच संबंध निर्धारित करने के लिए किया जाता है। ये ऑपरेटर प्रामाणिक परिणाम के आधार पर एक बूलियन मान (सच या झूठ) लौटाते हैं। जावा में सामान्य संबंधीय ऑपरेटर शामिल हैं:

- बराबर (==): दो ऑपरेंड समान हैं या नहीं, यह जांचता है।

- असमान (!=): दो ऑपरेंड समान नहीं हैं, यह जांचता है।

- अधिक (>): बाएं ऑपरेंड दाएं ऑपरेंड से अधिक है या नहीं, यह जांचता है।

- कम (<): बाएं ऑपरेंड दाएं ऑपरेंड से कम है या नहीं, यह जांचता है।

- अधिकतम या बराबर (>=): बाएं ऑपरेंड दाएं ऑपरेंड से अधिक या बराबर है या नहीं, यह जांचता है।

- कमतर या बराबर (<=): बाएं ऑपरेंड दाएं ऑपरेंड से कमतर या बराबर है या नहीं, यह जांचता है।


3. तार्किक ऑपरेटर:

तार्किक ऑपरेटर बूलियन मानों पर तार्किक परिचालन करने के लिए प्रयोग होते हैं। ये आपको कई शर्तों को संयोजित करने और समग्र परिणाम का मूल्यांकन करने की अनुमति देते हैं। जावा में सामान्य तार्किक ऑपरेटर शामिल हैं:

- तार्किक और (&&): दो ऑपरेंड सच हैं या नहीं, यह जांचता है।

- तार्किक या (||): दो ऑपरेंडों में से कोई एक सच है या नहीं, यह जांचता है।

- तार्किक नहीं (!): ऑपरेंड के बूलियन मान को उलटा करता है।


4. सौंपन ऑपरेटर:

सौंपन ऑपरेटर वेरिएबल्स को मान देने के लिए प्रयोग होते हैं। इन ऑपरेटर्स का उपयोग सौंपन ऑपरेशन को अन्य परिचालनों के साथ मिलाता है। जावा में सामान्य सौंपन ऑपरेटर्स शामिल हैं:

- सौंपन (=): दाएं ऑपरेंड की मान को बाएं ऑपरेंड को सौंपता है।

- जोड़ सौंपन (+=): दाएं ऑपरेंड को बाएं ऑपरेंड में जोड़ता है और परिणाम को बाएं ऑपरेंड को सौंपता है।

- घटाव सौंपन (-=): दाएं ऑपरेंड को बाएं ऑपरेंड से कम करता है और परिणाम को बाएं ऑपरेंड को सौंपता है।

- गुणा सौंपन (*=): दाएं ऑपरेंड को बाएं ऑपरेंड से गुणा करता है और परिणाम को बाएं ऑपरेंड को सौंपता है।

- भाग सौंपन (/=): दाएं ऑपरेंड को बाएं ऑपरेंड से भाग करता है और परिणाम को बाएं ऑपरेंड को सौंपता है।

ये केवल कुछ उदाहरण हैं जो जावा में उपलब्ध ऑपरेटर्स के बारे में हैं। जावा में और भी प्रकार के ऑपरेटर्स समर्थित होते हैं जैसे कि बिटवाइज ऑपरेटर्स, टर्नरी ऑपरेटर और अन्य। ऑपरेटर्स को समझना और सक्रिय रूप से उपयोग करना जावा प्रोग्रामों में गणना, निर्णय लेने और डेटा को परिवर्तित करने के लिए महत्वपूर्ण है।

No comments

Powered by Blogger.