mode 5 Flashcards
What are generics?
Generics use angle brackets to create a “placeholder” for a future datatype.
They’re a type of polymorphism
Do generics work with primitives?
GENERICS DO NO WORK WITH PRIMITIVES, ONLY OBJECTS
How do I instantiate a generic object?
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.
Is it good practice to make your generics objects?
Why?
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.
What is Compile Time Safety?
Compile-time safety means that the compiler can analyze your code and guarantee that certain kinds of errors are not present.
What is the instanceof keyword?
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
What is a Collection or Collection API in Java?
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.
What is Collections
CollectionSSS is a utility class filled with static methods that aid with objects that are of type “Collection”
The Collection API Hierachy
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]
What is the difference between ArrayList & Vector, and HashMap & HashTable
They’re all the same thing respectively, except one is threadsafe (Vector and HashTable)
What is a List?
An indexable group of data entries, duplicates are allowed.
What is a Set?
A non-indexable groupd of data entries, NO DUPLICATES ARE ALLOWED
What is a Queue?
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)
What is a Map?
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
What is a binary tree?
A tree that has at most two child nodes