Basic Operators: OR in Java
Hello readers, in this tutorial, we will learn the operator OR in Java programming language.
1. Introduction
Java programming offer Operators that are used to perform various operations . In this tutorial, we’ll only cover the OR
operator that falls under the Conditional and Bitwise category.
1.1 Conditional operators in Java
Following table list the different conditional operators.
Operator | Description |
---|---|
|| | Conditional-OR operator; true if either of the boolean expression is true |
&& | Conditional-AND operator; true if all boolean expressions are true |
1.2 Bitwise operators in Java
Following table list the different bitwise operators. These operators are rarely used in a programming language, so we are listing here for knowledge purposes only.
Operator | Description |
---|---|
& | Bitwise AND |
^ | Bitwise exclusive OR |
| | Bitwise inclusive OR |
To start with the captioned tutorial, we are hoping that users at present have their preferred Ide installed on their machines. For easy usage, I am using Eclipse Ide on a Windows operating system.
2. Basic Operators – OR in Java
In this example, we’ll demonstrate the OR
operator. For a better understanding, you can execute the below code in Eclipse Ide.
Example.java
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 | package com.jcg; public class Example { public static void main(String[] args) { int ele1 = 10 ; int ele2 = 20 ; // LOGICAL OR OPERATOR // // At least one expression needs to be true for result to be true! if ((ele1 > 10 ) || (ele2 > 10 )) { System.out.println( "Either ele1 or ele2 is greater than 10." ); } } } |
If everything goes well, the following output will be printed in the Ide console.
Output
1 | Either ele1 or ele2 is greater than 10. |
That is all for this tutorial and I hope the article served you whatever you were looking for. Happy Learning and do not forget to share!
3. Summary
In this tutorial, we learned the basic OR
operator. You can download the sample application as an Eclipse project in the Downloads section.
4. Download the Eclipse Project
This was an example of the operator OR.
You can download the full source code of this example here: Basic Operators – OR in Java
Nice explanation on operators in java.
Cheers,
https://www.flowerbrackets.com/operators-in-java/
Well Written Article, you talked about Basic Operators which is to the point, a small article, and a quick read too. Well done! Also, check this article on Java Operators for a more in-depth understanding.