← Back to Core Java Course | Chapter 3: Operators | Lesson 1 of 9

Java के Operators

Operators special symbols हैं जो एक या ज़्यादा operands पर act करके एक नई value produce करते हैं, और Java उन्हें वे किस तरह का result produce करते हैं इसके आधार पर arithmetic, relational, और logical जैसी categories में group करता है।
Syntax
java
result = operand1 operator operand2;

What are Operators?

एक operator एक special symbol है जो एक या ज़्यादा values पर, operands कहलाती हैं, एक operation perform करता है, एक नई value produce करते हुए -- + symbol, उदाहरण के लिए, एक operator है जो दो numeric operands को एक साथ जोड़ता है।

उदाहरण: What are Operators?

java
public class Main {
	public static void main(String[] args) {
		int result = 5 + 3; // '+' is the operator, 5 and 3 are the operands
		System.out.println(result);
	}
}

Categories of Operators

Java operators को इस आधार पर categories में group करता है कि वे किस तरह का result produce करते हैं: arithmetic operators numbers compute करते हैं, relational operators values compare करते हैं और booleans produce करते हैं, और logical operators boolean values combine करते हैं।

उदाहरण: Categories of Operators

java
public class Main {
	public static void main(String[] args) {
		int sum = 5 + 3;          // arithmetic -> number
		boolean isBigger = 5 > 3; // relational -> boolean
		boolean both = true && isBigger; // logical -> boolean
		System.out.println(sum + " " + isBigger + " " + both);
	}
}

Operators and Operands

हर operator operands पर act करता है -- + और * जैसे ज़्यादातर operators binary हैं और दो operands चाहते हैं, जबकि ++ और unary - जैसे कुछ unary हैं और सिर्फ एक single operand पर act करते हैं।

उदाहरण: Operators and Operands

java
public class Main {
	public static void main(String[] args) {
		int a = 5, b = 3;
		int sum = a + b;   // binary - needs two operands
		int negative = -a; // unary - needs just one operand
		System.out.println(sum + " " + negative);
	}
}

Combining Operators in Expressions

अलग-अलग categories के operators अक्सर एक single expression में combined होते हैं, जैसे एक condition बनाने के लिए arithmetic और relational operators mix करना, या एक result compute और store करने के लिए arithmetic और assignment operators।

उदाहरण: Combining Operators in Expressions

java
public class Main {
	public static void main(String[] args) {
		int total = 5;
		total += 3;                  // arithmetic + assignment combined
		boolean valid = total > 5 && total < 20; // relational + logical combined
		System.out.println(total + " " + valid);
	}
}

Operator Precedence Preview

जब एक expression कई operators mix करता है, Java उन्हें एक fixed precedence order के अनुसार evaluate करता है -- multiplication और division default रूप से addition और subtraction से पहले चलते हैं, और parentheses हमेशा उस default order को override कर सकते हैं।

उदाहरण: Operator Precedence Preview

java
public class Main {
	public static void main(String[] args) {
		int result = 2 + 3 * 4;   // multiplication runs first: 2 + 12 = 14
		int forced = (2 + 3) * 4; // parentheses override: 5 * 4 = 20
		System.out.println(result + " " + forced);
	}
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. = (assignment) को == (comparison) के साथ confuse करना।
  2. यह मान लेना कि integers पर / एक decimal result देता है, जब 7 / 2 3 है।
  3. Precedence नज़रअंदाज़ करना, इसलिए 2 + 3 * 4 14 है, 20 नहीं; clear होने के लिए parentheses उपयोग करें।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.