Explain the difference between the Boolean & operator and
the && operator?
Answer Posted / 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 View All Answers
What are the ways in which a thread can enter the waiting state?
Can we create an object of private class?
Can I uninstall java?
What is the difference between == and === javascript?
Which class is the superclass for every class in java programming?
What is tree node in java?
How many types of memory areas are allocated by JVM in java?
What is a method header?
Does A Class Inherit The Constructors Of Its Superclass?
What is a method in programming?
hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea
How is string stored in java?
When throws keyword is used?
How does callback work in java?
What is the difference between object oriented programming language and object based programming language?