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

How do you make an arraylist empty in java?

912


What is the use of put method?

933


Define how does a try statement determine which catch clause should be used to handle an exception?

1131


What about method local inner classes or local inner classes in java?

1036


What is a instance variable in java?

1029


How to disable caching on back button of the browser?

1059


How is final different from finally and finalize?

914


What are inbuilt functions?

973


How can we create objects if we make the constructor private ?

984


What is the difference between heap memory and stack memory?

1044


How does arraylist work in java?

1096


What are the different types of multitasking?

1086


Why are data types important?

1069


What is the difference between the size and capacity of a vector?

1014


Why is string buffer better than string ?

1095