It’s just common(s) sense
Monday 3 April 2006 @ 9:59 am
Filed under:

Most java projects use a bunch of common classes for various things.
Because this functionality is so common, we tend to copy these common classes from one of our earlier projects.
Instead of just copying some ‘legacy’ snippets from previous projects, it might be a more sensibly thing to use the (Apache) Jakarta Commons libraries instead.
One of the jakarta commons should be mandatory for each Java project: Commons Lang

The commons lang contains all kind of utility classes that will make you think why it is not part of the standard Java lang(uage).

One of the most handy features of the Commons Lang are the Builder classes to easily create toString, equals and hashCode implementations for a class. All these builder classes are smart enough to detail with null and array arguments, so you don’t have to.

Another handy class is the StringUtils class that contains a whole bunch of string functionality like isEmpy / isBlank, trimming, replacing, chomp / chop etc.

When coding I like to aggressively enforce my constructor / method pre-conditions by throwing and IllegalArgumentException when any argument value is not according to a pre-condition. The Validation class will help you with that. It contains utility methods to easily check if the supplied argument isTrue, notEmpty and notNull. Furthermore for a collection / array you can easily validate if there are no null element and that all elements are of a certain type.

There last class I would like to mention is the Enum / ValuedEnum base class.
By extending from this class you can easily create a enum class in Java 1.4 (in Java 5 you should use the new enum language functionality).

I would advise any Java programmer to have a (short) look at the Javadocs of Commons Lang, because besides the features I described above there are a lot more gems to be discovered.

— By Emil van Galen   Comments (0)   PermaLink


Sha256 mining

Blog Categories

Browse by Date
April 2006

Upcoming Events

Monthly Archives

Recent Comments


XML Feeds Option

Get Firefox  Powered by WordPress

code validations
Valid RSS 2.0  Valid Atom 0.3
Valid W3C XHTML 1.0  Valid W3C CSS