Term
| what is the default behavior of the toString() method? |
|
Definition
| The class of the object@unsigned hex representation of object's hash code |
|
|
Term
| What is the default behavior of equals method? |
|
Definition
| It uses the == to compare to see if two objects are equal. |
|
|
Term
| what are the implications of not overriding the equals() method. |
|
Definition
| they cant be used in hashmap as keys since the hashmap uses the equals method to see if search key is same as the object you provided. |
|
|
Term
| What is an important check that is required in an objects equals method? |
|
Definition
| the test to see if the Object is an instanceof the class. |
|
|
Term
| why must we caset the object into a moof before we call a getter method on it |
|
Definition
| because without the cast the compiler will try to call the given method on an Object and fail miserably |
|
|
Term
| can we use the default access modifier when overriding equals, hashCode() or toString()? |
|
Definition
| NO! they are default public and the default access modifier is more restrictive. |
|
|
Term
| what does it mean to say that equals method is reflexive? |
|
Definition
|
|
Term
| what does it mean to say that equals method is symmetric? |
|
Definition
| y.equals(x) then x.equals(y) |
|
|
Term
| What does it mean to say that the equals method is transitive? |
|
Definition
| x.equals(y) and y.equals(z) then x.equals(z) |
|
|
Term
| What does it mean to say that the equals method is consistent? |
|
Definition
| x.equals(y) will always return true if x and y dont change no matter weather it is called on sunday or monday. |
|
|
Term
| What is the fourth unamed rule of equals() |
|
Definition
| x.equals(null) should always be false. |
|
|
Term
| what is the relationship between the hashCode() method and the equals() method? |
|
Definition
| if equals() method says to objects are equal then their hashcodes should be the same. |
|
|
Term
| what happens if the hashcode method is implemented incorrectly? |
|
Definition
| objects that test equal using .eqauls() will not be found in Collections since hash code wont come out equal. |
|
|
Term
| does a hashcode that returns same value for all objects violate the exam contract? |
|
Definition
| No! since objects that are .equals() get the same hashCode since all objects get the same hashCode() |
|
|
Term
| What does a typical hashCode method do? |
|
Definition
| XORs instance variables and multiplies with a prime number |
|
|
Term
| what is the return type of the hashCode method. |
|
Definition
| the return type is always int. |
|
|
Term
| what is the requirement of hashCode changing when invoked on an object? |
|
Definition
| if no info changed in equals method is changed hashcode should return same integer. |
|
|
Term
| does the integer of hashcode need to remain same for all execution so it. |
|
Definition
| no need not be same between executions. |
|
|
Term
| if two objects are equal using .equals() what is the requirement of hashCode() |
|
Definition
| they must be equal ie equal objects must lie in same bucket. |
|
|
Term
| what if two hashcodes are not equal? |
|
Definition
| then they are not in same bucket and cannot be equal. |
|
|
Term
| why shouldnt we use transient variables in hashCode() |
|
Definition
| because when serialised their info will be lost. |
|
|
Term
| what can be done with objects in a collection? |
|
Definition
| add/remove , search/retrieve copy, iterate |
|
|
Term
| name the core collection interfaces? |
|
Definition
| Collection,List,Set,Map, SortedSet,SortedMap |
|
|
Term
| What is the Collections class? |
|
Definition
| Since it ends with s it is a class in java.util which provides static utility methods for use with collections |
|
|
Term
| Which collections class does not extend the Collection interface. |
|
Definition
| Map doesnt implement Collection interface. |
|
|
Term
|
Definition
|
|
Term
| what is diff between list an Set |
|
Definition
| set is unique things, while list can have duplicates |
|
|
Term
|
Definition
|
|
Term
| What does the term Ordered mean? |
|
Definition
| it means iterating through the list or set will always produce its contents in a certain order . eg Hashtable will not have an order any one iteration may differ from the next. |
|
|
Term
| What does Sorted Collection mean? |
|
Definition
| it means that elements are stored in their natural order. I dont know about the compareTo() method wheather there is such a thing in Java. |
|
|
Term
| How do you iterate through a collection? |
|
Definition
Iteratoer it = list.iterator(); while(it.hasNext()){ System.out.println(it.next()); } |
|
|
Term
| What are the general specialised methods of Lists |
|
Definition
| get(int index), indexOf(),add(int index,Object obj) |
|
|
Term
| What is a marker interface? |
|
Definition
| An interface with no methods implemented to give other classes information about the class. |
|
|
Term
| When should you choose ArrayList over LinkedList? |
|
Definition
| when you need fast iterations but wont do much iteration and deletion. eg. ArrayList implements RandomAccess interface |
|
|
Term
| Why do you want to use ArrayList |
|
Definition
| for fast iteration and retrieval while infrequent insertion and removal |
|
|
Term
| Does the Vector implement the RandomAccess Interface? |
|
Definition
| Vector is the only class apart from an ArrayList to implement the RandomAccess interface. |
|
|
Term
| When was ArrayList introduced into java language. |
|
Definition
|
|
Term
| What are the thread issues in using ArrayList? |
|
Definition
| array list methods are not synchronised you have to use the collection methods to get synchronisations |
|
|
Term
| How are LinkedList when compared to ArrayList? |
|
Definition
| insertion deletion is fast but random access is slow. Underlying data structure is a doubly linked list. |
|
|
Term
| What determines the uniqueness of a Set? |
|
Definition
| the .equals() method is typically used to determine the uniqueness of a set. |
|
|
Term
|
Definition
| it is a Set that is unordered and unsorted which is accessible using the elements hashCode() |
|
|
Term
| What is the difference between LinkedHashSet and HashSet? |
|
Definition
| LinkedHashSet is implemented with a with a doubly-linked list used to maintain the order of the elements. |
|
|
Term
|
Definition
| it is sorted collection implemented with red-black trees. Maintains the Natural order of elements |
|
|
Term
| Name two sorted Collection classes? |
|
Definition
|
|
Term
|
Definition
| creates a link between a key object and a value object. stored based on key object's hashCode() |
|
|
Term
| So what does HashMap do ? |
|
Definition
| Store unsorted unordered key value pairs, |
|
|
Term
| Can null be used as a key in HashMap? |
|
Definition
| Yes Null may be used as one of the keys |
|
|
Term
|
Definition
| nope only list and sets are collections. stands to reason as there is no concept of key in collectoins |
|
|
Term
| What is the difference between a HashMap and a Hashtable? |
|
Definition
1. that methods in Hashtable like Vector are synchronized. 1. that null cannot be used as key to Hashtable. 3. that t is little |
|
|
Term
|
Definition
| it has an order ie maintains insertion order. |
|
|
Term
| What are the advantages of HashMap over LinkedHashMap? |
|
Definition
| Adding and removing elements is slower. |
|
|
Term
| what are the advantages of LinkedHashMap over HashMap? |
|
Definition
| iteration is faster and maintains insertion order. |
|
|
Term
| what is a TreeMap how does it compare with a HashMap? |
|
Definition
| it is a sorted map. sorted by natural order of the key and allows you to specify what that order is. |
|
|
Term
| What does teh garbage collector do? |
|
Definition
| it finds and deletes unreachable objects. |
|
|
Term
| can you ask for garbage collection to run at any point in time? |
|
Definition
| you could ask garbage collector to run at a particular point in time but you cant force this to happen |
|
|
Term
| How would you set up an object for garbage collection? |
|
Definition
| by setting its reference to null.reassigning the reference, |
|
|
Term
| is there any way to garbage collect even when there is a valid reference? |
|
Definition
| yes if there is no way to get to the reference ie ther eis loop of valid references but there is no way to to get to them |
|
|
Term
| What is the Runtime class in java? |
|
Definition
| a singleton class providing a way to communicate directly with the VM |
|
|
Term
| what is the command to request for a garbage collection |
|
Definition
|
|
Term
| When is the garbage collector guaranteed to run? |
|
Definition
| right before system throws an out of memory exception |
|
|
Term
| What is the advantage of finalize() method? |
|
Definition
| it can be used to close resources an object is using before it is deleted. |
|
|
Term
| what is the disadvantage of finalize() method? |
|
Definition
| it is not guaranteed to run |
|
|