TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java Tutorials

Java Relational Operators

Overview

Java relational operators are symbols that are used to compare the operands. The operators are binary and require two operands to perform the calculations.

Relational Operators

Java relational operators are shown below:

Relational Operation
Operator Symbol  Example
Equal To

 

== a == b
Not equal to != a != b
Greater Than > a > b
Greater Than or Equal To >= a >= b
Less Than < a < b
Less Than or Equal To <= a <= b

 

Example

Let’s look at an example of Relation operator in a sample program. We will declare two variables of type int. We will compare if a is less than b in a if statement. If a < b then the expression evaluates to true.

 

public class RelationalOperatorDemo {

 public static void main(String[] args) {
 int a = 10;
 int b = 20;
 if( a < b) // Relational Operator
 System.out.println("a is less than b");
 else if(a == b)
 System.out.println("a is equal to b");
 else
 System.out.println("a is greater than b");
 }
}

 

 

Based on the values, a variable holds the value of 10 and b variable holds the value of 20. Since, 10 < 20 the expression a < b evaluates to true. The if statement would be executed and the else statements will not execute.

 

Java Relational Operator

—

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

Related Posts

Download Greenfoot Windows

Java Tutorials /

Download & Install Greenfoot on Windows

Java Tutorials /

Java Static Code Analysis

Java Tutorials /

Java Testing Tools

Java Tutorials /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java Tutorials /

Exceptions in Java Programs

‹ Java Arrays› Java Conditional Operators

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version