Understanding Operators, Operands, and Expressions
Operators
Special symbols that perform operations on operands (e.g., + in 5 + 3). Operands
Entities on which operators act (e.g., 5 and 3 in 5 + 3). Expressions
Combinations of operators and operands that produce a result (e.g., a + b - c). Key Operators in Java
Arithmetic Operators
Perform basic math operations: +, -, *, /, %. Assignment Operators
Assign values to variables: =, +=, -=, etc. Unary Operators
Operate on a single operand: ++, --. Comparison Operators
Compare two values: ==, !=, >, <. Logical Operators
Combine boolean expressions: &&, ||, !. Bitwise Operators
Operate on binary representations: &, |, ^, ~. Arithmetic, Assignment, and Unary Operators
Addition and Subtraction
int addResult = num1 + num2; int subResult = num1 - num2; Modulus Operator
int modResult = num1 % num2; Assignment Operators
Unary Operators
Comparison and Logical Operators
Comparison Operators
Logical Operators
x < 5 && x > 2; // Logical AND x < 5 || x > 2; // Logical OR !(x == y); // Logical NOT Bitwise Operators
Bitwise AND (&)
int c = a & b; // Binary: 0101 & 0011 = 0001 Bitwise OR (|)
int c = a | b; // Binary: 0101 | 0011 = 0111 Bitwise XOR (^)
int c = a ^ b; // Binary: 0101 ^ 0011 = 0110 Bitwise NOT (~)
int d = ~a; // Binary: ~0101 = 1010 (two's complement) Bitwise Left Shift (<<)
int b = a << 1; // Binary: 0101 << 1 = 1010 Bitwise Right Shift (>>)
int b = a >> 1; // Binary: 0101 >> 1 = 0010 Operator Precedence
Operator precedence determines the order in which operators are evaluated in an expression, similar to BODMAS in mathematics.
Example
int result = 20 - 3 * 2 + 8 / 2; // Evaluates to 18
Multiplication and division first: 3 * 2 = 6, 8 / 2 = 4 Then addition and subtraction: 20 - 6 + 4 = 18
These concepts of Operators In Java are very useful for understanding core Java. For more detailed information, refer to the Notion link: