chapter 4 Flashcards
What is a statement in Java?
A complete unit of execution in Java, terminated with a semicolon.
What does an if statement allow for?
An application to execute a particular block of code if and only if a boolean expression evaluates to true at runtime.
What is a switch statement?
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.
What is the structure of a switch statement?
switch (variableToTest) { case constantExpression: // code break; ... default: ... } cases and default are optional.
What types of variables do switch statements support?
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)
What is the default block of a switch statement?
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.
When will a default block in a switch statement execute even after there has been a matching case value within the switch?
if the default block is encountered after a case statement for which there is no terminating break statement.
What must the values of each case statement be?
literals, enum constants, or final constant variables of the same data type as the switch value.
What type of numeric promotion do switch statements support?
type that does not require an explicit cast.
What is a loop?
A repetitive control structure that can execute a statement of code multiple times in succession.
What is the difference between a while and a do/while loop?
A do/while loop is guaranteed to execute the block of code or statement at least one time.
What are the two things the right side of a for-each loop can be?
A built-in Java array
An object whose type implements java.lang.iterable
What is an option label?
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.
What does a break statement do?
Transfers the flow of control out to the enclosing statement.
Where do break statements transfer control?
To the enclosing statement.