Java Operators

The following operators can be used in Java programs

Arithmetic operators

Operator Meaning Example
* Multiply As for normal multiplication
/ Division As for normal division. If destination variable is int then integer division
% Modulo Returns the integer remainder of division: 21%5 = 1
+ Addition As for normal addition
- Subtraction As for normal subtraction
x++ Increment Increase the integer x by 1: 5++ = 6
x Decrement Decrease the integer x by 1: 5— = 4

Comparison operators

Operator Meaning
> Greater than
< Less than
== Equal to
!= Not equal to
<= Less than or equal to
>= Greater than or equal to

Logical (Boolean) operators

! NOT
| | Short circuit OR
&& Short circuit AND
== EQUALS
!= NOT EQUALS

Bitwise (flags) operators

Operator Meaning
| OR
& AND
^ XOR
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License