6/4/2021 Java - Basic Operators - Tutorialspoint
Java - Basic Operators
Java provides a rich set of operators to manipulate variables. We can divide all the Java operators
into the following groups −
Arithmetic Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Misc Operators
The Arithmetic Operators
Arithmetic operators are used in mathematical expressions in the same way that they are used in
algebra. The following table lists the arithmetic operators −
Assume integer variable A holds 10 and variable B holds 20, then −
Show Examples
Operator Description Example
Adds values on either side of the
+ (Addition) A + B will give 30
operator.
Subtracts right-hand operand from
- (Subtraction) A - B will give -10
left-hand operand.
Multiplies values on either side of the
* (Multiplication) A * B will give 200
operator.
Divides left-hand operand by right-
/ (Division) B / A will give 2
hand operand.
Divides left-hand operand by right-
% (Modulus) B % A will give 0
hand operand and returns remainder.
++ (Increment) Increases the value of operand by 1. B++ gives 21
-- (Decrement) Decreases the value of operand by 1. B-- gives 19
https://www.tutorialspoint.com/java/java_basic_operators.htm 1/8
, 6/4/2021 Java - Basic Operators - Tutorialspoint
The Relational Operators
There are following relational operators supported by Java language.
Assume variable A holds 10 and variable B holds 20, then −
Show Examples
Operator Description Example
Checks if the values of two operands are
== (equal to) equal or not, if yes then condition becomes (A == B) is not true.
true.
Checks if the values of two operands are
!= (not equal to) equal or not, if values are not equal then (A != B) is true.
condition becomes true.
Checks if the value of left operand is greater
> (greater than) than the value of right operand, if yes then (A > B) is not true.
condition becomes true.
Checks if the value of left operand is less
< (less than) than the value of right operand, if yes then (A < B) is true.
condition becomes true.
Checks if the value of left operand is greater
>= (greater than or
than or equal to the value of right operand, if (A >= B) is not true.
equal to)
yes then condition becomes true.
Checks if the value of left operand is less
<= (less than or
than or equal to the value of right operand, if (A <= B) is true.
equal to)
yes then condition becomes true.
The Bitwise Operators
Java defines several bitwise operators, which can be applied to the integer types, long, int, short,
char, and byte.
Bitwise operator works on bits and performs bit-by-bit operation. Assume if a = 60 and b = 13; now
in binary format they will be as follows −
a = 0011 1100
b = 0000 1101
-----------------
a&b = 0000 1100
https://www.tutorialspoint.com/java/java_basic_operators.htm 2/8
Java - Basic Operators
Java provides a rich set of operators to manipulate variables. We can divide all the Java operators
into the following groups −
Arithmetic Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Misc Operators
The Arithmetic Operators
Arithmetic operators are used in mathematical expressions in the same way that they are used in
algebra. The following table lists the arithmetic operators −
Assume integer variable A holds 10 and variable B holds 20, then −
Show Examples
Operator Description Example
Adds values on either side of the
+ (Addition) A + B will give 30
operator.
Subtracts right-hand operand from
- (Subtraction) A - B will give -10
left-hand operand.
Multiplies values on either side of the
* (Multiplication) A * B will give 200
operator.
Divides left-hand operand by right-
/ (Division) B / A will give 2
hand operand.
Divides left-hand operand by right-
% (Modulus) B % A will give 0
hand operand and returns remainder.
++ (Increment) Increases the value of operand by 1. B++ gives 21
-- (Decrement) Decreases the value of operand by 1. B-- gives 19
https://www.tutorialspoint.com/java/java_basic_operators.htm 1/8
, 6/4/2021 Java - Basic Operators - Tutorialspoint
The Relational Operators
There are following relational operators supported by Java language.
Assume variable A holds 10 and variable B holds 20, then −
Show Examples
Operator Description Example
Checks if the values of two operands are
== (equal to) equal or not, if yes then condition becomes (A == B) is not true.
true.
Checks if the values of two operands are
!= (not equal to) equal or not, if values are not equal then (A != B) is true.
condition becomes true.
Checks if the value of left operand is greater
> (greater than) than the value of right operand, if yes then (A > B) is not true.
condition becomes true.
Checks if the value of left operand is less
< (less than) than the value of right operand, if yes then (A < B) is true.
condition becomes true.
Checks if the value of left operand is greater
>= (greater than or
than or equal to the value of right operand, if (A >= B) is not true.
equal to)
yes then condition becomes true.
Checks if the value of left operand is less
<= (less than or
than or equal to the value of right operand, if (A <= B) is true.
equal to)
yes then condition becomes true.
The Bitwise Operators
Java defines several bitwise operators, which can be applied to the integer types, long, int, short,
char, and byte.
Bitwise operator works on bits and performs bit-by-bit operation. Assume if a = 60 and b = 13; now
in binary format they will be as follows −
a = 0011 1100
b = 0000 1101
-----------------
a&b = 0000 1100
https://www.tutorialspoint.com/java/java_basic_operators.htm 2/8