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 are the different types of classes implemented in the set interfaces? : java collections

1050


What is deque in the java collections framework? : java collections

1059


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

2375


What are the types of java collections? : java collections

1038


What are the interfaces in java collections? : java collections

1140


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

1028


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

1113


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

1015


What are the types of interface used in the java collections? : java collections

1030


HOW MUCH PERCENTAGE WE DEDUCT FOR OUR SUPPLIERS OR OTHER PROFESSIONALS

2040


can u draw class/object diagram for ATM

6090


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

1036


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

2337


who will give req's to u?. how they send req's to u? . what design documents contains?. when bugs raised on other developer code how to report to them?.(throgh mail or ........). how to retrive 100 recods from dao layer to presentation layer.using which collection?. what is sequence diagram.?.

2320


what is mean by hasing and maping in java platform and advantage?

2364