Operators and Statements Flashcards

1
Q

What would the operation 10/3 output?

A

3

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

If two values have different data types and have an operator applied to them …

A

Java will automatically promote one of the values to the larger of the two data types

short a = 1;
int b = 1;
a+b will be an int

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

If one of the values is integral and the other is floating point and they have an operator applied to them …

A

Java will automatically promote the integral value to the floating-point value’s data type

int a = 1;
double b = 1.0;
a+b will be a double

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

When byte, short, and char are involved in a binary operation …

A

They are promoted to int before operation, even if neither operand is an int

short a = 10;
byte b = 5;
a/b will be an int

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

What is the output?

int counter = 0;
System.out.println(counter); 
System.out.println(++counter);  
System.out.println(counter); 
System.out.println(counter--);  
System.out.println(counter);
A
0
1
1
1
0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

x & y

booleans

A

Result same as x && y

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

x | y

booleans

A

Result same as x || y

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

x ^ y

booleans

A

Exclusive or

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

With x || y and x && y if x is true (for ||) or x is false (for && y) then …

A

y is not evaluated

Note: not the case for | and &

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

Two references are equal if and only if ….

A

They point to the same object or both point to null

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

What are the boolean values of 0 and 1?

A

Nothing! They mean nothing in the boolean world of Java!

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

booleanExp ? exp1 : exp2

A

If booleanExp is true, then execute exp1, otherwise execute exp2

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

switch statement syntax

A
switch (variableToTest) {
    case constantExp:
             //Code to run
             break;
    default:
             //Code to run
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the data types supported by switch statements?

A

1) byte and Byte
2) short and Short
3) char and Character
4) int and Integer
5) String
6) enum values

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

What are the three types of values you can use for case values in a switch statement?

A

A literal, enum constant, or a final constant variable

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

do-while statement syntax

A
do {
     //Code to be executed
} while (booleanExp);
17
Q

for-each loop syntax

A
for (datatype instance : collection) {
     // Code to be executed
}
18
Q

Statement Labels

A

You can add a label to a block statement to allow the application flow to jump to it or break from it.
Usually only used in loop structures, good for nested loops

MY_LABEL: for (int x : nums)

19
Q

How to break from a loop that is layers away

A

Add a label (MY_LABEL) to the loop, and code
break MY_LABEL;

Can do the same with continue