October 14, 2004

Use Local Classes for Proper Cleanup in Exception-enabled Apps

Exceptions enable you to detect and handle anomalous runtime conditions promptly. However, they also complicate the design of your program as they increase the number of possible execution paths. In most cases, implementing the “resource acquisition is initialization” idiom guarantees that data isn’t destroyed and that resources are always released.

Find Programs or Libraries Related to a Particular Keyword on a UNIX Platform

Note: This tip applies primarily to UNIX platforms (fortunately or unfortunately). The code was run on a Sun Solaris server (SunOS 5.8). How many times have you wondered what programs installed on your machine will handle content of a given type? There’s an easy utility that does this called apropos.

Hide .jsp Names from the URL

There are instances when .jsp names need to be hidden from the URL. This can be done using various design techniques. But if your application is small and simle enough that it doesn’t even require a servlet, you can hide a real URL by defining a mapping in the web.xml

A Better Way to Force a C++ Class to Be a Singleton

The tip “How to Force a C++ Class to Be a Singleton” does not provide enough flexibility for the programmer to control the creation/deletion of the singleton instance. The following code provides better control over memory and class instance. class MySignleton{public: static MySingleton* GetInstance() { if(!m_pThis) m_pThis = new MySingleton();

Monitoring Garbage Collection in the JVM

Big applications create huge numbers of objects. Though Java manages the memory allocation and de-allocation for these objects, sometimes this huge number can result in memory leak problem. To monitor when and how much garbage collection is happening, use the following example method: Suppose you start your application as: java