Now that we’ve got some basic concepts under our belt, let’s explore some more interesting things that we can do with Java. Relational Operators compare data types that have a defined ordering.

Relational operators will always return a Boolean value (either true or false). Here are the relational operators that we’ll cover in this lesson:

< Less than

<= Less than or equal to

> More than

>= More than or equal to

The relational operator is placed between the two values (or operands) that we wish to compare. Now that we know a little but more about relational operators, let’s get coding. Create a new Java class in our program called RelationalOperators and write the following code within the main method:

In this code, we create two int variables number1 and number2. We then print out the values of each relational operator being tested against out variables. Our output is as follows:

Of course this is a very basic overview of what we can do with Operators. Next up we’ll look at Boolean Operators.