Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Java Variables Micro Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of understanding regarding Java variables and operators.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

A relational operator is an operator that tests or defines a relationship between two operands. These include numerical equality such as "5 = 5" and inequalities such as "7<3". Please take a look at the six relational operators that follow.

RelationalOperatorExample.java

package exlcode;
public class RelationalOperatorExample {
public static boolean exampleVariableOne = 10 < 15;
public static boolean exampleVariableTwo = 10 > 15;
public static boolean exampleVariableThree = 10 <= 10;
public static boolean exampleVariableFour = 10 >= 15;
public static boolean exampleVariableFive = 15 == 10;
public static boolean exampleVariableSix = 15 != 10;
public static void main(String[] args) {
System.out.println(exampleVariableOne);
System.out.println(exampleVariableTwo);
System.out.println(exampleVariableThree);
System.out.println(exampleVariableFour);
System.out.println(exampleVariableFive);
System.out.println(exampleVariableSix);
}
}

All of the operators above return a true or false result. The first four operators are recognizable and common. They work the same way as you learned in math class. Check the text below for an explanation of the operators functions.

> Tests whether the first integer is greater than the second integer.

< Tests whether the first integer is smaller than the second integer.

>= Tests whether the first integer is greater than or equal to the second integer.

<= Tests whether the first integer is less than or equal to the second integer.

== Tests whether the first integer is equal to the second integer.

Remember that '=' cannot be used to compare two values because a solo '=' is used only for assigning values to variables as we saw previously.

!= Tests whether the first integer is different from the second integer.

Therefore, a statement like 5 != 7 will return a result of "true".