Explain the difference between the Boolean & operator and
the && operator?



Explain the difference between the Boolean & operator and the && operator?..

Answer / ranganathkini

This can be explained with an example

1. The bitwise AND operator ( & )

(boolean expression1) & (boolean expression2)

to evaluate the above expression, Java first evaluates both
boolean expression1 and boolean expression2

hence only if both boolean expression1 and boolean
expression2 evaluate to true, the whole expression evaluates
to true.

2. The conditional AND operator ( && )

( boolean expression1 ) && ( boolean expression2 )

Here Java first evaluates boolean expression1, only if it
evaluates to true, boolean expression2 is evaluated. Hence
boolean expression2 is not evaluated if boolean expression1
evaluates to false.

The conditional AND operator, sometimes called the
short-circuit operator is more efficient that the bitwise
AND operator. As it saves the processing of expression2 by
first evaluating expression1 and ascertaining that the final
result will be false.

Is This Answer Correct ?    25 Yes 1 No

Post New Answer

More Core Java Interview Questions

What do you mean by order of precedence and associativity?

0 Answers  


What is difference between == equals () and compareto () method?

0 Answers  


Can we create our own wrapper class in java?

0 Answers  


StringBuilder s = new StringBuilder("Hello Mom");s.append(",I mean,Mother"); Response.Write(s.ToString()); String s = "Hello Mom"; s+ = ",I mean Mom"; Response.Write(s); Which is faster ? which uses the most memory?

6 Answers   HCL,


What ide should I use for java?

0 Answers  






What is the difference between an if statement and a switch statement?

0 Answers  


What is protected in java?

0 Answers  


What are methods in java?

0 Answers  


What state is a thread in when it is executing?

0 Answers  


I have 2 objects inside one object(vector). how can i serialize one of them. I dont want to serialize the second one

3 Answers   ABC, L&T,


What is xslt in java?

0 Answers  


What is the difference between a Window and a Frame?

6 Answers   Infosys, ProKarma,


Categories