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 |
why use interface? if interface declear a method implement in class. why direct implement method in class
What is a void return type?
What does business logic mean?
What are scalar data types?
Give me some null interfaces in java?
What is use of super keyword in java?
How do you pass by reference?
What will happen if there is a default method conflict as mentioned above and we have specified the same signature method in the base class instead of overriding in the existing class ?
How many types of packages are there in Java?
How many types of threads are there in java?
What do you know about java?
Can I override protected method in java?