Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7507513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:30:08+00:00 2026-05-29T22:30:08+00:00

When used with boolean operands, & and | become logical operators per Section 15.22.2

  • 0

When used with boolean operands, & and | become logical operators per Section 15.22.2 of the JLS. Unlike && and ||, however, these don’t short-circuit; they always evaluate both sides. I have a silly question: Why are the less-efficient non-short-circuit logical operators (&, |) still there, when we have the more-efficient short-circuit logical operators (&&, ||)? I mean, what is the real usage of the non-short-circuit logical operators, as opposed to with the short-circuit logical operators? In other words, what is the usage of always evaluating both sides by using the non-short-circuit logical operators?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:30:08+00:00Added an answer on May 29, 2026 at 10:30 pm

    Updated answer:

    Apologies, I missed the word “logical” in your question even though it is there. (I’ve taken the liberty of emphasizing it a bit with an edit.)

    Consider the case where you want any side-effects to always occur, regardless of whether the left-hand expression evaluates true or false. E.g., contrast:

    if (foo() & bar()) {
        // Only call this if both operations returned true
    }
    

    with

    if (foo() && bar()) {
        // Only call this if both operations returned true
    }
    

    Let’s assume both foo and bar have effects that we want to have happen regardless of whether foo returns true or false. In the first one above, I know that bar will always get called and have its effect. In the latter, of course, bar may or may not get called. If we didn’t have the non-short-circuit version, we’d have to use temporary variables:

    boolean fooResult, barResult;
    fooResult = foo();
    barResult = bar();
    if (fooResult && barResult) {
        // ...
    }
    

    You might argue (I probably would) that you should do that anyway, because it’s way too easy to misread if (foo() & bar()), but there we go, a pragmatic reason for having non-short-circuit versions.

    Original answer:

    How would you propose & (or |) be a short-circuited operator? With && and ||, it makes sense because you’re dealing with boolean conditions: They can be true or false, there are no shades of grey. But & and | deal with bits, not booleans. The result is a number. I mean, I guess & could not evaluate the right-hand side if the left-hand side were 0, and similarly | could not evaluate it if the left-hand side were all-bits-on for whatever the type was, but I don’t see much point to making the one edge case of each operator significant (as compared to the 254 or more other cases).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What formatter is used for boolean values? EDIT: Example: NSLog(@ ??, BOOL_VAL); , what
I have a boolean function which is used in the decision-making of many other
While database design I used a field name deleted and use it as Boolean.
I am used to the word primitive being used for basic data types: boolean,
In my Android programs, I frequently used : private static final boolean D =
The atomic integer, long, boolean etc are used to do any atomic updates to
I have a table that contains approximately 22000 rows and I used a Boolean
I wrote the function used to decompose a Boolean function, the problem is that
public class A { public void search(boolean[] searchList) { // searchList array is used
I always thought that && operator in Java is used for verifying whether both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.