Core Java

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.

OperatorDescription
||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.

OperatorDescription
&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.

Download
You can download the full source code of this example here: Basic Operators – OR in Java

Yatin

An experience full-stack engineer well versed with Core Java, Spring/Springboot, MVC, Security, AOP, Frontend (Angular & React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Siddarth
2 years ago

Nice explanation on operators in java.
Cheers,
https://www.flowerbrackets.com/operators-in-java/

Pankaj . J
1 year ago

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.

Last edited 1 year ago by Pankaj . J
Back to top button