x*x + y*y
(x > 0) && (y == z)
Like C, Java uses the symbol && for the boolean ``and''
operation and the symbol == for the equality operation
on numbers. (The symbols
& and = are used in the C and Java
for other purposes.)
The following table lists the major infix operators provided by Java:
+ addition - subtraction * multiplication / division % mod (remainder from integer division) < less than <= less than or equal > greater than >= greater than or equal == equal != not equal && and || or
Java also supports the prefix operators - (negation) and ! (not) used in conventional mathematical notation.
Finger Exercise: Conduct some experiments to see how these operators behave by writing simple expression evaluation programs in Java (as shown in the previous section).
The only pure expression form in Java that deviates from conventional mathematical notation is the conditional expression notation
test ? consequent : alternativeborrowed from C. This expression returns the value of consequent if test is true and and the value of alternative otherwise.