Week 5 and 6 Flashcards

1
Q

The order of statement execution in a method is called the …

A

“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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Logical operators – Boolean operands

A

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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

If-else statement

A

An if statement uses a boolean expression as

its condition.

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

While loop

A

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.

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

The ArrayList class defines …

A

an object that can hold a list of other objects called elements.

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

Common Methods of an ArrayList

A

-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

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

When comparing type char…

A

using the equality and relational operators (==, !=, , <=, >=)

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

When comparing types double and float…

A

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

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

Object types (other than the numeric wrapper classes) can be compared using …

A

the equality operators (==, !=), but in most cases the object’s equals() or compareTo() method should be used

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

values of char types A-Z vs a-z

A

A-Z numeric values 65-90. a-z numeric values 97-122

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

some classes provide a compareTo() which returns…

A

an int rather than a Boolean

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

equalsIgnoreCase and compareToIgnoreCase

A

methods for the String class

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

nested statements

A

when an if-else is inside another if-else statement. same with while statements.

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

infinite loops

A

common logical error

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

break statement

A

in a loop will skip the rest of the code in that iteration and exit the loop

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

continue statement

A

will skip the rest of the code in that iteration and attempt the next iteration of the loop

17
Q

when reading a file use a …

A

FileNotFoundException (throw)

18
Q

iterator

A

an iterator is an object that allows you to process a collection of items one at a time.

  • hasNext() that returns true if there is at least one more item to process
  • next() returns the next item
19
Q

Switch statement:

A
  • the switch statement – very similar to the “if” statement (input is a char)
  • A switch statement can jump directly to the correct case, whereas an if-else-if-else as to evaluate each boolean expression until one is true or all are false
  • see diagrams
20
Q

Ternary operator

A

a way to make if-else statement more concise. (condition ? if result : else result)

21
Q

Do-While loop

A

Similar to a while loop, except that the Boolean expression is evaluated at the nd of the loop (the do-while statement is a post-test loop whereas the while statement is a pre-test loop)

§ This means the body of the do-while will always be executed at least once, regardless of whether the boolean expression is true

-see diagrams

22
Q

For loop

A

Similar to the while loop, but well-suited for iterating a specific number of times or over a range of values. (for (initialization; termination – Boolean; increment))

23
Q

An ArrayList is an Iterable object

A

which means it can be the target of the “for-each” statement
-for (“ArrayList Object type” “variable use to reference current item in each iteration”: variable name for the ArrayList)