operatorsII Flashcards
List the other of operators. Yes all of them
Post-unary operators expression++, expression–
Pre-unary operators ++expression, –expression
Other unary operators +, -, !
Multiplication/Division/Modulus *, /, %
Addition/Subtraction +, -
Shift operators «,»_space;,»_space;>
Relational operators <, >, <=, >=, instanceof
Equal to/not equal to ==, !=
Logical operators &, ^, |
Short-circuit logical operators &&, ||
Ternary operators
Assignment operators
Post-unary operators
expression++
Pre-unary operators
++expression
Other unary operators
+, - and !
Shift operators
> > , «.»_space;>
Relational operators
> , <, >=, instance of
Logical operators
&, ^, |
Short circuit logical operators
&&, II
The if-then Statement
allowing our application to execute
a particular block of code if and only if a boolean expression evaluates to true at runtime.
if(booleanExpression) {
// Branch if true
}
remember it’s a instanceof b
instanceof
NOT
instanceOf
what is a instanceof b?
True if the reference that a points to is an instance of
a class, subclass, or class that implements a particular
interface, as named in b
Common use of short circuit operator?
A more common example of where short-circuit operators are used is checking for null
objects before performing an operation, such as this:
if(x != null && x.getValue() < 5) {
// Do something
}
if x is null, it’s false and it wont go to x.getValue() and avoid nullpointer exception
if(x != null & x.getValue() < 5) {
// Do something
}
if(x != null && x.getValue() < 5) {
// Do something
}
if(x != null & x.getValue() < 5) { // Throws an exception if x is null
// Do something
}
What is the output?
int x = 6;
boolean y = (x >= 6) || (++x <= 7);
System.out.println(x);
true
short (other is not ever evualuated)
int hourOfDay =1;
int morningGreetingCount=0;
if(hourOfDay < 11)
System.out.println(“Good Morning”);
morningGreetingCount++;
System.out.println(morningGreetingCount);
mourningGreetingCount is 1