View Tanya  Sharma 's Profile
What is singleton?
It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … }
Asked by Tanya Sharma | Feb 12 2019 | Report this Report abuse
Replies (6)
View Roshan  shah 's Profile
In object-oriented programming, a singleton class is a class that can have only one object (an instance of the class) at a time.
After first time, if we try to instantiate the Singleton class, the new variable also points to the first instance created. So whatever modifications we do to any variable inside the class through any instance, it affects the variable of the single instance created and is visible if we access that variable through any variable of that class type defined.
To design a singleton class:

Make constructor as private.
Write a static method that has return type object of this singleton class. Here, the concept of Lazy initialization in used to write this static method.
Feb 18 2019 | Report this Report abuse
View Shatish  Rao 's Profile
In object-oriented programming, a singleton class is a class that can have only one object (an instance of the class) at a time.
After first time, if we try to instantiate the Singleton class, the new variable also points to the first instance created. So whatever modifications we do to any variable inside the class through any instance, it affects the variable of the single instance created and is visible if we access that variable through any variable of that class type defined.
To design a singleton class:

Make constructor as private.
Write a static method that has return type object of this singleton class. Here, the concept of Lazy initialization in used to write this static method.
Feb 18 2019 | Report this Report abuse
View Shatish  Rao 's Profile
What is Class.forName() does and how it is useful?
Feb 17 2019 | Report this Report abuse
View Nirupama  Pathak 's Profile
A singleton is a class that allows only a single instance of itself to be created and gives access to that created instance. It contains static variables that can accommodate unique and private instances of itself. It is used in scenarios when a user wants to restrict instantiation of a class to only one object. This is helpful usually when a single object is required to coordinate actions across a system.

The singleton pattern is used in programming languages such as Java and .NET to define a global variable. A single object used across systems remains constant and needs to be defined only once rather than many times.
Feb 16 2019 | Report this Report abuse
View Khushi   Kumari 's Profile
A singleton is a class that allows only a single instance of itself to be created and gives access to that created instance. It contains static variables that can accommodate unique and private instances of itself. It is used in scenarios when a user wants to restrict instantiation of a class to only one object. This is helpful usually when a single object is required to coordinate actions across a system.

The singleton pattern is used in programming languages such as Java and .NET to define a global variable. A single object used across systems remains constant and needs to be defined only once rather than many times.
Feb 16 2019 | Report this Report abuse
View Shuchita   Shukla 's Profile
Thanks Shuchita Shukla for mentioning our article reference for Singleton concept.

Actually, one must understand what are the various ways to create Objects in Java and then move over to Singleton design pattern.

http://www.benchresources.net/various-ways-to-create-object-in-java-4-ways/
Feb 16 2019 | Report this Report abuse