= // Simple assignment operator
+ // Additive operator (also used for strings concatenation) - // Subtraction operator * // Multiplication operator / // Division operator % // Remainder operator (Modulo operator)
+ // Unary plus operator; indicates positive value - // Unary minus operator; negates an expression ++ // Increment operator; increments a value by 1 -- // Decrement operator; decrements a value by 1 ! // Logical complement operator; inverts the value of a boolean
== // Equal to != // Not equal to > // Greater than >= // Greater than or equal to < // Less than <= // Less than or equal to
&& // Conditional-AND (short-circuit evaluation) || // Conditional-OR (short-circuit evaluation) ?: // Ternary (shorthand for if-then-else statement)
~ // Unary bitwise complement & // Bitwise AND (always evaluate both sides) | // Bitwise inclusive OR (always evaluate both sides) ^ // Bitwise exclusive OR (always evaluate both sides)Java Samples:
final byte b1 = 0; // 0: (0) 0000000 final byte b1_ = ~b1; // -1: (1) 1111111 final byte b1__ = ~b1_; // 0: (0) 0000000 final byte b2 = 1; // 1: (0) 0000001 final byte b2_ = ~b2; // -2: (1) 1111110 final byte b2__ = ~b2_; // 1: (0) 0000001 final byte b3 = 127; // 127: (0) 1111111 final byte b3_ = ~b3; // -128: (1) 0000000 final byte b3__ = ~b3_; // 127: (0) 1111111
System.out.println("1 & 1: " + (1 & 1)); // output: 1 & 1: 1 System.out.println("1 & 0: " + (1 & 0)); // output: 1 & 0: 0 System.out.println("0 & 1: " + (0 & 1)); // output: 0 & 1: 0 System.out.println("0 & 0: " + (0 & 0)); // output: 0 & 0: 0
System.out.println("1 | 1: " + (1 | 1)); // output: 1 | 1: 1 System.out.println("1 | 0: " + (1 | 0)); // output: 1 | 0: 1 System.out.println("0 | 1: " + (0 | 1)); // output: 0 | 1: 1 System.out.println("0 | 0: " + (0 | 0)); // output: 0 | 0: 0
System.out.println("1 ^ 1: " + (1 ^ 1)); // output: 1 ^ 1: 0 System.out.println("1 ^ 0: " + (1 ^ 0)); // output: 1 ^ 0: 1 System.out.println("0 ^ 1: " + (0 ^ 1)); // output: 0 ^ 1: 1 System.out.println("0 ^ 0: " + (0 ^ 0)); // output: 0 ^ 0: 0
<< // Left shift <<= // Left shift assignment >> // Signed right shift >>= // Signed right shift assignment >>> // Unsigned right shift >>>= // Unsigned right shift assignmentJava Samples:
final byte b1 = 1; // 1: (0) 0000001 final byte b1_ = b1 << 1; // 2: (0) 0000010 final byte b1__ = b1 << 2; // 4: (0) 0000100
final byte b1 = -1; // -1: (1) 1111111 final byte b1_ = b1 << 1; // -2: (1) 1111110 final byte b1__ = b1 << 2; // -4: (1) 1111100
final int b1 = 1; b1 <<= 1; // Equivalent to: b1 = b1 << 1;
final byte b1 = 1; // 1: (0) 0000001 final byte b1_ = b1 >> 1; // 0: (0) 0000000 final byte b2 = 2; // 2: (0) 0000010 final byte b2_ = b2 >> 1; // 1: (0) 0000001 final byte b3 = 4; // 4: (0) 0000100 final byte b3_ = b3 >> 1; // 2: (0) 0000010
final byte b1 = -2; // -2: (1) 1111110 final byte b1_ = b1 >> 1; // -1: (1) 1111111 final byte b2 = -4; // -4: (1) 1111100 final byte b2_ = b2 >> 1; // -2: (1) 1111110 final byte b3 = -8; // -8: (1) 1111000 final byte b3_ = b3 >> 1; // -4: (1) 1111100
final int b1 = 1; b1 >>= 1; // Equivalent to: b1 = b1 >> 1;
final byte b1 = 8; // 1: (0) 0001000 final byte b1_ = b1 >>> 1; // 2: (0) 0000100 final byte b1__ = b1 >>> 2; // 4: (0) 0000010
final int b2 = -8; // 1: (1) 1111111111111111111111111111000 final int b2_ = b2 >>> 1; // 2147483644: (0) 1111111111111111111111111111100 final int b2__ = b2 >>> 2; // 1073741822: (0) 0111111111111111111111111111110
final int b1 = 1; b1 >>>= 1; // Equivalent to: b1 = b1 >>> 1;
instanceof // Compares an object to a specified type
x = a / b * c
can be written x = (a / b) * c
a += b -= c
can be written a += (b -= c)
Operator | Description | Associativity |
---|---|---|
[] . ()
|
Array element access Object member access Method call |
Left to right |
++ -- |
Post increment Post decrement |
|
! ~ ++ -- + - () new
|
Logical NOT Bitwise NOT Pre increment Pre decrement Unary plus Unary minus Cast Instantiation |
Right to left |
* / %
|
Multiplication Division Remainder |
Left to right |
+ - +
|
Additive Subtraction String concatenation |
Left to right |
<< >> >>>
|
Signed left shift Signed right shift Unsigned right shift |
Left to right |
< <= > >= instanceof
|
Less than Less than or equal to Greater than Greater than or equal to Type Comparison |
Left to right |
== !=
|
Equal to Not equal to |
Left to right |
& |
Bitwise AND | Left to right |
^ |
Bitwise XOR | Left to right |
| |
Bitwise OR | Left to right |
&& |
Conditional AND | Left to right |
|| |
Conditional OR | Left to right |
?: |
Ternary | Right to left |
= += -= *= /= %= &= |= ^= <<= >>= >>>=
|
Right to left |