chapter 4 Flashcards

1
Q

What is a statement in Java?

A

A complete unit of execution in Java, terminated with a semicolon.

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

What does an if statement allow for?

A

An application to execute a particular block of code if and only if a boolean expression evaluates to true at runtime.

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

What is a switch statement?

A

A complex decision-making structure in which a single value is evaluated and flow is redirected to the first matching branch, known as a case statement. If no such matching case statement is found, an optional default statement will be called or the entire switch will be skipped.

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

What is the structure of a switch statement?

A
switch (variableToTest) {
  case constantExpression: 
    // code
    break;
  ...
  default: 
    ...
} 
cases and default are optional.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What types of variables do switch statements support?

A
int and Integer,
byte and Byte, 
short and Short,
char and Character,
String,
enum values,
var (if type resolves to one of the preceding ones)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the default block of a switch statement?

A

A block that is branched to only if there is no matching case value for the switch statement, regardless of its position within the switch statement.

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

When will a default block in a switch statement execute even after there has been a matching case value within the switch?

A

if the default block is encountered after a case statement for which there is no terminating break statement.

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

What must the values of each case statement be?

A

literals, enum constants, or final constant variables of the same data type as the switch value.

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

What type of numeric promotion do switch statements support?

A

type that does not require an explicit cast.

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

What is a loop?

A

A repetitive control structure that can execute a statement of code multiple times in succession.

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

What is the difference between a while and a do/while loop?

A

A do/while loop is guaranteed to execute the block of code or statement at least one time.

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

What are the two things the right side of a for-each loop can be?

A

A built-in Java array

An object whose type implements java.lang.iterable

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

What is an option label?

A

An option label is an optional pointer to the head of a statement that allows the application flow to jump to it or break from it. It is a single identifier that is proceeded by a colon.

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

What does a break statement do?

A

Transfers the flow of control out to the enclosing statement.

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

Where do break statements transfer control?

A

To the enclosing statement.

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

Where do continue statements transfer control?

A

To the boolean expression that determines if the loop should continue.

17
Q

What is true of code placed immediately after a continue, break, or return statement?

A

It will cause a compiler error of unreachable code.