CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > What is > Logical Operators in Java

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor
  • Home

Logical Operators in Java

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 · 2 min read · 0 Comments
Share: in X

Logical operators in Java are used to perform logical operations on boolean expressions. There are three logical operators in Java.

Table of Contents

  • List of logical operators in Java
  • && Operator
  • || Operator
  • ! Operator

List of logical operators in Java

OperatorMeaningExampleDescription
&&Short-circuit ANDa && bReturns true if both are true. If a is false b will not be evaluated and returns false.
||Shirt-circuit ORa || bReturns true if anyone is true. If a is true, b will not be evaluated and returns true.
!Logical unary NOT!aReturns true if a is false.

&& Operator

The AND operator (&&) is used to test if two expressions are true. It returns true if both expressions are true, and false if either expression is false. For example:

boolean result = (5 > 3) && (10 < 20);
// result is true because both expressions are true

|| Operator

The OR operator (||) is used to test if at least one of two expressions is true. It returns true if either expression is true, and false if both expressions are false. For example:

boolean result = (5 > 3) || (10 > 20);
// result is true because the first expression is true

! Operator

The NOT operator (!) is used to negate a boolean value. It returns the opposite boolean value of the expression it operates on. For example:

boolean result = !(5 > 3);
// result is false because the expression 5 > 3 is true

It is important to note that the AND operator has a higher precedence than the OR operator. This means that the AND operator will be evaluated before the OR operator. For example:

boolean result = (5 > 3) && (10 > 20) || (2 < 4);
// result is true because the OR operator returns true

In the example above, the AND operator is evaluated first, resulting in false. However, the OR operator is then evaluated, and because the second expression is true, the overall result is true.

Logical operators are commonly used in control structures such as if-else statements and while loops to control the flow of a program. They are an essential part of programming in Java and are used frequently in a wide range of applications.

Related Posts:

  • java.lang.Boolean class in Java
  • Control Statements in Java
  • Expressions in Java
  • Boolean Data Type in Java
  • List in Java
  • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
Tags:javalanguage-fundamentals
Was this article helpful?
← Previous ArticleIterable to Stream in Java
Next Article →Difference Between Scale In And Scale Out In AWS

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap