Lecture 8B Flashcards

1
Q

In Java we must wrap functions in objects to pass them around. How is this realized?

A

Use interfaces with just a single abstract method. And of course classes which implement this interface. Note: a functor can be realized using an anonymous class (a class without s name).

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

Do you require generics to use functors?

A

No, but it increases type safety.

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

Arrays are only efficient for…

A

Random access and if the length of the collection does not need to change, no insertion and deletion.

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

Which package is ye collections framework in?

A

java.util.

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

Collections are similar to arrays but more powerful and flexible (albeit slower if dynamic size not needed). Can collections store primitives?

A

No. Try need to be boxed and unboxed using a wrapper class.

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

What are basic operations derived from collection interface?

A

Add(e), remove(e), clear(), contains(e), size()

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

What are four interfaces that extend interface collection?

A

Set, List, Queue, Map

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

What is a Set?

A

Extends interface Collection. Does not contain duplicate elements. Elements in no particular order. However there are also ordered sets.

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

Three types of Set:

A

HashSet (fast search), LinkedHashSet (maintains order, slower), TreeSet (sorts elements using comparable interface).

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

All classes in the collections Api are generic, but can be used non-generically.

A

Ok

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

Charachteristics of Lists?

A

Allow duplicates, always maintain order (the order in which they are added). Dynamic size. ArrayList stores linear sequence, LinkedList stores by connecting pointers, not a continuous block of memory.

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

When to use Arraylist versus LinkedList?

A

If only need to add element at end of list-ArrayList. Also speedy, random access. If need to insert or remove elements form other positions then LinkedList. Slower.

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

Explain Vector and Stack?

A

Vector like ArrayList but thread safe. Stack derived from Vector and allows last-in-first-out LIFO methods: pop(), push(e), peek()

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

LinkedList also implements queues interface. Which allows…

A

FIFO.

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

What are maps?

A

They allow to associate keys with values - keys can be objects not just numbers.

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

What is a functor?

A

An object which represents a function. Often used for passing a method as an argument to another method. Typical use: callbacks, such as event handlers. They are a pattern, not a new language element.