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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:07:05+00:00 2026-05-30T03:07:05+00:00

Possible Duplicate: Does java evaluate remaining conditions after boolean result is known Why do

  • 0

Possible Duplicate:
Does java evaluate remaining conditions after boolean result is known
Why do we usually use || not |, what is the difference?

I missed my class lecture the other day and I was wondering if anyone could give an explanation what short circuiting is and maybe an example of it being used in a simple Java program. Thanks for your help!

  • 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-30T03:07:06+00:00Added an answer on May 30, 2026 at 3:07 am

    Short-circuiting is where an expression is stopped being evaluated as soon as its outcome is determined. So for instance:

    if (a == b || c == d || e == f) {
        // Do something
    }
    

    If a == b is true, then c == d and e == f are never evaluated at all, because the expression’s outcome has already been determined. if a == b is false, then c == d is evaluated; if it’s true, then e == f is never evaluated. This may not seem to make any difference, but consider:

    if (foo() || bar() || baz()) {
        // Do something
    }
    

    If foo() returns true, then bar and baz are never called, because the expression’s outcome has already been determined. So if bar or baz has some other effect than just returning something (a side effect), those effects never occur.

    One great example of short-circuiting relates to object references:

    if (a != null && a.getFoo() != 42) {
        // Do something
    }
    

    a.getFoo() would normally throw a NullPointerException if a were null, but because the expression short-circuits, if a != null is false, the a.getFoo() part never happens, so we don’t get an exception.

    Note that not all expressions are short-circuited. The || and && operators are short-circuited, but | and & are not, nor are * or /; in fact most operators are not.

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

Sidebar

Related Questions

Possible Duplicate: When do you use Java's @Override annotation and why? Java, What does
Possible Duplicate: Does use of final keyword in Java improve the performance? The final
Possible Duplicate: Why does C# not provide the C++ style ‘friend’ keyword? I'd like
Possible Duplicate: Does Java guarantee that Object.getClass() == Object.getClass()? If I have a class
Possible Duplicate: Why does (360 / 24) / 60 = 0 … in Java
Possible Duplicate: Java - why no return type based method overloading? The compiler does
Possible Duplicate: What is the Java ?: operator called and what does it do?
Possible Duplicate: The constructor Date(…) is deprecated. What does it mean? (Java) I'm getting
Possible Duplicate: What does “String[] args” contain in java? I want to know the
Possible Duplicate: Import package.* vs import package.SpecificType while importing packages in java does it

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.