A. Classification by Operand Count:
- Unary Operators: Operate on a single operand. (e.g., Unary plus
+a, Unary minus-a, Increment++a, Decrement--a, Logical NOT!flag). - Binary Operators: Operate on two operands. (e.g., Addition
a + b, Multiplicationa * b, Equalitya == b, Logical ANDa && b). - Ternary Operator: Operates on three operands. In Java, there is only one ternary operator: the Conditional Operator (
condition ? expr1 : expr2).
B. Arithmetic Operators (The Calculation Engine):
| Operator | Operation | Behavior with Integers | Behavior with Floating-Point |
|---|---|---|---|
+ | Addition | 10 + 4 = 14 | 10.5 + 4.2 = 14.7 (Also String Concatenation) |
- | Subtraction | 10 - 4 = 6 | 10.5 - 4.0 = 6.5 |
* | Multiplication | 10 * 4 = 40 | 2.5 * 4.0 = 10.0 |
/ | Division | 10 / 4 = 2 (Fractional truncated!) | 10.0 / 4 = 2.5 (True decimal division) |
% | Modulus (Remainder) | 10 % 4 = 2 | 10.5 % 4.0 = 2.5 |
Modulus Sign Rule: The result of a % b always carries the algebraic sign of the numerator (first operand): -10 % 3 = -1; 10 % -3 = 1; -10 % -3 = -1.