Buff up your Buffers...

1 min read

Happy 3rd National Slacker Day!

We installed a Netscreen 5XP yesterday. It's not fully configured yet. Allon spent a lot of time on the phone with them and is still expecting a callback on some unresolved issues.

I just noticed that StringBuffer implements indexOf() under JDK 1.4. Whenever we move our codebase to 1.4, I'll be able to get rid of my own implementation. Kewl!

While on the subject, remember that in order to reach optimal performance you should always try to avoid using:

buffer.append("test" + s + ".");

but instead:

buffer.append("test").append(s).append('.');

and don't forget it also applies for declarations, e.g.:

StringBuffer buffer = new StringBuffer(s).append("test");

I much prefer using StringBuffers over Strings, especially when holding temporary data. Reusing the same temporary object over and over allows me to keep the total number of objects to a bare minimum. I just need to make sure the object is properly reset when needed. For example:

StringBuffer tmp = new StringBuffer(0);
int i = 0;

for ( ; i < 10; i++)
{
    ...
    // Reset the temporary buffer
    tmp.setLength(0);
}

// Reset the loop iterator integer
i = 0;

The same principle works extremely well with tag libraries, as most JSP containers pool individual tags. What I usually do is implement a reset function which is called when all processing is done:

public int doEndTag()
{
    ...
    // Reset objects
    reset();
}
...

/**
 * Reset all reusable objects
 */
protected void reset()
{
    ...
    // Reset the temporary buffer
    tmp.setLength(0);
}

Simple, yet efficient. KISS.

Gert Van Ham's released the first beta version of his JCE taglib which can be used to bring strong encryption to JSP applications.

Ant 1.5.1b1 is now available. I will probably install it later on today.

JIRA 1.4 beta 1 was also released today.

I like the look & feel of this blog. Good article on WiFi too.

No babies were dumped while composing this article.