Question

I am programming in Java and was told to refactor some code to coding standards. I was told that util packages are meant for static utility classes and not application functionality. Is this correct? What exactly does this mean? Also, considering the "java.util" package contains Collection interface, how else could I accomplish tasks requiring lists?

Was it helpful?

Solution

Whoever told you that was wrong — or you misunderstood. java.util.* has a bunch of extremely useful, extremely common classes, most of which are not utility classes (in the common sense of "a class with only/mostly static methods for common tasks"). For instance, List is in java.util, along with its commonly-used implements ArrayList and LinkedList. Ditto Map/HashMap/TreeMap, Set/HashSet/TreeSet, and many others.

OTHER TIPS

There are no hard and fast rules about what would appear in a util package. To quote the javadoc java.util contains

the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).

As you rightly say this is much more that only utility classes. In this case the person seems to be taking the word utility and package util a bit too literally.

I would say that a util package is for miscellaneous useful classes that don't have enough similar classes to justify grouping them in their own package.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top