Java operators
Operators are special symbols that perform specific operations on operands, and then return a result. The following are the operators supported by the Java programming language:
A simple assignment operator
=
: A simple assignment operator
Arithmetic operators
+
: An additive operator (also used for string concatenation)-
: The subtraction operator*
: The multiplication operator/
: The division operator%
: The remainder operator
Unary operators
+
: 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 value
Equality and relational operators
==
: Equals to!=
: Not equal to>
: Greater than>=
: Greater than or equal to<
: Less than<=
: Less than or equal to
Conditional operators
&&
: Conditional AND operator||
: Conditional OR operator?
: Ternary operator
Type comparison operator
instanceof
: This compares an object to a specified type
Bitwise and bit shift operators
~
: Unary bitwise complement<<
: Signed left shift>>
: Signed right shift>>>
: Unsigned right shift&
: Bitwise AND^
: Bitwise exclusive OR|
: Bitwise inclusive OR
Operator precedence
The operators in the following table are listed according to the precedence order. Operators with higher precedence are evaluated before operators with relatively lower precedence. Operators on the same line have equal precedence.
Precedence |
Name |
Operators |
Associativity |
---|---|---|---|
1 |
postfix |
|
Right to Left |
2 |
unary |
|
Right to Left |
3 |
multiplicative |
|
Left to Right |
4 |
additive |
|
Left to Right |
5 |
shift |
|
Left to Right |
6 |
relational |
|
Left to Right |
7 |
equality |
|
Left to Right |
8 |
bitwise AND |
|
Left to Right |
9 |
bitwise exclusive OR |
|
Left to Right |
10 |
bitwise inclusive OR |
|
Left to Right |
11 |
logical AND |
|
Left to Right |
12 |
logical OR |
|
Left to Right |
13 |
ternary |
|
Right to Left |
14 |
assignment |
|
Right to Left |
Note
Reference link for Java operators
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html