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

When arithmeticexception is thrown?

1069


Why array is used in java?

1015


Can a serialized object be transferred via network?

1020


When is the finalize() called?

1227


What is fail first in java?

1286


What is super constructor?

1051


Why charat is used in java?

1102


Is java owned by oracle?

1070


Explain the difference between an Interface and an Abstract class?

1222


What is the use of default method in interface in java?

1046


How to read and write image from a file ?

1098


What is meant by class loader? How many types are there? When will we use them?

1008


What is the difference between == and === javascript?

1245


Is this valid in java ? Can we instantiate interface in java?

1021


How to create a base64 decoder in java8?

1104