Lubos Programming Blog

Lubos Blog about Programming (mainly Java) and Computers

Nice tools for Java developers

Posted by lubosp on December 31, 2004

Nice tools for Java developers [Java Java Proxy]
This time a collection of links to various tools that can easen our burden a little bit.

First, PDF and Excel creation using pure Java. This may seem unnecessary to small projects, but turns out to be quite handy, especially as more and more technical literature and external communications are written in PDF. We shouldn’t forget about Excel also: altough this is “we love to hate” Microsoft product, but one must agree that it gives the end user the time of his life creating the slice charts.

The following two packages allow reading and writing PDF and Excel files from Java:

  • PDF – IText from here
  • Excel – JExcelAPI from here

Pay particular attentions to the example that explains how to create a dynamic PDF which is sent to the web-based client from the servlet. This doesn’t involve creating the PDF on the web-server file system. The resulting stream is treated by the client automatically based on the content header and then associated with the corresponding plugin.

In addition, Jakarta POI project allows manipulating OLE2 Microsoft format used for all Office formats. Currently supported is – full support for Excel, simple capabilities for Word. More open-source for PDF can be found here

And now to the more prosaic world of memory profiling. This beast starts to raise its ungodly head when you suddenly find out that the garbage collection can get you so far. This much appraised mechanism makes our lives much easier, freeing us from both dreaded UNIX segmentation faults and elaborate C++ mechanism of virtual destructors; on the other hand we grow sloppier every day in forgetting to “free” objects that are no longer needed. This is referred to as unintentional retention.

I’ve experienced this one lately: there’s a massive computation performed by some object. This object creates a series of graphs, each having hundreds of thousands of nodes, and eventually splits these graphs. The result is a very compact segmentation of some input space which later is reused. As this computation is spread through several functions, i’ve decided to store these graphs in a member list variable. In the outer classes i store a reference to this object for reuse of the result. Guess what? The intermediate results are stored as long as this object lives, because I didn’t nullify them

So here a few tools (only one of them was actually run by me) that are collectively known as heap profilers:

  • hprof, not a tool on itself, more of a utility supplied with JDK. Detailed explanation is provided in this article from Sun
  • HAT, Heap Analysis Tool that works with Java 5.0 and provides a web-based GUI (in your browser of choice). Make sure though that you update the hat.bat to use -Xmx512M: for an hprof file of 46Mb, the JVM running Hat takes over 303Mb.
  • HUP, Heap Usage Profiling available here
  • HeapAnalyzer available from IBM (after they force you to tell them everything about yourself in a 10-page web form)

So, the next time you complain to your boss about that 1GB RAM that doesn’t meet your needs anymore, use these. The GC itself will thank you.


[via java.blogs Day’s Entries]


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: