Learning Objectives: After this lesson, students should be able to: Define what a relational operator is. Identify the different relational operators in Java. Use relational operators in simple conditional statements (if-else) . Explain the true or false results of relational comparisons.
Relational Operators Relational operators are used to compare two values . The result is always a boolean value — either true or false .
Table of Relational Operators These operators work with numbers and characters . They are often used in if statements to make decisions . Operator Meaning Example Result == Equal to 5 == 5 true != Not equal to 5 != 3 true > Greater than 10 > 7 true < Less than 3 < 8 true >= Greater than or equal to 5 >= 5 true <= Less than or equal to 4 <= 4 true
Conditional Statements These are control structures that make decisions based on a condition. They use relational operators (and sometimes logical ones) to decide what code to run .
What is an if statement? An if statement is a decision-making statement in Java. It allows your program to check a condition — and run a block of code only if the condition is true . If ( condition)
Example Java compares a and b using relational operators and gives boolean results (true/false) .
If else/ Syntax
If else
Create a Java program using if-else statement that checks the temperature. If the temperature is greater than 25, display 'It's a hot day!', otherwise display 'It's a cool day!'.
If else if (Because 85 is not ≥ 90, but it is ≥ 75) symbol ≥ is called the “greater than or equal to” operator in English, and in Java syntax , we write it as: 👉 >=