Collections and Maps

I have been studying up on the Java Collections Framework for the past week. It was hard to get a grasp on such a huge subject. Initially I had trouble figuring out what were the interfaces and what were the classes. With the help of Wikipedia and the Java API documentation, I think I am starting to understand it a little better.

There are really two main things to get here - collections and maps. Collections is the bigger piece. The grandfather interface is Collection (from java.util.Collection). A couple important interfaces extend Collection. They are List, Queue, and Set. You then get a bunch of classes that implement these interfaces. Do not get confused by some base classes which are then extended to the classes you use on a daily bases.

Maps are their own thing in that they store pairs of keys and values. Like the Collection interface, maps start with the Map interface. Then you have some classes that implement Map. Those classes are often extended to give you convenient classes to do your work.

One thing that is common to all this is that you need to write some code to get a feel for using the collections and maps. When in doubt of the hierarchy, take a look at the UML diagrams from Wikipedia on Collection and Map.

Collections Framework

This week my college class is doing the chapter on the Java Collections Framework. The textbook was very confusing. It looks like there are some interfaces to get familiar with. Then there are multiple classes that implement the interfaces. Other interfaces are involved as well. Initially I was overwhelmed. Now I am trying to focus on a few classes at a time.

I found that Wikipedia has a good overview on the collections. The first class I got familiar with was the HashSet. This thing is a generic class. You need to pass in the type of the items that are stored in the collection. HasSet implements the Set interface. As such, it can only hold unique items in the collection. You add() items to the set. You can also check whether they are already ikn the set with a call to contains().

The second class I played with is HashMap. Do you see a pattern forming here? This class implements the Map interface. You store key/value pairs with this thing. You need to specify the types of the key and value when you create the generic class. Then you put or get key/value pairs.

Most of these collection-related items seems to be in java.util. Let's see if I can figure out all the other classes and interfaces. I am studying it hard.

James Gosling Makes a Move

I just read a post about James Gosling quitting Google corporation. He has moved on to work at Liquid Robotics. What a name for a company. The guys is going to be chief architect there. This is surprising. I thought Google would have been keeping him happy and well paid. Perhaps sometimes you need to make a change, or work for the little guy.

In the rare instance that you do not know, James Gosling is the inventor of the Java programming language. He did that back when he worked for Sun Microsystems (which has since been acquired by Oracle). Poor Google. Gosling only lasted 6 months there. Is there more to this story?