Relational operators in Java

(Last Updated On: February 25, 2019)

Relational operators in java language e.g. equal, greater than or less than etc. are used to check the relationship between two variables or expressions. It is also known as comparison operators in java programming.

For example,

If int a =10 and int b =20;
Then, we car write a relation ship as a == b to check if a and b are equal.

Or as , a > = b; to check if a is >= b etc.

NOTE: All Relational operators returns Boolean value. E.g. considering above value of a and b, the expression, a == b, returns false, as a is 10 and b=20.


List of relational operators in java language.

= = Equal to, e.g. a == b;

> Greater than e.g. a > b;

< Less that e.g. a < b;

> = Greater than or equal to. E.g. a >= b;

< = Less than or equal to. E.g. a <=b;

!= Not equal to. E.g. a != b;


Relational Operators Example in Java

Uses of all relational operators are shown by java program example. All expressions using relational operators returns true or false as an output.

a == b :false
a > b :false
a < b :true a >= b :false
a <= b :true
a != b :true