Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Tech Solutions
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • E-Commerce Demo Application
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • E-Commerce Demo Application
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Java For Automation

  • 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 For Automation
  • 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.

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.

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.

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.

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.

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.

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 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105