Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Java Relational Operators

    Java Programming Tutorials


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

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

    Operator Meaning
    == 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


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.