Week 11 Part 2 Flashcards

1
Q

o T/F – each element in an Array is the same data type.

A

True

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

o T/F – Each element in an array is differentiated by a subscript

A

True

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

o T/F – Each array element can be used in the same way as a single item of the same data type

A

True

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

o Arrays can be used to replace __ structures with several different user inputs

A

if

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

o It’s good practice to use _________ for array sizes

A

constants

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

o Why are constants good for array sizes?

A

Easier to change the array size later, removes magic numbers

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

o The most basic method of searching an array is

A

A linear search in a loop where the loop control variable also acts as the arrays index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • What is a Parallel Array?
A

An array that runs concurrent to another. One array for different pieces of data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  • Why should we not use Parallel Array in Java?
A

High maintenance, you need to keep the array indexes synchronized

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

o Solution to Parallel Array problem

A

Create a record object that an array can reference instead

customer Cust = new Customer(id, name, house);
Index[index] = customerId(index+1, name, house)
index [2] = customerId(index+1, name, house)

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

o A ___ loop is a natural way to sequentially access each element in an array. What is this process known as?

A

For, iterating over the array

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

What is an array in Java?

A

An object or reference type. It’s of reference regardless of whether the stored values are primitive.

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

Java can have elements of __________ type or _________

A

primitive, reference

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

o In java indexes are ____ or anything that can be promoted to an ___

A

Ints, int

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

o The lowest index value for an array is _

A

0

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

o T/F – In java, an array can be resized after it is instantiated

A

False

17
Q

T/F - every array has a final instance field “length”

A

True

18
Q

o What is the command for the size of the array? Will this let you change the array size?

A

arrayName.length. No

19
Q

o Once instantiated, are arrays aware of their size in Java?

A

Yes

20
Q

o A: DataType arrayName[]; B: DataType[] arrayName; Which syntax is preferred?

A

B

21
Q

o Array reference variables are automatically set to ____ after they are declared

A

Null (might be better to set this explicitly to help other programmers)

22
Q

o If we declare an array - num int[] numbers; - Does this place an array object in memory?

A

 No, this is only a declaration

23
Q

o Are either of these local scope array reference variables initialized? Is this behaviour consistent with other local scope reference variables?

Public void doStuff(){
String[] someNumbers;
String[] otherNumbers = null; }

A

String[] someNumbers is not initialized, String[] otherNumbers = null is initialized.

This is the same as other local scope reference variables. NOTE – they are still just declarations, not array objects

24
Q

o T/F – You are permitted to specify the size of the array in the same box when declaring it in Java

A

False

25
Q

o T/F – You are permitted declare and initialize an Array on the same line

A

True