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

  • Home
  • SEARCH
  • 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 8846831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:05:47+00:00 2026-06-14T12:05:47+00:00

Possible Duplicate: Difference in & and && I’ve read several tutorials and answer regarding

  • 0

Possible Duplicate:
Difference in & and &&

I’ve read several tutorials and answer regarding short circuit operations in java and I’m still not quite understanding the difference in how java handles short circuiting for a double vertical pipe vs a double ampersand. For instance …

Why does the logical AND short circuit evaluation fail?

Citing the JSL 15.23. Conditional-And Operator &&

The conditional-and operator && is like & (§15.22.2), but evaluates its right-hand operand only if the value of its left-hand operand is true.

public static void main( String... args ) {


    int a = 1;

    int b = 2;

    // Okay. Prints
    if( a == 1 | b == 3 ) {

        System.out.println( "Comparison via |" + "\na is " + a + "\nb is " + b );

    }

    // Okay. Prints
    if( a == 1 || b == 3 ) {

        System.out.println( "Comparison via ||" + "\na is " + a + "\nb is " + b );

    }

    // Okay. Does not print
    if( a == 1 & b == 3 ) {

        System.out.println( "Comparison via &" + "\na is " + a + "\nb is " + b );

    }

    // I don't understand. Shouldn't the Short Circuit succeed since the left side of the equation equals 1?
    if( a == 1 && b == 3 ) {

        System.out.println( "Comparison via &&" + "\na is " + a + "\nb is " + b );

    }

}
  • 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-06-14T12:05:49+00:00Added an answer on June 14, 2026 at 12:05 pm

    I don’t understand. Shouldn’t the Short Circuit succeed since the left side of the equation equals 1?

    No, absolutely not. The point of && is that the result is only true if the left and the right operands are true; the short-circuiting means that the right operand isn’t evaluated if the left operand is false, because the answer is known at that point.

    You should read sections 15.23 and 15.24 of the JLS for more details:

    The conditional-and operator && is like & (§15.22.2), but evaluates its right-hand operand only if the value of its left-hand operand is true.

    The conditional-or operator || operator is like | (§15.22.2), but evaluates its right-hand operand only if the value of its left-hand operand is false.

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

Sidebar

Related Questions

Possible Duplicate: Difference between Color.red and Color.RED I have seen that the Java class
Possible Duplicate: Calculating the Difference Between Two Java Date Instances How do I get
Possible Duplicate: Difference between “and” and && in Ruby? Ruby: difference between || and
Possible Duplicate: What’s the difference between IComparable & IEquatable interfaces? What is the major
Possible Duplicate: Difference between Covariance & Contra-variance I'm trying to understand what covariance and
Possible Duplicate: Is there any difference between the :key => “value” and key: “value”
Possible Duplicate: Difference in SQL Between operator and “>=” & “<=” operator I see
Possible Duplicate: What's the difference between using the Serializable attribute & implementing ISerializable? What
Possible Duplicate: What's the difference between cout<<cout and cout<<&cout in c++? I accidentally found:
Possible Duplicates: What's the difference between | and || in Java? Difference in &

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.