Classification by Arity
- Unary: Operates on a single operand.
- Binary: Operates on two operands.
- Ternary: Operates on three operands.
Operator Categories and Syntax
Unary Operators
Require a single operand. While all are unary by arity, they are distinguished by their syntax position (postfix vs. prefix) and precedence level. Postfix operators associate left-to-right, while prefix and other unary operators associate right-to-left.| Operator | Description |
|---|---|
expr++, expr-- | Post-increment / Post-decrement (evaluates, then mutates) |
++expr, --expr | Pre-increment / Pre-decrement (mutates, then evaluates) |
+expr, -expr | Unary plus (promotes type) / Unary minus (arithmetic negation) |
!expr | Logical complement (inverts boolean value) |
~expr | Bitwise complement (inverts bits of integer types) |
(Type) | Type cast (explicitly converts operand to specified type) |
Arithmetic Operators
Perform standard mathematical computations. While they primarily operate on numeric types, the additive operator (+) is overloaded for String concatenation. If at least one operand is a String, the + operator converts the other operand to a String and concatenates them.
| Operator | Description |
|---|---|
+, - | Addition (or String concatenation) / Subtraction |
*, /, % | Multiplication / Division / Modulo (Remainder) |
Relational and Equality Operators
Evaluate the magnitude or equivalence relationship between two operands, strictly returning aboolean value.
| Operator | Description |
|---|---|
>, >=, <, <= | Greater than / Greater than or equal to / Less than / Less than or equal to |
==, != | Equal to / Not equal to |
Logical Operators
Perform Boolean logic operations. The conditional operators (&&, ||) exhibit short-circuiting behavior, meaning the second operand is not evaluated if the first operand determines the overall result.
| Operator | Description | ||
|---|---|---|---|
&&, ` | ` | Conditional-AND / Conditional-OR (Short-circuiting) | |
&, ` | ` | Boolean logical AND / OR (Non-short-circuiting) | |
^ | Boolean logical exclusive OR (XOR) |
Bitwise and Bit Shift Operators
Operate directly on the binary representations of integer types (byte, short, int, long, char).
| Operator | Description | |
|---|---|---|
&, ` | , ^` | Bitwise AND / Inclusive OR / Exclusive OR |
<< | Signed left shift (shifts bits left, fills with 0) | |
>> | Signed right shift (shifts bits right, preserves sign bit) | |
>>> | Unsigned right shift (shifts bits right, fills with 0) |
Assignment Operators
Assign the evaluated value of the right operand to the left operand. Compound assignment operators perform the specified operation and an implicit type cast to the type of the left-hand variable.| Operator | Description | |
|---|---|---|
= | Simple assignment | |
+=, -=, *=, /=, %= | Arithmetic compound assignment | |
&=, ` | =, ^=, <code><<=</code>, >>=, >>>=` | Bitwise/Shift compound assignment |
Ternary Operator
The only operator in Java that takes three operands. It evaluates a boolean condition and returns one of two expressions based on the result.| Operator | Description |
|---|---|
? : | condition ? exprIfTrue : exprIfFalse |
Type Comparison Operator (instanceof)
A binary operator that evaluates whether an object reference is an instance of a specific class, superclass, or interface, returning a boolean. As of Java 16, Pattern Matching for instanceof allows declaring a binding variable directly within the evaluation, eliminating the need for an explicit cast.
| Operator | Description |
|---|---|
instanceof | Type comparison and optional pattern matching |
Precedence and Associativity
When an expression contains multiple operators, precedence dictates the order of evaluation. Operators with higher precedence are evaluated before those with lower precedence. When operators of the same precedence appear in the same expression, associativity determines the evaluation direction:- Right-to-Left: Applies to prefix Unary, Ternary, and Assignment operators.
- Left-to-Right: Applies to postfix Unary operators and all other binary operators.
- Postfix (
expr++,expr--) - Unary (
++expr,--expr,+expr,-expr,~,!,(Type)) - Multiplicative (
*,/,%) - Additive (
+,-) - Shift (
<<,>>,>>>) - Relational (
<,>,<=,>=,instanceof) - Equality (
==,!=) - Bitwise AND (
&) - Bitwise XOR (
^) - Bitwise OR (
|) - Logical AND (
&&) - Logical OR (
||) - Ternary (
? :) - Assignment (
=,+=,-=, etc.)
Tired of Poor Java Skills? Fix That With Deep Grasping!Learn More





