by Dinesh Thakur Category: Operators and Expressions

Relational operators also known as comparison operators are used to check the relation between two operands. In other words, the operators used to make comparisons between two operands are called relational operators. Relational operators are binary operators and hence require two operands. The result of a relational operation is a Boolean value that can only be true or false according to the result of the comparison.

Relational operators are normally used with if statements, while loop, do-while loop and for loop to make branching and looping decisions.


Table shows you the different relational operators used in java programming.


                                                          Relational Operators









Less than

Greater than

Less than or equal to

Greater than equal to

Equal to

Not equal to








//program Showing Relational Operations
  public class RelationalOperators
       public static void main (String[] args)
          int x=5 ,y=3;
          System.out.println("x  > y --> " + (x>y));
          System.out.println("x  < y --> "  + (x<y));
          System.out.println("x <= y --> " + (x<=y));
          System.out.println("x >= y --> " + (x>=y));
          System.out.println("x == y --> " + (x==y));
          System.out.println("x != y --> " + (x!=y));

Relational Operators in Java Example

Java Example to Perform Relational Operations Using Scanner Class.

import java.util. *;
class RelationalOperationsUsingScanner
          public static void main(String args[])
                int x,y;
                Scanner scan = new Scanner(;
                System.out.print("Enter the Value of x : ");
                System.out.print("Enter the Value of y : ");
                System.out.println("x>y : "+(x>y));
                System.out.println("x<y : "+(x<y));
                System.out.println("x>=y : "+( x>=y));
                System.out.println("x<=y : "+( x<=y));

Java Example to Perform Relational Operations Using Scanner Class

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.