Java Relational Operators

The Java Relational operators compare between operands and determine the relationship between them.

There are six types of relational operators in Java, these are:

OperatorMeaning
==Is equal to
!=Is not equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

These operators are mainly used when applying control statements in the program.

The output of the relational operator is (true/false) boolean value, and in Java, true or false is a non-numeric value that is not related to zero or one.

Program to Show Relational Operators Works

Example:
public class relatiop {

 public static void main(String[] args) {
  //Variables Definition and Initialization
  int num1 = 12, num2 = 4;

  //is equal to
  System.out.println("num1 == num2 = " + (num1 == num2) );

  //is not equal to
  System.out.println("num1 != num2 = " + (num1 != num2) );

  //Greater than
  System.out.println("num1 >  num2 = " + (num1 >  num2) );

  //Less than
  System.out.println("num1 <  num2 = " + (num1 <  num2) );

  //Greater than or equal to
  System.out.println("num1 >= num2 = " + (num1 >= num2) );

  //Less than or equal to
  System.out.println("num1 <= num2 = " + (num1 <= num2) );

 }
}
Output:
num1 == num2 = false
num1 != num2 = true
num1 >  num2 = true
num1 <  num2 = false
num1 >= num2 = true
num1 <= num2 = false