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 methods in java?

956


Is integer a class?

1030


What is entry in java?

987


Distinguish between a predicate and a function?

955


What does localhost mean?

901


What is constructor in java ?

1142


Can you declare a private method as static?

1116


Explain about varargs in java?

1079


What is Mutex (Mutual Exclusion Object) ?

1100


Is 64bit faster than 32 bit?

1026


Which of the following classes will have more memory allocated?

985


Why object class is super class for every class in java?

987


Differentiate between a class and an object.

1001


How is it possible in java programming for two string objects with identical values not to be equal under the == operator?

989


How to split a string in java?

1086