mode 5 Flashcards

1
Q

What are generics?

A

Generics use angle brackets to create a “placeholder” for a future datatype.

They’re a type of polymorphism

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

Do generics work with primitives?

A

GENERICS DO NO WORK WITH PRIMITIVES, ONLY OBJECTS

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

How do I instantiate a generic object?

A

when instantiating a generic object you must provide the datatype that THIS instance will be using from now on;

i. e from this point this SPECIFIC OBJECT cannot change the datatype it will
* be working with.
*
* But OTHER INSTANCES of this generic class can “work with” other datatypes.

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

Is it good practice to make your generics objects?

Why?

A

It is NOT good practice to make your generics objects, (though there ARE cases where they actually NEED to be objects)

The reason it is bad practice is because making a more broad generic does not allow you to have compile time safety.

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

What is Compile Time Safety?

A

Compile-time safety means that the compiler can analyze your code and guarantee that certain kinds of errors are not present.

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

What is the instanceof keyword?

A

The instanceof keyword checks whether an object is an instance of a specific class or an interface. The instanceof keyword compares the instance with type. The return value is either true or false

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

What is a Collection or Collection API in Java?

A

A collection is a data structure that contains object. Aka an object that contains other objects.

There are MANY types of data structures in computer science.

The collection API is Java has a lot of these data structures already created for you. So you don’t need to create them yourself.

Lastly, built in datastructures are EXTREMELY optimized.

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

What is Collections

A

CollectionSSS is a utility class filled with static methods that aid with objects that are of type “Collection”

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

The Collection API Hierachy

A

Iterable [i]
Collection [i]
List [i]: ArrayList [c], LinkedList[c], Vector [c]
Set [i]: HashSet [c], SortedSet [i]: TreeSet [c]
Queue [i]: Deque [i], PriorityQueue [c]

Map [i]
HashMap[c]
TreeMap [c]
HashTable [c]

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

What is the difference between ArrayList & Vector, and HashMap & HashTable

A

They’re all the same thing respectively, except one is threadsafe (Vector and HashTable)

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

What is a List?

A

An indexable group of data entries, duplicates are allowed.

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

What is a Set?

A

A non-indexable groupd of data entries, NO DUPLICATES ARE ALLOWED

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

What is a Queue?

A

A group of data entries that has an order to them, and is designed to remove elements in a specific order: firs in first out (FIFO)

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

What is a Map?

A

A Map is a key-value pair. It holds a group of data entries, but each data entrie (value) can only be retrieved if you have a “key” to reference it

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

What is a binary tree?

A

A tree that has at most two child nodes

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

What is Big-O notation?

A

big-o notation is a measure of how FAST (or how space efficient) an algorithm is
in its worst case scenario.

17
Q

heirarchy of big-O, Omega, Theta

A

big o is worst case
big theta is average case
big omega is best case

18
Q

What is the difference between comparable and comparator

A

Comparable