---
title: Relational Operators
description: "***Relational Operators*** Relational operators in Java are used to compare two values. They return a boolean result, which is either *true* or *false*. Relational operators are fundamental for controlling the flow of a program using conditional statements such as*if, while,*…"
url: "https://vinothqaacademy.com/docs/relational-operators/"
updated: "2025-10-05"
category: Java
tags:
  - Java
---

# Relational Operators

***Relational Operators***

Relational operators in Java are used to compare two values. They return a boolean result, which is either *true* or *false*. Relational operators are fundamental for controlling the flow of a program using conditional statements such as*if, while,* and *for.*

### List of Relational Operators

1. Equal to (**==**)
2. Not equal to (**!=**)
3. Greater than (**>**)
4. Less than (**<**)
5. Greater than or equal to (**>=**)
6. Less than or equal to (**<=**)

### Examples and Explanations

**1. Equal to (****==****)**

The equal to operator checks if two values are equal.

```javascript

                public class Main {

    public static void main(String[] args) {

        int a = 10;

        int b = 20;

        boolean result = (a == b);

        System.out.println("a == b: " + result); 

        b = 10;

        result = (a == b);

        System.out.println("a == b: " + result); 

    }

}

Output:
a == b: false
a == b: true
```

**2. Not equal to (****!=****)**

The not equal to operator checks if two values are not equal.

```javascript

                public class Main {

    public static void main(String[] args) {

        int a = 10;

        int b = 20;

        boolean result = (a != b);

        System.out.println("a != b: " + result); 

        b = 10;

        result = (a != b);

        System.out.println("a != b: " + result); 
    }

}

Output:
a != b: true
a != b: false
```

**3. Greater than (>)**

The greater than operator checks if the value on the left is greater than the value on the right.

```javascript

                public class Main {

    public static void main(String[] args) {

        int a = 10;

        int b = 20;

        boolean result = (a > b);

        System.out.println("a > b: " + result); 

        a = 30;

        result = (a > b);

        System.out.println("a > b: " + result); 

    }

}

Output:
a > b: false
a > b: true
```

**4. Less than (<)**

The less than operator checks if the value on the left is less than the value on the right.

```javascript

                public class Main {

    public static void main(String[] args) {

        int a = 10;

        int b = 20;

        boolean result = (a < b);

        System.out.println("a < b: " + result); 

        a = 30;

        result = (a < b);

        System.out.println("a < b: " + result); 

    }

}

Output:
a < b: true
a < b: false
```

**5. Greater than or equal to (>=)**

The greater than or equal to operator checks if the value on the left is greater than or equal to the value on the right.

```javascript

                public class Main {

    public static void main(String[] args) {

        int a = 20;

        int b = 20;

        boolean result = (a >= b);

        System.out.println("a >= b: " + result); 

        a = 10;

        result = (a >= b);

        System.out.println("a >= b: " + result); 

    }

}

Output:
a >= b: true
a >= b: false
```

**6. Less than or equal to (<=)**

The less than or equal to operator checks if the value on the left is less than or equal to the value on the right.

```javascript

                public class Main {

    public static void main(String[] args) {

        int a = 20;

        int b = 20;

        boolean result = (a <= b);

        System.out.println("a <= b: " + result); 

        a = 30;

        result = (a <= b);

        System.out.println("a <= b: " + result); 

    }

}

Output:
a <= b: true
a <= b: false
```

**Summary**

Relational operators are crucial in making comparisons between values in Java. They help in decision-making processes within programs by providing boolean results that control the flow of execution. Understanding how to use these operators effectively allows you to write more dynamic and responsive code.
