top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is short-circuit operator in Java?

+2 votes
507 views
What is short-circuit operator in Java?
posted Sep 11, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The logical operators && and || is known as short circuit operators in Java as they don't evaluate right-hand side until it is necessary. Example:

  • false && (some expression): here evaluation of some expression is not necessary because F && (T) = False and compiler works smartly here.

  • The Same case is with logical OR (||) operators, T || F = True but if it F || T then it will evaluate right-hand side expression too to check whether it is true or false.

Note: Don't confuse with bitwise AND and OR because both sides evaluated here as it performs operations on bit level of both side expressions.

answer Sep 12, 2017 by Shivam Kumar Pandey
Similar Questions
+2 votes

Given 2 strings, a and b, return a string of the form shorterString+longerString+shorterString, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length 0). If input is "hi" and "hello", then output will be "hihellohi".

0 votes

I am search for different approach.
Let see how many solution i can get

0 votes

Which one will be faster in Java, Increment operator or Decrement operator?

a) for(int i = 0; i < 1000; i++) {}    
b) for(int i = 1000; i > 0; i--) {}
...