A working reference for the symbols that make Java code compute — with a closer look at bit-shifting and the ternary shortcut, worked out like they'd run in a console.
Standard math on numeric values.
| Op | Meaning | Example | Result |
|---|---|---|---|
| + | Addition | 5 + 3 | 8 |
| - | Subtraction | 5 - 3 | 2 |
| * | Multiplication | 5 * 3 | 15 |
| / | Division | 5 / 2 | 2 (int) |
| % | Modulus | 5 % 2 | 1 |
Store or update a value in a variable.
| Op | Meaning | Equivalent to |
|---|---|---|
| = | Assign | x = 5 |
| += | Add & assign | x = x + 3 |
| -= | Subtract & assign | x = x - 3 |
| *= | Multiply & assign | x = x * 3 |
| /= | Divide & assign | x = x / 3 |
| %= | Modulus & assign | x = x % 3 |
Compare two values; always evaluate to a boolean.
| Op | Meaning |
|---|---|
| == | Equal to |
| != | Not equal to |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| <= | Less than or equal to |
.equals() to compare object content (like Strings) — == on objects compares references, not values.Combine boolean expressions.
| Op | Meaning |
|---|---|
| && | Logical AND (short-circuits) |
| || | Logical OR (short-circuits) |
| ! | Logical NOT |
Act on a single operand.
| Op | Meaning |
|---|---|
| + / - | Unary plus / minus |
| ++ | Increment (pre or post) |
| -- | Decrement (pre or post) |
| ! | Logical NOT |
Operate directly on the binary representation of integers.
| Op | Meaning |
|---|---|
| & | Bitwise AND |
| | | Bitwise OR |
| ^ | Bitwise XOR |
| ~ | Bitwise complement |
| << | Left shift — covered below |
| >> | Right shift — covered below |
| >>> | Unsigned right shift |
<<Shifts every bit to the left by n places, filling the vacated positions on the right with zero. Each left shift by one place doubles the value — it's the bitwise equivalent of multiplying by 2ⁿ.
>>Shifts every bit to the right by n places, refilling from the left with the sign bit (0 for positive numbers, 1 for negative). It's the bitwise equivalent of dividing by 2ⁿ, rounding toward negative infinity.
>> is an arithmetic shift and preserves the sign of negative numbers. If you need the vacated bits filled with 0 regardless of sign, use the unsigned right shift >>> instead.?:A compact stand-in for an if-else statement that returns a value in a single expression: condition ? valueIfTrue : valueIfFalse.
grade above) works, but keep it to one or two levels — beyond that, an if-else chain reads far more clearly.When an expression mixes several operators, Java doesn't evaluate left to right — it follows a fixed pecking order. Higher rows bind tighter and run first; operators on the same row run according to their associativity.
| Rank | Operators | Category | Associativity |
|---|---|---|---|
| 1 | expr++ expr-- | Postfix | Left → Right |
| 2 | ++expr --expr +expr -expr ! ~ | Unary | Right → Left |
| 3 | * / % | Multiplicative | Left → Right |
| 4 | + - | Additive | Left → Right |
| 5 | << >> >>> | Shift | Left → Right |
| 6 | < > <= >= | Relational | Left → Right |
| 7 | == != | Equality | Left → Right |
| 8 | & | Bitwise AND | Left → Right |
| 9 | ^ | Bitwise XOR | Left → Right |
| 10 | | | Bitwise OR | Left → Right |
| 11 | && | Logical AND | Left → Right |
| 12 | || | Logical OR | Left → Right |
| 13 | ? : | Ternary | Right → Left |
| 14 | = += -= *= /= %= &= ^= |= <<= >>= >>>= | Assignment | Right → Left |
x = y = 5 works — the rightmost assignment happens first, then its result feeds the next one going left.