Week 5 and 6 Flashcards
The order of statement execution in a method is called the …
“flow of control”
- Sequence - sequential
- selection – statements that allow us to decide whether or not to execute a particular statement. (if, if-else, switch statements)
- iteration – repetition – statements that allow us to execute a statement (while, do-while, for statements.)
- Boolean expressions are used by Selection and Iteration statements to determine whether a statement is executed.
Logical operators – Boolean operands
True or False results
- ! Logical NOT (applied before && and ||)
- && Logical AND (applied ||) (SHORT circuited if the first is false other isn’t evaluated.
- || Logical OR (SHORT circuited if the first is TRUE then the other isn’t evaluated.
If-else statement
An if statement uses a boolean expression as
its condition.
While loop
A while statement (or while loop) will continually execute a statement or block of statements as long as its condition (Boolean expression) is true; i.e., it repeats the statement or block) until the condition is false.
-ANY variables in the Boolean expression need to be initialized BEFORE the loop.
The ArrayList class defines …
an object that can hold a list of other objects called elements.
Common Methods of an ArrayList
-add(): adds an object to the list
-remove(): removes an object or the object at a specified index
-get(): returns the object at the specified index
-indexOf(): returns the index of the specified object
(indexed from 0)
-size(): returns the number of objects in the list
When comparing type char…
using the equality and relational operators (==, !=, , <=, >=)
When comparing types double and float…
should use == or != with care due to possible rounding; best to check that the absolute value of the difference between two items is less a specified tolerance
Object types (other than the numeric wrapper classes) can be compared using …
the equality operators (==, !=), but in most cases the object’s equals() or compareTo() method should be used
values of char types A-Z vs a-z
A-Z numeric values 65-90. a-z numeric values 97-122
some classes provide a compareTo() which returns…
an int rather than a Boolean
equalsIgnoreCase and compareToIgnoreCase
methods for the String class
nested statements
when an if-else is inside another if-else statement. same with while statements.
infinite loops
common logical error
break statement
in a loop will skip the rest of the code in that iteration and exit the loop