What is a selection statement?
A statement that lets you choose actions with alternative courses based on conditions
What is a Boolean expression?
An expression that evaluates to a Boolean value: true or false
What is the boolean data type used for?
To declare a variable with the value either true or false
What are the 6 relational operators in Java?
< (less than), <= (less than or equal), > (greater than), >= (greater than or equal), == (equal to), != (not equal to)
What is the equality testing operator?
== (two equal signs, not one)
What is the difference between = and ==?
= is assignment operator, == is equality testing operator
What are Boolean literals?
true and false (not keywords, but reserved words)
What is the syntax for a one-way if statement?
if (boolean-expression) { statement(s); }
What shape represents a Boolean condition in a flowchart?
Diamond box
What shape represents statements in a flowchart?
Rectangle box
Can you omit braces in an if statement?
Yes, if there’s only one statement, but it’s error-prone
What is the syntax for a two-way if-else statement?
if (boolean-expression) { statements-for-true; } else { statements-for-false; }
What is a nested if statement?
An if statement inside another if statement
What is a multi-way if-else statement?
A series of if-else statements for multiple alternatives, preferred style for readability
What are the 4 logical operators in Java?
! (not), && (and), || (or), ^ (exclusive or)
What does the ! operator do?
Negates true to false and false to true
When is && (and) true?
Only when both operands are true
When is || (or) true?
When at least one operand is true
When is ^ (exclusive or) true?
When operands have different Boolean values (p1 ^ p2 same as p1 != p2)
What are short-circuit operators?
&& and || - they don’t evaluate second operand if first determines the result
What is De Morgan’s law?
!(condition1 && condition2) = !condition1 || !condition2, and !(condition1 || condition2) = !condition1 && !condition2
What data types can be used in switch expressions?
char, byte, short, int, String
What is fall-through behavior in switch?
When break is omitted, execution continues to next case
What is the syntax for switch statement?
switch (expression) { case value1: statements; break; default: statements; }