Difference between the Boolean & operator and the && operator

What is the difference between the Boolean & operator and the && operator?

A single ampersand is used to perform ‘bit-wise AND’ operation on integer arguments. It constitutes the logical AND operator, which returns 1 if both bits in first and second arguments. Otherwise it returns 0. It always evaluates both the arguments.

A double ampersand is used to perform boolean operations, such as ‘logical AND’. It returns true if both the operands are true, otherwise returns false. It will evaluate the second argument if the first argument is true; otherwise the operation of the second operand is skipped.

Example
A & B
In this, both the operands A as well as B are evaluated and then ‘&’ is applied to them.

A && B
In this, A is evaluated first. If A is true then B is evaluated and then the operand is applied to them.
If A is false, evaluation of B is skipped.
Java - Advantage of the event-delegation model over event inheritance model.
Event-delegation model has two advantages over event-inheritance model...
What is the purpose of the wait(), notify(), and notifyAll() methods?
The wait() method makes the thread to halt, thus allowing other thread to perform...
Event-listener interface and an event-adapter class
An event-listener interface allows describing the methods which must be implemented...
Post your comment