Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothtechsolutions@gmail.com
Vinoth Tech Solutions
  • Home
  • Tutorials
  • End-to-End QA Projects
    • API Manual and Automation Testing using SoapUI
    • DevOps CI CD using Real Time Project Setup
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • About Me & Feedback
    • LinkedIn Profile
    • Placed Students Feedback
    • Online Training Feedback
    • TechTalk
  • FAQS
  • Demo Sites
    • Practice Automation
      • Registration Form
      • Transaction Details
      • DropDown
      • Basic Authentication
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
      • Date Picker Calendar
    • E-Commerce Demo Application
    • Healthcare Demo Page
    • Create Account Demo Page
    • Python JS Online Compiler
  • Home
  • Tutorials
  • End-to-End QA Projects
    • API Manual and Automation Testing using SoapUI
    • DevOps CI CD using Real Time Project Setup
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • About Me & Feedback
    • LinkedIn Profile
    • Placed Students Feedback
    • Online Training Feedback
    • TechTalk
  • FAQS
  • Demo Sites
    • Practice Automation
      • Registration Form
      • Transaction Details
      • DropDown
      • Basic Authentication
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
      • Date Picker Calendar
    • E-Commerce Demo Application
    • Healthcare Demo Page
    • Create Account Demo Page
    • Python JS Online Compiler

Java

  • What is Java?
  • Why to Learn Java?
  • History of Java
  • Types of Java Applications
  • Naming Conventions
  • Hello World Program
  • Internal Details of Java program
  • What is Java JDK, JRE and JVM ?
  • What is Java Comments ?
  • What is Java Variable?
  • Variable Naming convention
  • Primitive Data Types
  • Non Primitive Data Types
  • Type Casting
  • Java Arithmetic Operators
  • Relational Operators
  • What is logical operators in Java? 
  • What is Assignment Operators in Java? 
  • What is Unary Operators in Java? 
  • What is Ternary Operators in Java?
  • What is Java Control Statements?
  • What are Decision Making statements?
  • What are looping statements?
  • What are Jump statements?
  • What is OOPS concept in Java?
  • Advantages of Java OOPs
  • What is Java Inheritance?
  • What is Java Constructor?
  • What is this keyword?
  • What is Polymorphism?
  • What is super keyword ?
  • What is final keyword? 
  • What are access modifiers?
  • What is Encapsulation? 
  • What is Abstraction? 
View Categories
  • Home
  • Tutorials
  • Java
  • Java
  • Relational Operators

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.

📄
filename.js
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.

📄
filename.js
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.

📄
filename.js
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.

📄
filename.js
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.

📄
filename.js
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.

📄
filename.js
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.

Java
What are your Feelings

Share This Article :

  • Facebook
  • X
  • LinkedIn
Java Arithmetic OperatorsWhat is logical operators in Java? 
Table of Contents
  • List of Relational Operators
  • Examples and Explanations
© 2018 – 2025 V-Tech Solutions Ltd (UK), Reg. No: 16489105