Short Circuit Logical and Boolean Operators in Java by Example
Short Circuit Logical and Boolean Operators in Java by Example
cs-fundamentals.com
programming tutorials and interview questions
Home
C Programming
Java Programming
Data Structures
Web Development
Tech Interview
For example, if A and B are two boolean expressions then following Java logical
operators can be applied on expressions A and B.
https://cs-fundamentals.com/java-programming/java-logical-operators 1/5
05/04/2024, 12:53 Short Circuit Logical and Boolean Operators in Java by Example
!A logical NOT
Short circuit logical operators are efficient and safe to use, that's why we usually do
not see not-short circuit in programs.
Note that all logical and boolean operators except the unary ! operator have a
lower precedence than the comparison operators. Thus, it is perfectly legal to write
a line of code like the one above. However, some programmers prefer to use
parentheses to make the order of evaluation explicit:
if ((x < 10) && (y > 3)) ...
Logical OR (||)
https://cs-fundamentals.com/java-programming/java-logical-operators 2/5
05/04/2024, 12:53 Short Circuit Logical and Boolean Operators in Java by Example
Boolean OR (|)
This operator performs a boolean OR operation on its two boolean operands. It is
like the || operator, except that it always evaluates both operands, even if the first
one is true. The | operator is almost always used as a bitwise operator on integer
operands; its use with boolean operands is very rare.
Last Word
https://cs-fundamentals.com/java-programming/java-logical-operators 3/5
05/04/2024, 12:53 Short Circuit Logical and Boolean Operators in Java by Example
In this tutorial we discussed boolean and logical operators of Java. Hope you have
enjoyed reading this tutorial on logical operators. Please do write us if you have any
suggestion/comment or come across any error on this page. Thanks for reading!
References
1. Core Java Volume I - Fundamentals
2. Java: The Complete Reference, Seventh Edition
3. Operators: Sun tutorial
4. Bit Twiddling Hacks
All Topics
Home
C Programming Tutorials
Java Programming Tutorials
Data Structures Tutorials
All Tech Interview Questions
C Interview Question Answers
Java Interview Question Answers
DSA Interview Question Answers
Email:
Subscribe
https://cs-fundamentals.com/java-programming/java-logical-operators 4/5
05/04/2024, 12:53 Short Circuit Logical and Boolean Operators in Java by Example
https://cs-fundamentals.com/java-programming/java-logical-operators 5/5