August 7, 2001

Use StringBuffer for Speedy Servlet Output

Servlets often need to display a lot of HTML. One way to do this is with println() commands and String concatenation. However, String concatenation is an expensive process. It is much faster to use a StringBuffer.The original code might look like this: for (int i=0; i

Avoid Instantiability of Utility Classes

There are times when almost every programmer comes up with a class that consists only of public static methods. Usually these are some kind of utility classes, which do not maintain any state and thus it doesn

Appending Data to an Existing File

There is a constructor in the java.io.FileOutputStream class which can be used to append data to an existing file. Usage:public FileOutputStream(String name, boolean append) throwsFileNotFoundExceptionwhere:name – the file nameappend – if true, data will be written to the end of the file So, if you wish to append to a

How to Make a Swing Component Appear and Disappear

Here’s a very short bit of code that will make a StatusBar hide or show, accordingly: public void viewStatusBar() { /* Hide or show the statusbar */ StatusBarPane().setVisible(!(StatusBarPane().isVisible()));} Just have a button actionlistener call this function.

Encapsulate Member Objects

Objects frequently contain member objects that need to be exposed.Often, these are not correctly encapsulated, which could lead to problems that are difficult to track down.Consider a Circus object, which has a private collection of the names of its clowns. We could expose this Collection with a public property: Public

No more posts to show