Skip to the content
onlineexamguide
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login

Relational Operators in Java or Comparison Operators, Priority Tutorial

Relational Operators in Java

Study and learn MCQ questions and answers on Relational Operators in Java or Comparison Operators. Also, learn their priorities. Attend job interviews easily with these Multiple Choice Questions.

Relational Operators in Java

Java language comes with Relational Operators to compare two expressions, variables or constants. These Relational operators are also called Comparison Operators or Conditional Operators. Conditional operators are used inside Conditional Control Statements like IF, ELSE, ELSE IF and SWITCH.

Relational Operators or Comparison Operators in java

A Java relational operator checks the relationship of one expression with that of another expression like more, less or equal etc. The output of a Comparison or Relational Operation is a boolean data type Value. Relational operators return true for successful check and false for the unsatisfying condition. There are Six Relational operators in Java language.

You can use Relational operators with the data types like char, boolean and number data types like byte, short, int, long, float and double. You can not use Strings with relational operators directly without using String class methods like length. “char” data type value is simply treated as a number and comparison is performed.

NOOperatorMeaning
1>Greater than
2>=Greater than or Equal to
3<Less than
4<=Less than or Equal to
5==Equal to
6!=Not Equal to

1. Greater Than Operator

Greater Than Operator (>) checks if the left operand is greater than the right side operand.

2. Greater Than or Equal to Operator

Greater Than or Equal To Operator (>=) checks for two things namely Greater Than and Equal To. 

3. Less Than Operator

Less Than operator (<) checks if the left side operand is less than the right side operand.

4. Less Than or Equal To Operator

Less than or Equal to Operator (<=) checks for two things namely Less Than and Equal To.

5. Equal To operator

Equal To operator (==) checks whether left and right side operands are equal or not.

6. Not Equal To Operator

Not Equal To Operator (!=) checks the opposite condition of Equal To (==) operator. It checks for Unequal or Not Equal to Condition first and returns either true or false.

Relational Operators in Java example

class RelationalOperators
{
  public static void main(String args[])
  {
    int a=5;
    int b=20;
    if(a >= 4)
      System.out.println("a>=4");
    if(b == 20)
      System.out.println("b is 20.");
    if(a < 20)
      System.out.println("LESS");
    else
      System.out.println("MORE");
  }
}
//OUTPUT::
//a>=4
//b is 20.
//LESS

Relational Operators with char in java

class RelationalOperators2
{
  public static void main(String args[])
  {
    char a ='A'; //65 Unicode
    char b = 'b'; //98 Unicode
    if(a > b)
      System.out.println("A > b");
    else
      System.out.println("A < b");
  }
}
//OUTPUT::
//a<b

Relational Operators with Switch Statement in java

You can only use String, char and integer type data as an INPUT to switch() statement. You can use Relational Operators to construct CASE Constants in a Switch case as shown in this example. With the help of Java Ternary operator, we have used Comparison operators inside a SWITCH statement. Without the “final” keyword, this program does not work as SWITCH expects only constants.

class RelationalOperators3
{
  public static void main(String args[])
  {
    final int c = 5;
    switch(c<10?c:2)
    {
      case (c<10?c:2): System.out.println("C < 10"); break;
      default: System.out.println("OUTSIDE");
    }
  }
}
//OUTPUT::
//C < 10

Java Relational or Comparison Operators Priority or Precedence

Notice that Equal or Not Equal to Operation has got less priority than Greater Than, Greater Than or Equal to, Less than and Less than or Equal to Operations.

PriorityOperatorMeaning
1>, >=, <, <=Greater than, Greater than or Equal to, Less than, Less than or Equal to
2==, !=Equal to, Not Equal to

Comparison Operators with boolean and numbers in java

In the below example, > has more priority than ==. So, a is compared with b first. In the end, the result of the first relational expression is compared with false.

class ComparisonOperators
{
  public static void main(String args[])
  {
    int a=5;
    int b=20;
    boolean bill = a > b == false;
    System.out.println(bill);
  }
}
//OUTPUT::
//true
//(a > b) == false
//(false) == false
//true

In the next chapters, you will learn about Bitwise Operators and Logical Operators.

Relational Operators Quiz

[WpProQuiz 67]

Write a comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Atal Bihari Vajpayee | श्री अटल बिहारी वाजपेयी जीवन परिचय
  • सम्राट अशोक का जीवन परिचय (Emperor Ashoka)
  • Prithviraj Chauhan
  • बाल गंगाधर तिलक
  • स्वामी दयानंद सरस्वती
  • UPPSC Mines Inspector Recruitment 2022 Notification Out
  • AIIMS Delhi JR Vacancy 2022 [194 Post] Notification and Apply Online
  • भीमराव अम्बेडकर
  • डॉक्टर राजेंद्र प्रसाद का जीवन परिचय
  • श्रीनिवास रामानुजन का जीवन परिचय
  • Amnesty International day
  • World Economic Forum
  • UPSSSC VDO Syllabus and Exam Pattern 2022
  • RBI Officer Grade B Recruitment 2022
  • UKMSSB Assistant Professor Recruitment 2022 Apply Now 339 Post

onlineexamguide

onlineexamguide.com is the ultimate guide that will keep you updated about almost every Exam & Interviews . We aim to provide our readers with an informative details that have been occurring in Examination . Here at onlineexamguide.com , we focus on delivering our readers with the latest exam Pattern Mock test

We Provide Free online test to practice for Competitive exams , Online Exam, Entrance and Interview. Learn and Practice online test for Free and Prepare for your exam online with us

Quick links

  • About us
  • Privacy Policy
  • Instructor Registration
  • Student Registration
  • Java Programming Tests
  • C programming Tests
  • C++ programming Tests
  • Aptitude Tests

Follow us

Free Online Mock Test

  • UPTET PRIMARY Online Test Series
  • Super TET Mock Test in Hindi 2022
  • CTET Mock Test 2022 Paper 1
  • SSC CHSL Online Mock Test
  • SSC MTS Mock Test 2022
  • SSC CGL Mock Test
  • SSC GD Mock Test
  • ccc online test

Search

Learn and Earn

Register as Instructor - Create and sell online courses and coaching services with the best online platform onlineexamguide.com . Build a course, build a brand, earn money

Contact us

For any queries

Email us on - admin@onlineexamguide.com

We will response fast as much as we can
Copyright © 2022 onlineexamguide.com - All Rights Reserved.
error: Content is protected !!

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.