Tutorials

# Relational Operators

Relational operators are used to compare two expressions.

The relational operation returns a Boolean value as result that can be either true or false.

The relational operators used in java and their behaviour is shown in chart below:

 Relational Operators Meaning Example Output == Equal 8==5 5==5 False True != Not equal to 5!=3 3!=3 True False > Greater than 6>4 4>6 True False < Less than 5<5 4<5 False True >= Greater than or equal than 7>=7 True <= Less than or equal to 10<=6 6<=6 False True

### = vs ==. Are they different or same?

= and == are not same.

Assignment operator (=)

It is an assignment operator. Using = we assign value to a variable.

For example, i=9;

Here we are assigning value 9 to variable i.

Equality operator (==)

It is an equality operator. Using ==, we compare if the two different expressions are equal to each other or not.

If they are equal, boolean value true is returned else false is returned.

For example,

9==9 → true

7==9 → false