1: Qs wk 3 Flashcards

1
Q

Name the two equality operators and what types of data they operate on

A

== and != are sometimes called equality operators. They can be used on any kind of data, whereas the other four relational operators are limited to the 6 numeric types plus type char.

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

Describe how relational operators may be used to compare char values.

A

Each character has a unicode number associated with it.

  1. Space has the lowest unicode character.
  2. Numbers as characters, i.e. ‘1’, ‘2’, ‘3’, etc. start at Unicode #48.
  3. Uppercase letters come before lowercase letters (i.e. the uppercase letters have a lower Unicode number than lowercase letters).

E.g.

‘X’ > ‘A’ is true (because the code for ‘X’ is bigger than the code for ‘A’)
‘3’ > ‘0’ is true (because the code for ‘3’ is bigger than the code for ‘0’)
‘b’ > ‘W’ is true (because all lower-case letters have higher codes than any upper-case letter)

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

What is identity equality?

A

== and != may also be used with object references. Comparing object references with != or == compares the references of the objects (memory addresses) directly. That means we are testing to see if they refer to the same object.

Identity equality: obj1 == obj2

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

What is content equality?

A

Content equality is different from identity equality (in which we are using == or != to compare object references). Content equality is testing to see if two objects are considered to be equal.

Content equality: obj1.equals(obj2)

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

What are the Boolean operators?

A

! (NOT)
&& (AND)
|| (OR)

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

Write an operator precedence table

A

parentheses; array subscript; member selection: () . [ ] .
unary postfix operators: expr++ . expr–
unary prefix operators: ++expr –expr +expr -expr !(NOT)
instantiation; type cast: new . (type)
multiplicative: * / %
additive: + -
relational and instanceof : < > <= >= instanceof
equality: == !=
logical AND: &&
logical OR: ||
conditional: ? :
assignment: = += -= *= /= %=

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

Compound condition

A

A compound condition is one that makes use of logical operators to join ‘sub conditions.q’

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

What is a predicate method?

A

A method that returns type boolean is called a predicate method. The equals method used to test for content equality is an example of a predicate method.

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

What is “multi-way selection”?

A

A “multi-way selection” situation is a situation in which one choice is made from a set of three or more possibilities. There are always multiple conditions in multi-way selection structures.

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

What is a switch statement?

A

A switch statement is a control structure used to perform multiway selection when the decision can be made by matching specific values of a variable or expression. The switch statement tries to match the value of an expression with one of several specific values listed in case statements. The action associated with the first match is executed.

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

Loop control variable

A

The variable that has its value tested before entering the loop is known as a loop control variable. The loop control variable must be initialized - given an initial value - before it is tested. The loop control variable must also be updated, so that there is a way for the loop to terminate. The update needs to be inside the body of the loop.

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

Name the 5 key elements of a loop.

A
  1. Initialization. Set up the proper conditions for the start of the loop, including identifying and assigning an initial value to the loop control variable.
  2. Loop test. Specify the conditions that must be satisfied for the loop to be executed.
  3. Main work. Statements to be executed during each iteration of the loop.
  4. Update. The value of the loop control variable must be changed inside the body of the loop.
  5. Finalization. Add any final steps to properly wrap things up.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Explain the difference between definite and indefinite loops.

A

With a definite loop, such as counting loops, you can tell from the algorithm how many times it will iterate. With indefinite loops, you will not know in advance how many times the loop will iterate.

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

What are the three different control (loop) structures in Java?

A

while
for
do…while

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

What is a pre-test loop?

A

Both the while and for loop are pre-test loops, because the test of the loop control variable happens before the first iteration of the loop can happen. This allows for the possibility that the loop will never be executed.

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

What is a post-test loop?

A

A do…while loop is an example of a post-test loop. This loop is written so that they body of the loop is written before the loop test appears in the code, which means that the body of the loop is executed once before the test happens.

do
{
body of the loop
} while ( test_expression );

17
Q

Counter

A

A counter is a variable that has its value changed by a fixed amount with each iteration of the loop.

18
Q

Accumulator

A

An accumulator is a variable used to “accumulate” information (by having its value changed) during the execution of a loop.

19
Q

Flag

A

A flag is a variable used to remember if a certain condition has been satisfied during the execution of the loop.