A Singletone class;
Only one time in JVM per class loader would be instantiated. Same instance would be use for repeated calls.
public class OnlyOne {
private static OnlyOne one = new OnlyOne();
// private constructor, so this class cannot be instantiated from outside and prevents
//subclassing.
private OnlyOne();
//a global point of access
public static OnlyOne getInstance() {
return one;
}
}
To use it:
OnlyOne myOne = OnlyOne.getInstance();