Skip to content

I’ve recently needed to do some command line parsing. Instead of reinventing the wheel, I looked at the Apache Commons CLI library. This library seemed to do exactly what I wanted and was fairly easy to use.

One question though? Why does the standard Java runtime not have classes to deal with CLI arguments?

J2SE 5.0 gives developers a whole load of new features – too many to list here, but a complete list is given at

Generics is one of the best new features that has been added to J2SE 5.0 and they are incredibly easy to use! So what is Generics? Well, to put it simply, Generics gives you type safety on collections, so you can create collections that will only hold a specific type. Furthermore, when you get an object out of a collection using Generics, you don’t need to cast it to the relevant type – this is done automatically for you. This is best shown with a small example.

// Declare an array list called items that can only hold strings.
Collection items = new ArrayList();

// Add a couple of strings to the collection.
items.add("String 1");
items.add("String 2");

// Declare a 'String' iterator to loop through the collection.
Iterator iter = items.iterator();
while (iter.hasNext()) {
    // Get a value from the collection - note there is no need to cast it.
    String value =;