|
Page 1 of 5 As enterprise Java developers, we are routinely required to implement functionality like parsing XML, working with HTTP, validating input, and processing dates. The Jakarta Commons project is an attempt to
create components that can take care of all such commonly used tasks, freeing up your time to
focus only on core business solutions. In this article we will provide a quick introduction to the Jakarta Commons project and then demonstrate how the Lang component within Jakarta Commons can be used to handle and simplify everyday Java tasks such as string manipulation, working with dates and calendars, comparing data objects, and sorting objects. For all examples, we will use the latest version of Lang, version 2.1.
** First Published on dev2dev
Introduction to Commons and the Lang Component
Jakarta Commons is a project meant solely for reusable Java components. The project has dozens of components for simplifying Java development and addressing one particular requirement well. The range of available components is huge, and they aren't limited for use only in Java applications of a particular type.
The projects are classified into two parts:
- Commons Proper: Projects in the
Commons Proper can be termed as ready for production use.
- Commons Sandbox: Projects in the sandbox
are still in the experimental stage.
There are currently 33 projects in the Commons Proper and 22 projects in the works in the Commons Sandbox so there is something in there for every kind of Java project.
The Lang component is one of the more popular components in Jakarta Commons. Lang is a set of classes that you wish were present in J2SE itself.
In this article we will look at some of the most useful features of Lang. Note that you can do everything that Lang does using just the basic Java classes, however it is far easier to use Lang than it is to study, understand, and write the code yourself. Even if you can write superb code, using the tried and tested capabilities of Lang will be quicker and will save considerable review and testing cycle time.
Lang comes with proper JUnit test cases and as it is used so widely, it has been well
tested by its creators as well as by the real world.
An important feature of Lang is its simplicity. New Java components generally are so complex that unless you know A, B, C, and D technologies, you will not be able to use that component. Often, it is difficult to even understand what a component is trying to achieve, let alone actually use the component. This is not the case with most of the Commons components. Components like Lang are easy to use and very useful to a Java beginner as well as an advanced Java user.
If you need star endorsements before you adopt a technology, try this: Search for commons-lang*.jar in the directory where you keep your Java software. You will be surprised. Tomcat, Struts, Hibernate, Spring, and
WebWork are just some of the popular Java projects that make use of Lang.
Let's start with string manipulation with Lang, a task that most Java developers have to do almost every day.
|