Chapter 4 - Operators Flashcards
Relational operators
always result in a boolean value (true or false)
There are 6 relational operators
> >= < <= == (Equality Operator) != (Equality Operator)
Equality Operators
There are two: == and !=
4 things can be tested:
numbers, characters, booleans and reference variables
When comparing characters
Java uses Unicode value of character as the numeric value
instanceof operator
is for reference variables only, and checks if an object is of a particular type
instanceof operator
can be used only to test Objects (or null) against class types that are of the same hierarchy
for interfaces
an object passes the instanceof test if any of its superclasses implement the interface on the right side of the instanceof operator
There are 4 primary math operators
add, subtract, multiply and divide
The remainder operator (%)
returns the remainder of a division
Expressions are evaluated from left to right
unless you add parenthesis, or unless some operators have higher precedence
*,/, and %
operators have higher precedence than + and -
If either operand is a string
the + operator concatenates the operands
If both operands are numeric (in string concatenations)
the + operator adds the operands
Prefix operators ++ and – run
before the value is used in the expression
Postfix operators ++ and – run
after the value is used in the expression