How to easily reconfigure your applications — while they’re running

Welcome to the first installment of the Cool Tools column. Encouraged by the tremendous amount of positive feedback I received from my debut article on object pooling, I’ve decided to take a stab at this writing gig. Each month, I’ll introduce a new useful Java utility. These utilities are basically “tools” I’ve devised and evolved over the past couple years of my Java programming career. These tools simplify the job of the coder while enhancing the performance and robustness of the application. I hope you’ll find them as useful as I have.

This month’s topic is global values. These are the values that allow us to change the look or behavior of our applications without changing any code. Global values must be accessible from anywhere, anytime.

To read this article in full, please click here

JavaWorld Cool Tools

Clever Facade makes JDBC look easy

Before I dive into this second installment of my new Cool Tools column, allow me to offer up some corrections and clarifications to last month’s column, “How to easily reconfigure your applications — while they’re running.” I received lots of feedback on that article, most of it constructive, some of it abusive, but if it makes me a better writer and/or programmer, it’s all welcome. (Although, I do prefer the polite messages over the vulgar ones.)

Static finals and compilers

Last month I discussed the scenario wherein the values of static final variables are being compiled into the classes that reference them, thus requiring a recompile of the entire project for any changes to propagate. I stated that this behavior is (or was two years ago) different from one compiler to the next. JavaWorld reader Ethan Nicholas was kind enough to correct me on the matter:

To read this article in full, please click here

JavaWorld Cool Tools

Build your own caching mechanisms with volatile collections

The literal definition of the word volatile is “readily vaporizable,” with a secondary connotation of “changeable.” This month’s tool matches this description nicely, as its implementation will cause the objects contained in a hashtable to vaporize, and the rate of that vaporization is indeed changeable.

But more on that in a moment. First, I’ll address reader feedback from last month’s column.

Reflections

Half a dozen readers wrote in to inform me that the following block of code (which relates to the GlobalValues tool we discussed two columns back) is a performance bottleneck for multithreaded access.

To read this article in full, please click here

JavaWorld Cool Tools

Use JNDI to share objects between different virtual machines

Before I turn to this month’s tool, I would like to address feedback from my previous article. I’ll respond to reader comments on better design, performance problems, and bugs.

Better design

One reader commented that the Cachetable I presented in last month’s column violates the Liskov Substitution Principle (see Resources). This principle basically states that if B is a subclass of A, and C is a subclass of A, then B should be able to subclass C without any problems, and vice versa. In other words, any class that currently extends Hashtable should be able to also extend Cachetable without any side-effects. It wasn’t my original intention to support this notion, but the reader is correct in asserting that it is good object-oriented design.

To read this article in full, please click here

JavaWorld Cool Tools

Easier ways to handle arrays — plus a little string manipulation

Primitive arrays in Java are not very object-oriented. You can get around this shortcoming by using a Vector, but, as I’ll explain in more detail below, this is often overkill. The first tool I will introduce is a simple object-oriented wrapper for a primitive array. After discussing arrays, I will move on to the second tool, a pair of little string manipulation routines that I use for splitting and joining, and that have come in handy for me many times.

Dealing with arrays can be a hairy business. You want to use primitive arrays for fast access and low memory overhead, but you don’t always know how big an array has to be until it’s already populated. You can use a Vector, but doing so means that each primitive value must be wrapped in an object. For example, any int has to be wrapped in an Integer object. But don’t lose heart — there is a happy medium, and that is this month’s first tool.

To read this article in full, please click here

JavaWorld Cool Tools