singleton class

Ads
 

singleton class

What is singleton class?
View Answers

October 29, 2010 at 4:48 PM

Hi,

A class whose number of instances that can be instantiated is limited to one is called a singleton class. Thus, at any given time only one instance can exist, no more.

public class Single {
    private static Single a;

    private Single() {

    }

    public static Single getSingle() {
        if (a == null) {
            a = new Single();
        }
        return a;
    }

    public static void main(String... s) {
        Single a1 = Single.getSingle();
        Single a2 = Single.getSingle();
        System.out.println(a1);

        System.out.println(a2);
    }

}

This program give the out put as-

[email protected]
[email protected]

Thanks.

Ads









Related Tutorials/Questions & Answers:
singleton class
singleton class  What is singleton class
Why we use singleton class in hibernate sessionfactory?
Why we use singleton class in hibernate sessionfactory?  Hello, Please tell me why we use singleton class in hibernate sessionfactory? hibernate sessionfactory singleton example would be very helpful. Thanks
Advertisements
Singleton class
Singleton class       Singleton Design Pattern: The singleton design pattern allows to have one... be achieved in java by making a Singleton  class Benefits:  Singleton
singleton
singleton  import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.*; import java.util.Scanner; public class New { private static Connection connection = null
J2EE Singleton Pattern - Design Pattern Tutorials
only one instance of object is required. The Constructor in a Singleton class... class. Consider a simple Singleton class. public class... SimpleSingletonClaz(); // private constructor of a Singleton Class private
singleton program
singleton program  import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Scanner; public class Emp{ public
ModuleNotFoundError: No module named 'singleton'
ModuleNotFoundError: No module named 'singleton'  Hi, My Python... 'singleton' How to remove the ModuleNotFoundError: No module named 'singleton' error? Thanks   Hi, In your python environment you
Singleton Pattern
in those places where there is only one instance of a class. The Singleton pattern... a static class and a singleton class?"  The answer is static class is one of the approaches that makes a class ?Singleton?. We can create
Java Singleton Pattern
In this section, you will learn about singleton pattern in Java
ModuleNotFoundError: No module named 'celery-singleton'
ModuleNotFoundError: No module named 'celery-singleton'  Hi, My... named 'celery-singleton' How to remove the ModuleNotFoundError: No module named 'celery-singleton' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-singleton'
ModuleNotFoundError: No module named 'django-singleton'  Hi, My... named 'django-singleton' How to remove the ModuleNotFoundError: No module named 'django-singleton' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'jupyter-singleton'
ModuleNotFoundError: No module named 'jupyter-singleton'  Hi, My... named 'jupyter-singleton' How to remove the ModuleNotFoundError: No module named 'jupyter-singleton' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'm-singleton'
ModuleNotFoundError: No module named 'm-singleton'  Hi, My Python... 'm-singleton' How to remove the ModuleNotFoundError: No module named 'm-singleton' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'nocycle-singleton'
ModuleNotFoundError: No module named 'nocycle-singleton'  Hi, My... named 'nocycle-singleton' How to remove the ModuleNotFoundError: No module named 'nocycle-singleton' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pmc-singleton'
ModuleNotFoundError: No module named 'pmc-singleton'  Hi, My... 'pmc-singleton' How to remove the ModuleNotFoundError: No module named 'pmc-singleton' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'python-singleton'
ModuleNotFoundError: No module named 'python-singleton'  Hi, My... named 'python-singleton' How to remove the ModuleNotFoundError: No module named 'python-singleton' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'python-singleton'
ModuleNotFoundError: No module named 'python-singleton'  Hi, My... named 'python-singleton' How to remove the ModuleNotFoundError: No module named 'python-singleton' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'rigger_singleton'
ModuleNotFoundError: No module named 'rigger_singleton'  Hi, My... named 'rigger_singleton' How to remove the ModuleNotFoundError: No module named 'rigger_singleton' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'singleton-admin'
ModuleNotFoundError: No module named 'singleton-admin'  Hi, My... named 'singleton-admin' How to remove the ModuleNotFoundError: No module named 'singleton-admin' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'singleton-decorator'
ModuleNotFoundError: No module named 'singleton-decorator'  Hi, My... named 'singleton-decorator' How to remove the ModuleNotFoundError: No module named 'singleton-decorator' error? Thanks   Hi
ModuleNotFoundError: No module named 'singleton_factory'
ModuleNotFoundError: No module named 'singleton_factory'  Hi, My... named 'singleton_factory' How to remove the ModuleNotFoundError: No module named 'singleton_factory' error? Thanks   Hi, In your
class
is a class to represent a country in medal tally. It has an attribute of country... medals. In this class, you should also define constructors, and assessor, mutator methods. Task 2 MedalTally.java is a class to model a medal tally, containing
What is difference between singleton and prototype bean?
What is difference between singleton and prototype bean?  Hi, What is difference between singleton and prototype bean? Thanks
What is an efficient way to implement a singleton pattern in Java?
What is an efficient way to implement a singleton pattern in Java?  What is an efficient way to implement a singleton pattern in Java
Class
Class, Object and Methods       Class : Whatever we can see in this world all the things... is termed as a class. All the objects are direct interacted with its class
ModuleNotFoundError: No module named 'django-singleton-admin'
ModuleNotFoundError: No module named 'django-singleton-admin'  Hi...: No module named 'django-singleton-admin' How to remove the ModuleNotFoundError: No module named 'django-singleton-admin' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-singleton-admin-2'
ModuleNotFoundError: No module named 'django-singleton-admin-2'  Hi...: No module named 'django-singleton-admin-2' How to remove the ModuleNotFoundError: No module named 'django-singleton-admin-2' error? Thanks  
ModuleNotFoundError: No module named 'django-singleton-model'
ModuleNotFoundError: No module named 'django-singleton-model'  Hi...: No module named 'django-singleton-model' How to remove the ModuleNotFoundError: No module named 'django-singleton-model' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-admin-app-names-singleton'
ModuleNotFoundError: No module named 'django-admin-app-names-singleton' ...: ModuleNotFoundError: No module named 'django-admin-app-names-singleton' How to remove the ModuleNotFoundError: No module named 'django-admin-app-names-singleton'
Explain final class, abstract class and super class.
Explain final class, abstract class and super class.  Explain final class, abstract class and super class.   Explain final class, abstract class and super class. A final class cannot be extended. A final class
.class and .tld
.class and .tld  how to create .class and .tld file

Ads