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 or use the singleton class in java?

Answer Posted / aashish r. wadhokar

Singleton is a design pattern as well as class.
when we define singleton class it means we can have only one
object of that class.
We cant create multiple objects of that class.
In singleton class, constructor is always private.

eg:
public class Singleton
{
private static Singleton singletonObject = null;
private Singleton()
{
System.out.println("Singleton object created!!!");
}
public static Singleton CreateInstance()
{
if(singletonObject == null)
{
singletonObject = new Singleton();
}
return singletonObject;
}

Now we can get object as:
Singleton ref = null;

ref = Singleton.CreateInstance();

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you understand by synchronization? Why is it important?

996


What are the different types of collections views being provided by the map interface? : java collections

977


What is an algorithm in java collection framework? : java collections

1006


How is hashset maintained in memory by java ?

1092


What is the use of the list interface in the java collection? : java collections

977


What are the uses of the set interfaces in the java collections? : java collections

926


please mail me the interview question based on java/j2ee

1899


What are the queues in the java collection framework? : java collections

969


Which java collection class can be used to maintain the entries in the order in which they were last accessed?

995


What are the differences between the java collection and the java list? : java collections

1049


Hi frnds how to lock an user when he enter wrong credentials more than 3 time using java or j2ee tech take username and password in a bean no need to connect DB and validate give me some sample application code or links its urgent for me thanks in advance

2291


HOW MUCH PERCENTAGE WE DEDUCT FOR OUR SUPPLIERS OR OTHER PROFESSIONALS

1999


my interviewer asked me what technical specification you used how to answer that question

2322


How do I find jre path in windows?

963


What is the difference between comparable and comparator in java.util pkg?

1063