int done;
// ...
if(!done) ... // Valid in C/C++
if(done) ...
// but not in Java.
In Java, these statements must be written like this:
if(done == 0) ... // This is Javastyle.
if(done != 0) ...
The reason is that Java does not define true and false in the same way as C/C++. In C/C++,
true is any nonzero value and false is zero. In Java, true and false are nonnumeric values that
do not relate to zero or nonzero. Therefore, to test for zero or nonzero, you must explicitly
employ one or more of the relational operators.
Boolean Logical Operators
The Boolean logical operators shown here operate only on boolean operands. All of the
binary logical operators combine two boolean values to form a resultant boolean value.
Operator
Result
&
Logical AND

Logical OR
^
Logical XOR (exclusive OR)

Shor tcircuit OR
&&
Shor tcircuit AND
!
Logical unar y NOT
&=
AND assignment
=
OR assignment
^=
XOR assignment
==
Equal to
!=
Not equal to
?:
Ternar y ifthenelse
The logical Boolean operators, &, , and ^, operate on boolean values in the same way
that they operate on the bits of an integer. The logical ! operator inverts the Boolean state:
!true == false and !false == true. The following table shows the effect of each logical operation:
A
B
AB
A&B
A^B
!A
False
False
False
False
False
True
True
False
True
False
True
False
False
True
True
False
True
True
True
True
True
True
False
False
Search WWH :