operatorsII Flashcards

1
Q

List the other of operators. Yes all of them

A

Post-unary operators expression++, expression–
Pre-unary operators ++expression, –expression
Other unary operators +, -, !
Multiplication/Division/Modulus *, /, %
Addition/Subtraction +, -
Shift operators «,&raquo_space;,&raquo_space;>
Relational operators <, >, <=, >=, instanceof
Equal to/not equal to ==, !=
Logical operators &, ^, |
Short-circuit logical operators &&, ||
Ternary operators
Assignment operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Post-unary operators

A

expression++

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Pre-unary operators

A

++expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Other unary operators

A

+, - and !

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Shift operators

A

> > , «.&raquo_space;>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Relational operators

A

> , <, >=, instance of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Logical operators

A

&, ^, |

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Short circuit logical operators

A

&&, II

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The if-then Statement

A

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
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

remember it’s a instanceof b

A

instanceof

NOT
instanceOf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is a instanceof b?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Common use of short circuit operator?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

if(x != null & x.getValue() < 5) {
// Do something
}

if(x != null && x.getValue() < 5) {
// Do something
}

A

if(x != null & x.getValue() < 5) { // Throws an exception if x is null
// Do something
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the output?
int x = 6;
boolean y = (x >= 6) || (++x <= 7);
System.out.println(x);

A

true
short (other is not ever evualuated)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

int hourOfDay =1;
int morningGreetingCount=0;
if(hourOfDay < 11)
System.out.println(“Good Morning”);
morningGreetingCount++;
System.out.println(morningGreetingCount);

A

mourningGreetingCount is 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Will it compile?
int x = 1;
if(x) {

}

A

DNC
int x = 1;
if(x) { // DOES NOT COMPILE

}

17
Q

int x = 1;
if(x = 5) {

}

A

DNC
int x = 1;
if(x = 5) { // DOES NOT COMPILE

}