Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 3 - Coggle Diagram
Chapter 3
Understanding Java Operators
Operands return a result
Types of operators
Unary
-, !, ~, +, (type)
One operand
!
Binary
+, -, /*, /, %
Ternary
boolean expression ? exp1 : exp2;
Operator Precedence
var perimeter = 2 * height + 2 * height;
Multiplication has high precedence
Mult/Div/Mod
*, /, %
Ad/Sub
+, -
Relational operators
<, >, <=, >=, instanceof
Equal/Not Equal
==, !=
Logical Operators
&&, ||
Logical Complement And Negation Operators
Logical Compl
! negate
boolean truth = true;
truth = !truth;
Negation Oper.
reverses sign numeric
double temp = 1.21;
temp = -temp; // -1.21;
Increment and Decrement Operators
++, --
applied first
pre-increment
++plus;
pre-decrement
--plus;
pos-incre
plus++;
pos-decre
plus--;
Working binary arithmetic operator
/*, / has priority
Changing the order of operation
parentheses change order operation
int price = 2
((5+3)
4-8);
Verifying parentheses syntax
1 + ((3*5) / 3; //does not compile
miss close parentheses
can be a tricky
Division and Modulus Operators
modulus remainder value
division floor value integer
Numeric promotion
examples
10L * 2;
promote 2 to long
2L * 2.0F;
promote 2L to float
promote to large data
byte, short, char are promote to int
unary operators not apply
Assigning values
Assign operator
binary operator
Casting
unary operator
fit large into small
Compound Assignment Operators
+=, -=, *=, /=
camel *= giraffe
compound
already defined variable
long goat = 10;
int sheep = 5;
sheep += goat;
with compound cast automatically
Assignment operator return value
statement
int max = 5;
int value = (max = 3);
boolean healthy = false;
if(healthy=true) {}