Type boolean
In some programming languages, for example Matlab and C, integers are used to represent the logical values
true
and
false
. Generally, 0 is used for
false
, and any other integer can be used for
true
.
Java handles boolean values differently. There is a (primitive) type
boolean
, whose values are
true
and
false
(that's it). This type has five operations whose operands are booleans:
Type
boolean
Values:
true
,
false
Operations:
!
(
not
),
(
and
, or
conjunction
),

(
or
, or
disjunction
)
==
(equality, or equivalence),
!=
(inequality, or inequivalence)
Here is a table that defines the five operations.
b
c 
!b
b  c
b == c
b != c
false
false 
true
false
false
true
false
false
true 
true
false
true
false
true
true
false 
false
false
true
false
true
true
true 
false
true
true
true
false
We evaluate a few expressions in the interactions pane and discuss the operations.
1. !, which is read "not", is unary logical negation
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 GRIES
 Logic

Click to edit the document details