Home » Core Java » Basic Operators – OR in Java

About Yatin

Yatin
The author is graduated in Electronics & Telecommunication. During his studies, he has been involved with a significant number of projects ranging from programming and software engineering to telecommunications analysis. He works as a technical lead in the information technology sector where he is primarily involved with projects based on Java/J2EE technologies platform and novel UI technologies.

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, developers 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. Conclusion

In this tutorial, we learned the basic OR operator. Developers 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
(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of