Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to implement Singleton

Answer Posted / manoj kumar

public class DateUtil implements Serializable,Cloneable {

   private static volatile Dateutil instance;

   private DateUtil() {
     //no-op
   }

   public static DateUtil getInstance() {

      if(instance==null) {
        synchronized(DateUtil.this) {
           if(instance==null) {
              instance = new DateUtil();
           }
        }
        return instance;
      }
   
   protected Object readResolve() {
     return instance;
   }

   public Object clone() throws CloneNotSupportedException {

     super.clone();

     throw new CloneNotSupportedException;
  }

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are structs in java?

1001


What is a numeric literal?

995


What is function declaration?

914


How to implement a multithreaded applet?

2608


Is java an open source?

927


What is assembly condition codes?

935


Explain about static nested classes in java?

1025


What is the difference between jfc & wfc?

1012


What is JVM and is it platform independent?

988


does java support pointers?

933


Why charat is used in java?

983


What is the advantage of preparedstatement over statement?

1046


What is re-factoring in software?

977


what is the use of bean managed and container managed with example?

1925


Is string a class?

969