logical AND, bitwise AND
& and the && can be used as the logical AND operator, representing the logical and ( and ) , the result of the entire operation is true when the result of an expression on either side of the operator is true, otherwise, theresult is false,as long as there is a side of false.
&& also features a short-circuit , that is, if the first expression is false, the second expression is no longer evaluated, for example, for an if (str! = null &&!str.equals (")) expression, when a when str is null , subsequent expressions do not execute, so the nullpointerexception does not appear if you change && to & , you will throw NullPointerException exception. if (x==33 & ++y>0) y grows,if (x==33 && ++y>0) does not grow
& can also be used as a bitwise operator , when an expression on either side of the & operator is not of type Boolean,& represents bitwise AND operation, we typically use 0x0f to do with an integer & operation to get the minimum 4 bit bits of the integer , for example,0x31 & 0x0f The result is 0x01.
&&is logical AND
that is , whether the expression on both sides of the && is true or not, this && expression value is true
&is bitwise AND
1&1=1; 1&0=0; 0&1=0; 0&0=0
The number of both sides of the & will be expanded with binary, each seeking and computing (binary and operation, with logic and almost ), thelast obtained binary number is the result; logic and results are only true and false, And the bitwise and the result is a real number
Java Learning materials-logic and, bitwise AND