Archive for December, 2010

Apache Commons EqualsBuilder and HashCodeBuilder

December 30, 2010 2 comments

Before we go ahead and explore Apache Commons EqualsBuilder and HashCodeBuilder we must know the relationship between equals and hashCode.
java.lang.Object which is the super class of all Java classes has two very important methods defined in it. They are –

  • public boolean equals(Object obj)
  • public int hashCode()

These two methods are very important when our classes deal with other Java classes such as Collection API used for searching, sorting, comparison and eliminate duplicate objects from a set.
Read more…

Categories: Java APIs, Java Know Hows

An Introduction to Bitronix JTA Transaction Manager with MySQL

December 28, 2010 1 comment

The Java Transaction API (JTA) allows applications to perform distributed transactions —to access and update systems having multiple transactional resources: databases, message queues, custom resource, or resources accessed from multiple processes, perhaps on multiple hosts, as participants in a single transaction.

The purpose of this article is to provide a high-level overview of Bitronix JTA Transaction Manager with mySQL XA datasource.
Read more…

Categories: Database Programming

Retrieve Exchangeable Image File Format data using Apache Sanselan

December 28, 2010 1 comment

Exchangeable image file format (Exif) is a specification for the image file format used by digital cameras. The specification uses the existing JPEG, TIFF Rev. 6.0, and RIFF WAV file formats, with the addition of specific metadata tags. As we are now aware of what these things are, why not write a Small Java application to extract these data. But developing a full-fledged API is beyond the scope of this blog. So, I chose to use Sanselan from Apache Foundation. This Pure-Java library reads and writes a variety of image formats, including fast parsing of image info (size, color space, icc profile, etc.) and metadata. You can download it from Apache website at Using Sanselan, it is very easy to read Exif tags. I have written a small piece of code to get the basic information of an image. The steps required to perform are as follows:

Read more…

Categories: Java APIs

Monitor your application’s memory usage

December 28, 2010 2 comments

Utilization of memory efficiently is vital for any application’s performance. Even all modern development environments provide automatic memory management capability though Garbage Collection (GC) mechanism, we cannot completely rely on GC.
In several situations we create multiple objects and most the objects within the scope of the application, but we seldom use those objects. Even worse sometime we open database, network connections or file stream but do not close them. These mistakes eat up valuable system memory resulting degradation of application performance.

Even those there are multiple memory profiling tools available in the market we can still check how our application is performing in context of memory utilization by creating our own small utility class.
Let’s try to develop a class that can be hooked to any of the application which keeps on checking our applications heap memory utilization in every 30 second interval.
To develop this utility we need to take care three important Java classes:

  1. java.lang.Runtime – Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.
  2. java.util.TimerTask – A task that can be scheduled for one-time or repeated execution by a Timer.
  3. java.util.Timer – A facility for threads to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals.

Read more…

Categories: Java Know Hows