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

adapter class ?

2 Answers  


what is d difference between deep cloning and shallow cloning in core java?

3 Answers   Satyam,


Why string is immutable with example?

0 Answers  


what is difference betweem home interface and remote interface?

0 Answers   CTS, HCL,


How to sort an array in java without using sort method?

0 Answers  






How to extract HashMap values?

5 Answers   Marlabs,


why there are multiple catches for a try block.don't tell me that there can be multiple exception of a code segment that's why.tell me the real fact behind this.

4 Answers  


What is interface and its use?

8 Answers   HCL,


hi to all,i have a question on static block. i saved below as test.java class test extends a { static { System.out.println("test static"); } public static void main(String []dfs) { } } class a { static { System.out.println("a static"); } public static void main(String []asdf) { } } o/p as static test static but if i change base class as test class then class test { static { System.out.println("test static"); } public static void main(String []dfs) { } } class a extends test { static { System.out.println("a static"); } public static void main(String []asdf) { } } o/p test static explain me why "a static" wasn't print in second code when it is in derived class

1 Answers  


We can write any Java Logics in our JSP. Then why we are using servlets(Controller Layer) to interact with the DAO ?

6 Answers   TCS,


What are streams?

0 Answers  


Explain the term serialization?

10 Answers   Wipro,


Categories