Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
82 Cards in this Set
- Front
- Back
True or False? equals(), hashCode(), and toString() are private? |
False. They're public |
|
Why should you override toString()? |
So that System.out.println() or other methods can see something useful, like your object's state |
|
== compared to equals() |
== used to determine if two REFERENCE VARIABLES are meaningful equivalent equals() determines if two OBJECTS are meaningfully equivalent |
|
If you don't override equals() what will happen to your objects. (In regards to hashing keys) |
Your objects won't be useful hashing keys |
|
If you don't override equals() what will happen to your objects. (In regards to different objects) |
Different objects can't be considered equal |
|
Stings and wrappers do what that make them good hashing keys? |
override equals() |
|
What should you do when you override equals()? (in regards to comparing objects) |
Use instanceof operator to be sure yo're evaluating an appropriate class and compare the objects' significant attributes |
|
If x.equals(y) is true, then what is true about x and y's hashcodes? |
They're equal |
|
What must you do to hashCode() if you override equals()? |
If you override equals() you must override hashCode() |
|
How are the keys and buckets distributed in an efficient hashCode()? |
The keys are evenly distributed across its buckets |
|
An overridden equals() must be ____________ as precise as its hashCode() mate |
at least |
|
What variables aren't appropriate for equals() and hashCode()? |
transient |
|
collection meaning: |
Represents the data structure in which objects are stored |
|
Collection meaning: |
java.util interface from which Set and List extend |
|
Collections meaning: |
A class that holds static collection utility methods |
|
Definition of "Lists of things": |
Ordered, duplicates allowed, with an index |
|
Definition of "Sets of things": |
May or may not be ordered and/or sorted; duplicates NOT allowed |
|
Definition of "Maps of things with keys": |
May or may not be ordered and/or sorted; duplicate keys are NOT allowed |
|
Definition of "Queues of things to process": |
Ordered by FIFO or by property |
|
Definition of Ordered: |
Iterating through a collection in a specific, non-random order |
|
Definition of Sorted: |
Iterating through a collection in a sorted order |
|
Key Attributes of Common Collection Classes ArrayList: |
Fast iteration and fast random access |
|
Key Attributes of Common Collection Classes Vector: |
Like a slower ArrayList, but it has synchronized methods |
|
Key Attributes of Common Collection Classes LinkedList: |
Good for adding elements to the ends, i.e., stacks and ques |
|
Key Attributes of Common Collection Classes HashSet: |
Fast access, assures no duplicates, provides no ordering |
|
Key Attributes of Common Collection Classes LinkedHashSet: |
No duplicates; iterates by INSERTION order |
|
Key Attributes of Common Collection Classes TreeSet: |
No duplicates;iterates in SORTED order |
|
Key Attributes of Common Collection Classes HashMap: |
Fastest updates (key/values); allows one null key, many null values |
|
Key Attributes of Common Collection Classes Hashtable: |
Like a slower HashMap (as with Vector, due to its synchronized methods). No null values or null keys allowed |
|
Key Attributes of Common Collection Classes LinkedHashMap: |
Faster iterations; iterates by INSERTION ORDER OR LAST ACCESSED; allows one null key, many null values |
|
Key Attributes of Common Collection Classes TreeMap: |
A sorted map |
|
Key Attributes of Common Collection Classes PriorityQueue: |
A to-do list ordered by the elements' priority |
|
Collections hold only ________? But what about primitives? |
Collections hold only Objects, but primitives can be autoboxed |
|
Iterator hasNext(): |
determines if more elements exist; the Iterator does NOT move |
|
Iterator next() |
returns the next element AND moves the Iterator forward |
|
What must a Map's keys do to correctly use Collection classes? |
A map's keys must override equals() and hashCode() |
|
Queues use offer() to... |
add an element |
|
Queues use poll() to... |
remove the head f the queue |
|
Queues use peek() to... |
look at the head of the queue |
|
HashMap (Map/Set/List, ordered, sorted) |
Map NOT ordered NOT sorted |
|
Hashtable (Map/Set/List, ordered, sorted) |
Map NOT ordered NOT sorted |
|
TreeMap (Map/Set/List, ordered, sorted) |
Map Ordered Sorted (by natural or custom comparison rules) |
|
LinkedHashMap (Map/Set/List, ordered, sorted) |
Map Ordered by insertion order or last access order NOT sorted |
|
HashSet (Map/Set/List, ordered, sorted) |
Set NOT ordered NOT sorted |
|
TreeSet(Map/Set/List, ordered, sorted) |
Set Ordered Sorted by natural order or custom comparison rules |
|
LinkedHashSet(Map/Set/List, ordered, sorted) |
Set Ordered by insertion order NOT sorted |
|
ArrayList (Map/Set/List, ordered, sorted) |
List Ordered by index NOT sorted |
|
Vector (Map/Set/List, ordered, sorted) |
List Ordered by index NOT sorted |
|
LinkedList (Map/Set/List, ordered, sorted) |
List Ordered by index NOT sorted |
|
PriorityQueue (Map/Set/List, ordered, sorted)
|
NONE Sorted Sorted by to-do order |
|
You can create/extend "backed" sub-copies of which two Common Collection Classes? |
TreeSets TreeMaps |
|
What must we do first to start sorting and searching Arrays and Lists so that it provides ONLY ONE sort order? |
Implement Comparable using compareTo() |
|
How do we create MANY Comparators to sort a class in many ways? |
Implement compare() |
|
What must happen to an Array or List before it can be searched? |
The Array or List must be sorted first |
|
Difference between lower() and floor() |
lower() returns the element less than the given element, and floor() returns the element less than OR EQUAL TO the given element |
|
Difference between higher() and ceiling() |
higher() returns the element greater than the given element ceiling() returns the element greater OR EQUAL TO the given element |
|
java.util Utility Classes (two of them): |
Collections Arrays |
|
binarySearch() method |
Search a pre-sorted Array or List |
|
Array.asList() |
Creates a List from an array and links them together |
|
Collections.reverse |
Reverses the order of elements in a List |
|
Collections.reverseOrder() |
Returns a Comparator that sorts in reverse |
|
What do Generics allow you to do? |
They let you enforce compile-time type safety on Collections (or other classes and methods declared using generic type parameters) |
|
What kind of references can an ArrayList <Animal> accept? |
Animal or any subclass of it |
|
When is a cast NOT needed to get (declared type) elements out of the collection? |
When using generic collections Non-generic collections REQUIRE a cast |
|
True or False? You can pass a generic collection into a method that takes a NON-generic collection? |
True, but the results may be disastrous |
|
True or False? A compilation WARNING is considered a compilation ERROR or FAILURE |
False |
|
When does Generic type information exist? |
NOT at runtime It is a compile-time safety only |
|
Polymorphic assignments applies only to the ______ type, not the ________ type parameter |
base generic |
|
Which one can you say? List<Animal> aList = new ArrayList<Animal>(); List<Animal> aList= new ArrayList<Dog>(); |
List<Animal> aList = new ArrayList <Animal>(); Because Polymorphic assignments apply only to BASE types, NOT the generic type parameter |
|
Where does the polymorphic assignment rule apply to? |
Everywhere an assignment can be made. |
|
Why don't these two lines of code work? (different reasons) void foo(List<Animal> aList) {} List<Animal> bar() {} |
First one cannot TAKE a List<Dog> Second one cannot RETURN a List<Dog> |
|
Wildcard syntax allows for a generic method to... |
accept subtypes (or supertypes) or the declared type of the method argument |
|
Wildcard syntax. What can this method take? void addD(List<Dog> d) {} |
Can take only <Dog> |
|
Wildcard syntax. What can this method take? void addD(List<? extends Dog>){} |
Can take <Dog> or a subclass of dog |
|
The wildcard keyword extends is used to mean either _________ or __________ |
extends implements |
|
When using a wildcard, <? extends Dog>, what can the collection do and not do? |
The collection can be accessed but NOT modified |
|
When using a wildcard, List<?>, what type can be assigned to the reference? Is it for modifications? |
Any generic type can be assigned to the reference, but for access ONLY, NO modifications |
|
What type of object can List<?> or List<? extends Object> hold? Anything special about the object? |
It can hold any type of OBJECT. For access ONLY. |
|
What do T and E mean for declaration conventions for generics? |
T: for type E: for element |
|
The generics type identifier can be used in... |
class, method, and variable declaration class Foo<t> {} T anInstance; Foo(T aRef) {} |
|
True or False? You can use more than one parameterized type in a declaration? public class UseTwo<T, X> {} |
True |
|
True or False? You can declare a generic method using a type NOT defined in the class? public <T> void makeList (T t) {} |
True This method has a void return type, but to use T within the method's argument you must declare the <T>, which happens before the return type |