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 8116375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:48:45+00:00 2026-06-06T03:48:45+00:00

My understanding is that when using && as an mathematical operation in Java, if

  • 0

My understanding is that when using && as an mathematical operation in Java, if the LHS (Left Hand Side) of an evaluation fails, the right hand side will not be checked, so.

false && getName();

getName() would never be called as the LHS has already failed.

false & getName();

When would I ever want to check the RHS if I know the LHS has failed? Surely any dependency on the RHS evaluation being ran would be bad coding practice?

Thank you

  • 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-06T03:48:50+00:00Added an answer on June 6, 2026 at 3:48 am

    Well the reason for & and && is not, that one evaluates the right side and the other doesn’t.

    • & is a bitwise operator, which makes a bitwise AND of the two values. It returns a value.

      Theoretically, if all bits of the left side are 0 (as is the case for false), the right side must not neccessarily be evaluated. I guess it’s a design decision that it is evaluated in every case. In the simple cases, it is faster than checking if the left side is 0.

    • && is a conditional logical operator, which takes two booleans and returns a boolean (that is true if and only if both sides are true).

      The same applies here, if the left side is false, we don’t need to check the right side. Here the decision was taken to skip the evaluation of the right side in that case.

    And to answer your last question (when would you want to evaluate the RHS if the LHS has failed), there are some scenarios where it can be ok. However, in any case it is possible to prevent these situations (see jocelyn’s answer for a good way to make sure that both expressions are evaluated) without loosing readability. In fact, I think jocelyn’s way is more readable than if (exprA() & exprB()) { ... }.

    Personally I never use & unless I really need a bitwise AND.

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

Sidebar

Related Questions

I have the understanding that using /../ in a file location in bash will
My understanding is that the LinqToSql pseudolanguage describes a set using a syntax very
We're using ReportBuilder 1.0 (2005) for now. I'm not understanding the way that the
I am using the normalise function in the code below. My understanding was that
It is my understanding that expression templates will break on ranged based for in
I'm trying to implement dynamic array in C using realloc(). My understanding is that
Understanding that I should probably just dig into the source to come up with
It's my understanding that in Spring, all objects are treated by default as singletons.
It's my understanding that all three of these lines below should return an ARRAY
It is my understanding that a texture atlas is basically a single texture that

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.