If you want one and only one instance of ur class to be present in the system then u can use the singleton
pattern.
e.g
package org.avi.singleton;
class factory{
private static factory instance = null;
private factory(){
// to prevent new factory() outside this class
}
//getInstance method is sychronized as thread which is executing this method will aquire lock on this object
public static synchronized factory getInstance(){
if(instance == null){
instance = new factory();
}
return instance;
}
}