Java - Relational Operators

Java provides operators that can be used to check the relationship between values or values within variables also known as operands.

All relational operators, less than(<), less than or equal to(<=), greater than(>), greater than and equal to(>=) gives resultant value in boolean i.e either true or false after evaluation.

In this article, you will find Relational operators provided by Java.

Relational operators

OperatorDescriptionExample
<Less thanx == y
<=Less than or equal tox != y
>Greater thanx == y
>=Greater than or equal tox != y
  • All of these relational operators are binary operators.
  • All these relational operators also follow the general structure of Operand Operator Operand, meaning that an operator is always surrounded by two operands.
  • For example, an expression x >= y is a binary operation, where x and y are two operands and >= is an operator. If value of x is greater than y you will get true as value else false.
class RelationalOperatorsDemo
{
    public static void main(String[] args)
    {
        // create variables
        int a = 10, b = 12;

        // value of a and b
        System.out.println("Value of a is " + a + " and b is " + b);

        // > operator
        System.out.println(a > b); // false

        // < operator
        System.out.println(a < b); // true

        // >= operator
        System.out.println(a >= b); // false

        // <= operator
        System.out.println(a <= b); // true
    }
}

Hope you like this!

Keep helping and happy 😄 coding

Vishnu Damwala
Vishnu Damwala

A web geek, an industry experienced web developer & tutor/instructor residing in India 🇮🇳