• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/20

Click to flip

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;

20 Cards in this Set

  • Front
  • Back
What is the difference between an ArrayList and a Vector?
Both implement the List interface, but ArrayList is not thread safe whereas Vector is.
Whats the difference between a HashTable and a HashMap?
Both implement the Map interface but HashTable is thread safe whereas HashMap is not.
Describe a Collection that sorts the elements for you.
TreeSet or TreeMap. A TreeSet's Iterator is guaranteed to traverse the set in ascending element order while a TreeMap has the keys stored in natural ascending order.
What is an iterator?
Iterator is an interface, implementations of which allow the user to enumerate all of the elements in a collection. Each collection implements its own variety of Iterator depending on the type of collection, order of its elements, etc.
What are some top level interfaces in Java's Collection classes?
List, Set, Queue, Map and BeanContext.
What is the difference between a List and a Set?
Set does not allow duplicate elements while a List does.
If you override the hashCode() method of a class, what other things should you consider doing to it?
Override the equals() method so that it is consistent with hashCode so that it may be looked up properly in a collection.
How would you implement your own ArrayList?
Have an array of a given type and make sure you have enough room when adding an element. Otherwise, create a bigger array, and copy existing element references to the new array and manipulate.
Suppose you are given a sorted list. How do you perform a binary search of the list?
The class java.util.Collections has methods to perform a binary search.
What is the Collections class in Java?
java.util.Collections is a utility class that defines a number of static methods that operate on Collections.
What are some examples of useful methods in the Collections class?
binarySearch, sort, shuffle, min, max are all examples.
How do you enumerate all the elements in a HashMap?
You can get the entry set and enumerate each element and key in the set or you can get the key set and use that to retrieve the values.
What will happen if I get the KeySet from a HashMap and delete an element from the KeySet?
The corresponding element will be deleted from the HashMap.
What will happen if I try to add an element to the KeySet I obtain from a HashMap?
UnsupportedOperationException. You can not add an element to a HashMap's KeySet although you can remove elements from it.
What are generics in Java?
Generics create a mechanism by which a class or an interface can take one or more types as parameters and make that class or interface tied to that type or types. For example ArrayList <Integer> aList; // Creates a list that will accept only Integers.
Explain the for-each feature of Java.
It is a special for loop that allows one to iterate over a Collection without using indexes. It's less error prone and cleaner code.
Give the syntax of a for-each loop.
List<Integer> myList = new ArrayList<Ineger>();

for ( Integer I : myList) {
//do something to or with the current element which is I.
}
What are synchronized wrappers?
These are wrappers that add thread safety to an arbitrary Collection. Each of the 6 core Collection sub-interfaces has a static factory method that returns such a wrapper backed up by the specified Collection.
What is type erasure in Java?
The Java compiler actually erases types parameters from a generic after enforcement to ensure backward compatibility. This means the type is not available at run time.
What are wild cards in generics? How are they useful?
So Class A extends B and B implements interface C:
List<?> Any individual type.
List <? extends B> could be A OR it could be B.
List <? super C > could only be A or Object since it must be a super class of A.

As they pertain to Collections, it means that Collections can now be made type safe so that if you put something into a collection you will guaranteed to get the same type back out.