Chapter 5 PDF Flashcards

1
Q

Describe sequence in the flow of control

A

Execute instructions in order

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

Describe method calls in the flow of control

A

Transfer control to method, execute instructions in method, then return with or without a value

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

Describe selection in the flow of control

A

Execute different instructions depending on the data

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

Describe looping in the flow of control

A

Repeat a set of instructions for different data

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

Describe equality operators

A

They’re used to determine if the values of two expressions are equal or not equal

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

What is special about equality operators

A

Must be used with a primitive data type and object references, not to compare object data

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

What is a common error made with equality operators

A

Equality operators (==) and easily confused with the assignment operator (=)

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

What is relational operators used for

A

Relational Operators are used to compare the values of two expressions

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

What is the result for relational operators

A

The result for relational operators is either true or false

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

What is ! used for in programming

A

! is the NOT operator

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

What is the ! (NOT OPERATOR) used for

A

The NOT operator is used to evaluate to the inverse of the value of its operand. (EX: If the operand is true the result will be the opposite)

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

What is && used for in programming

A

&& is the AND operator

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

What is the && (AND OPERATOR) used for

A

The AND operator takes two boolean expressions as operands, if both operands are true then the result is true. Otherwise the result is false.

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

What is || used for in programming

A

|| is the OR operator

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

What is the OR operator used for

A

The OR operator takes two boolean expressions as operands. If both operands are false, the result will be false and otherwise it’ll be true.

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

In any logical operator, how are the operands evaluated?

A

Operands are evaluated left to right for any logical operator

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

What occurs if the result of the logical operator can be determined after evaluating the first operand

A

Only the first operand will be evaluated and the second one will be ignored

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

What is the result if the first operand of an OR statement is true

A

The result of the statement will be TRUE

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

What is the result if the first operand of an AND statement is false

A

The result of the statement will be FALSE

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

What is a common error when testing three ints

A

Each operand of a logical operator must be a boolean expression or else you will have a compiler error

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

What are DeMorgans Laws

A
  1. NOT( A AND B ) = ( NOT A ) OR ( NOT B )

2. NOT( A OR B ) = ( NOT A ) AND ( NOT B )

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

How would you find an equivalent expression using DeMorgans Laws

A
  1. Change AND to OR
  2. Change OR to AND
  3. NEGATE EACH OPERAND EXPRESSION
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is an if statement used for

A

If statements are used when the program should perform an operation for one set or data but do nothing for all other data

24
Q

What is special about curly brackets if the true block of an if statement only contains one statement

A

Curly braces are optional if the true block contains only one statement

25
Describe a simple IF Flow of Control
If the condition evaluates to true, the true block is executed. If the condition evaluates to false, the true block is skipped
26
What is a a common error with if statements
Do not put a semicolon after the condition in an if statement. Doing so would indicate that the true block is empty and will cause a logic error
27
When is the if/else statement used
Used when Data falls into two mutually exclusive categories and the program should perform different operations for each set of data
28
What is special about curly brackets if the true block of an if/else statement only contains one statement
Curly braces are optional if the true block contains only one statement
29
Describe an id/else flow of control
If the condition is true, then the true block is executed. | If the condition is false then the false block is executed
30
What is scope
The region within a program where an identifier can be referenced.
31
Where does the scope of a variable end and begin
The scope of a variable extends from the point of declaration to the end of the block in which it is declared
32
What are some examples of blocks
Classes Methods If statements true and false blocks
33
When is an if/else if statement used
Used when data falls into multiple, mutually exclusive categories and the program should perform different operations for each set of data
34
Describe the if/else if Flow of Control
* If the first condition is true, the first true block is executed. The rest of the if/else statement is skipped. * If the n^th condition is true then the n^th true block is executed. The rest of the if/else statement is skipped. * If no condition is true, the false block is executed.
35
What are nested if statements
If statements can be written as part of the true or false block of another if statement.
36
What is needed if you nest an if statement
If you nest an IF statement more information is required beyond the results of the first if condition
37
What occurs if you don't assign an else clause in a nested if statement
The compiler will match any else clause with the most previous if statements that doesn't already have an else clause
38
What can curly brackets be used for in a nested if/else statements
You can use curly brackets to force a desired if/else pairing
39
What is a "Dangling Else"
A dangling else occurs when an else clause cannot be paid with an if condition
40
What can occur with floating point representation
Minor rounding errors can occur in calculations, causing the equality operator not to consider the values equal.
41
How do we solve the equality operator not being able to consider values equal (in relation to rounding errors)
Consider a small threshold value. If the absolute value of the difference between the two values is less than the threshold value, then the two floating point numbers will be considered equal.
42
What does the equality operator compare
The equality operator compares object references. ie: compares that they point to the same object... doesn't compare the data
43
How would you compare object data instead of comparing the objects themselves
You would use the equals method
44
What is the common error when using equality operators
You do not use equality operators to compare object data, instead use the equals method
45
What are strings considered
Strings are objects (data)
46
How would you compare two strings
Use the equals method since Strings are objects (data)
47
What does a conditional operator do
A conditional operator contributes one of two values to an expression based on the value of the condition
48
What are some uses of conditional operators
Handling invalid input | Outputting similar messages
49
When is a switch statement used
In some selection operators, the switch statement can be used instead of an if/else/if statement
50
What are the requirements for using a switch statement
Can be used when we are comparing the value of an expression to constant intergers (byte, short, int), characters (char) or Strings.
51
How is the switch operation performed
The expression is evaluated, then its value is compared to the case constants in order. When a match is found, the statements following that case constant are executed in sequence until either a break statement or the end of a switch block is reached.
52
What are some optional aspects when using a switch statement
The break statement is optional The default label and its statements are also optional The statements under the case constant are also optional
53
Why is the break statement optional when using a switch statement
The break statement is optional when using a switch statement because the job of the break is to terminate execution of the switch statement
54
Why is the default label and its statements optional when using the switch statement
The default label is optional because they are executed only when the value of the expression does not match any of the case constants
55
Why are the statements under the case constant optional when using a switch statement
The statements under the case constant are also optional so multiple case constants can be written in sequence if identical operations will be performed for those values
56
What are common errors with break statements
(Remember that once a match is found, all succeeding statements are executed until a break statement is encountered). Be careful to code a break statement when you have finished the processing of a value, otherwise you may execute unintended statements