Relational Operators in Java

Video Tutorial
FREE
Relational Operators thumbnail
This video belongs to
Java Course - Mastering the Fundamentals
12 modules
Certificate
Topics Covered

Relational operators in Java are binary Java operators used to check the relations between two operands. They return a boolean value (true or false) by comparing the two operands. Java supports a variety of relational operators, including greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=), equal to (==), and not equal to (!=). These operators are commonly used in conditional statements, loops, and other programming constructs to make decisions based on the values of variables or expressions.

What are Relational Operators in Java?

In programming, we often need to check the relation between two operands such as equality, in-equality, etc. Relational operators in Java are used to check the relations between two operands. After comparison, the relational operators return a boolean value. Relational operators are mainly used for conditional checks in if, else, for, while, etc.

Syntax

The syntax for relational operators in Java is given below:

  • operand1 - The first variable to be compared
  • operand2 - The second variable to be compared
  • relational_operator - The relational operator to check relation between operand1 and operand2.

Types of Relational Operators in Java

There are six types of relational operators in Java, and they can be found below:

  • Equal To (==) - Checks if two operands are equal
  • Not Equal To (!=) - Checks if two operands are not equal
  • Greater Than (>) - Checks if one operand is greater than the other
  • Less Than (<) - Checks if one operand is less than the other
  • Greater Than or Equal To (>=) - Checks if one operand is either greater than or equal to the other.
  • Less Than or Equal To (<=) - Checks if one operand is either less than or equal to the other.

Equal To (==)

The Equal To (==) operator checks if two operands are equal. It returns true if two operands are equal; else false. The syntax of the == operator is:

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Not Equal To (!=)

The Not Equal To (!=) operator checks if two operands are not equal. It returns true if two operands are not equal; else false. The syntax of the != operator is:

Greater Than (>)

The Greater Than (>) operator checks if one operand is greater than the other. It returns true if the first operand is greater than the other; else false. The syntax for the > operator is:

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Less Than (<)

The Less Than (<) operator checks if one operand is less than the other. It returns true if the first operand is less than the other; else false. The syntax for the < operator is:

Greater Than or Equal To (>=)

The Greater Than or Equal To (>=) operator checks whether one operand is greater than or equal to the other. It returns true if the first operand is greater than or equal to the other; else false. The syntax for the >= operator is:

Less Than or Equal To (<=)

The Less Than or Equal To (<=) operator checks if one operand is either less than or equal to the other. It returns true if the first operand is less than or equal the other; else false. The syntax for the <= operator is:

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Examples of Relational Operators in Java

Equal To (==)

We used the == operator to check if two values are equal.

Output

Not Equal To (!=)

We used the != operator to check if the two values were not equal equal.

Output:

Greater Than (>)

We used the > operator to check if one value is greater than the other.

Output:

Less Than (<)

We used the < operator to check if one value is less than the other.

Output:

Greater Than or Equal To (>=)

We used the >= operator to check whether one value is greater than or equal to the other.

Output:

Less Than or Equal To (<=)

We used the <= operator to check if one value is either less than or equal to the other.

Output:

Conclusion

  • Relational operators in Java are binary operators used to check the relations between two operands
  • Relational operators return a boolean value
  • There are six relational operators in Java: ==, !=, <, >, <=, and >=
  • Relational operators are mainly used for conditional checks if, else, for, while, etc.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more