Java Operators
Operators are symbols that do operations to variables and values.
Java operators are classified into five types:
- Arithmetic Operators
- Assignment operators
- Comparison operators
- Logical operators
- Bitwise operators
Arithmetic Operators
Arithmetic operators are employed to execute mathematical operations.
Operator | Description | Syntax |
---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulus | a % b |
Assignment operators
Assignment operators are utilized to assign values to a variable.
Operator | Name | Syntax |
---|---|---|
= | Assignment | a = b |
+= | Addition assignment | a += b |
-= | Subtraction assignment | a -= b |
*= | Multiplication assignment | a *= b |
/= | Division assignment | a /= b |
%= | Modulus assignment | a %= b |
Comparison operators
Comparison operators are applied to compare two values.
Operator | Description | Example |
---|---|---|
== | Equal | a==b |
!= | Not Equal | a!=b |
> | Greater than | a>b |
>= | Greater than or equal to | a >= b |
<< /td> | Less than | a < b |
<=< /td> | Less than or equal to | a <= b |
Logical operators
Logical operators conduct logical operations and produce a Boolean result.
Operator | Description | Example |
---|---|---|
&& | Logical AND | a && b |
|| | Logical OR | a || b |
! | Logical NOT | ! (a=2 or b=3) |
Bitwise operators
Bitwise operators are applied in addressing binary operations.
Operator | Description | Example |
---|---|---|
& | Bitwise AND | a & b |
| | Bitwise OR | a | b |
~ | Bitwise NOT | ~a |
^ | Bitwise XOR | a ^ b |