GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.dremendo.com — Relational or Comparison Operators in Java | Dremendo
?>
Announcements
No new announcements.
Java Programming Tutorial
Table of Contents
Relational or Comparison Operators in JavaIn this lesson, we will learn what is the relational or comparison operator and how it works in Java programming with some examples. What is Relational OperatorsRelational operators in Java, also known as comparison operators, are used to compare the values of two operands. For example, they check if one operand is equal to the other, greater than, or less than the other, and so on.
Video Explanation
Click the button below to watch the explanation.
Please wait while the video is loading....
There are 6 types of relational operators in Java and they are:
Now let's see the examples of all the relational operators one by one for more understanding. Equality ==The equality operator == is used to check if the values of two operands are the same. The result of the == operator is 1 (true) if the values are equal; otherwise, the result is 0 (false) if they are not equal.
Example
In the example above, the result of a is 1 because the value of x and y is the same so, the relation is correct. On the other hand, the result of b is 0 because the value of x and z is not the same so the relationship is wrong. Greater than >The greater than > relational operator is used to check if the value of the left operand is greater than the value of the right operand. The result of the > operator is 1 (true) if the left operand is greater; otherwise, the result is 0 (false) if it is not.
Example
In the example above, the result of a is 1 because the value of x is greater than the value of y so, the relation is correct. On the other hand, the result of b is 0 because the value of x is not greater than the value of z so the relationship is wrong. Less than <The less than < relational operator is used to check if the value of the left operand is less than the value of the right operand. The result of the < operator is 1 (true) if the left operand is less; otherwise, the result is 0 (false) if it is not.
Example
In the example above, the result of a is 1 because the value of x is less than the value of y so, the relation is correct. On the other hand, the result of b is 0 because the value of x is not less than the value of z so the relationship is wrong. Greater than or equal to >=The greater than or equal to >= relational operator is used to check if the value of the left operand is greater than or equal to the value of the right operand. The result of the >= operator is 1 (true) if the condition is met; otherwise, the result is 0 (false) if it is not.
Example
In the example above, the result of a is 1 because the value of w is not greater but equal to the value of x so, the relation is correct. Next, the result of b is 1 because the value of x is greater than the value of y so, the relationship is correct. On the other hand, the result of c is 0 because the value of y is neither greater nor equal to the value of z so the relationship is wrong. Less than or equal to <=The less than or equal to <= relational operator is used to check if the value of the left operand is less than or equal to the value of the right operand. The result of the <= operator is 1 (true) if the condition is met; otherwise, the result is 0 (false) if it is not.
Example
In the example above, the result of a is 1 because the value of w is not less but equal to the value of x so, the relation is correct. Next, the result of b is 1 because the value of x is less than the value of y so, the relationship is correct. On the other hand, the result of c is 0 because the value of y is neither less nor equal to the value of z so the relationship is wrong. Not equal to !=The not equal to != relational operator is used to check if the value of the left operand is not equal to the value of the right operand. The result of the != operator is 1 (true) if the values are not equal; otherwise, the result will be 0 (false) if the values are equal.
Example
In the example above, the result of a is 1 because the value of x is not equal to the value of y so, the relation is correct. On the other hand, the result of b is 0 because the value of x is equal to the value of z so the relationship is wrong. Test Your KnowledgeAttempt the questions in the exercise to check whether you have understood the lesson clearly.
We care about your privacyDremendo uses cookies and similar technologies that are necessary for the site to work properly, understand how you interact with our website, and measure the effectiveness of our marketing. By clicking Accept All, you consent to the use of non-essential cookies and similar technologies for analytics, advertising, and ad measurement, as described in our Privacy Policy. Cookie PreferencesChoose which types of cookies Dremendo may use.
Necessary Cookies
Allow
Required for essential website functionality and security.
Analytics Cookies
Allow
Help us understand how visitors use Dremendo.
Marketing Cookies
Allow
Help us measure advertising performance and understand interactions with our advertisements.
Mentora
Question Asked: 0 / 20
Hi, I’m Mentora! I’m your personal AI tutor from Dremendo. Ask me anything, and I’ll help you understand it in a simple and easy way. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |