samar
singleton class
1 Answer(s)      2 years and 7 months ago
Posted in : Java Interview Questions

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-

samar.Single@3e25a5
samar.Single@3e25a5

Thanks.









Related Pages:
singleton class
singleton class  What is singleton class
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
singleton class in struts - Java Beginners
singleton class in struts  hi, This balakrishna, I want to retrive data from database on first hit to home page in struts frame work
singleton class in struts - Java Beginners
singleton class in struts  hi, This balakrishna, I want to retrive data from database on first hit to home page in struts frame work
singleton class in struts - Java Beginners
singleton class in struts  hi, This balakrishna, I want to retrive data from database on first hit to home page in struts frame work
singleton class in struts - Java Beginners
singleton class in struts  hi, This balakrishna, I want to retrive data from database on first hit to home page in struts frame work
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
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
What is singleton? - Java Beginners
What is singleton?   Hi, I want to know more about the singleton in Java. Please explain me what is singleton in Java? Give me example of Singleton class. Thanks   hello, Singleton is a concept in which you
singleton - Java Interview Questions
singleton  what is singleton class.give one example of implementation of singleton class?  hi friend, import java.io.*; public class SingletonExam implements Serializable { public static SingletonExam single
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
where singleton class used in java - Java Interview Questions
where singleton class used in java  where singleton classes are used in j2ee web application.can we use it for connection pooling. Thanks Prakash
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
PHP Singleton Method
PHP Singleton Method: Many application resources are exclusive like database, in that case the class should have a single object. The connection to a database is exclusive. The singleton pattern is exactly the same, it uses
Java singleton
Java singleton  What is singleton
Singleton in Flex
Singleton in Flex  hi..... please tell me about How can you implement Singleton in Flex Application? please give me the procedure so i can implement....... Thanks
Singleton Design Pattern
on a class in java. The Singleton design pattern ensures that only one instance of a class is created, it provides a global point of access... Singleton Design Pattern      
singleton pattern - Java Beginners
singleton pattern  how i use singleton pattern in my web aplication project.plz give an example.its urgent
Singleton & Threadsafe in struts - Struts
Singleton & Threadsafe in struts  Hi, How to implement singleton and threadsafe in struts . same in jsp and servlet. Thanks in advance
Implementing a Serializable Singleton
Implementing a Serializable Singleton   ... are going to serialize the class. This can be done very easily. What we need...;   static SerializableSingleton singleton;  
Java Singleton Pattern
In this section, you will learn about singleton pattern in Java
Is Singleton Default in Struts - Struts
Is Singleton Default in Struts   Hi Friend, Is Singleton default in Struts ,or should we force any technique Thanks Prakash  Hi friend, Use of singletons is normally
How singleton in struts - Java Interview Questions
How singleton in struts  Hi, How to implement singleton and threadsafe in struts . same in jsp and servlet. Thanks Prakash
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
Java singleton program - Java Interview Questions
Java singleton program  Hi All, Can you please explain me in brife with an example how the singleton program works, i did see some documents but was not able to unerstand except one object can be used. this was a java
Creational Design Patterns
;     Singleton Pattern The singleton design... of achieving this pattern. Benefits: Singleton pattern controls access... flexibility than class operations. Read more at: http://www.javajazzup.com
class
class  Is a class a subclass of itself
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
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
corejava - Java Interview Questions
in the whole application.Example of Singleton Class in JAVASingleton.java- - - - - - - -public class Singleton{ private static volatile Singleton instance; private... singleton"); }} - - - - - - - - - - -Resource of singleton class in Javahttp
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,, the super class of an exception is throwable class. and the super class of an throwable class is the object class
core java - Java Interview Questions
core java   how can make a normal class as singleton
Class
Class       This section explores the concept of a class in reference to object oriented programming techniques. A class defines the properties of  objects and methods used
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
class loaders
class loaders   Explain static and dynamic class loaders
class file
class file  How to create class file in jsf easily
inner class
inner class  what is mean by inner class   Inner class is a non-static class which is defined inside another class
Node class
Node class   hii, What is a node class?   hello, A node class is a class that has added new services or functionality beyond the services inherited from its base class
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Java class
Java class  What is the purpose of the Runtime class
immutable class
immutable class  How to make a class immutable
Abstract class
Abstract class  Can an abstract class be final
printstrim class
printstrim class  discribe PrintStream class
wrapper class
wrapper class  wrapper class methods
lock on a class
lock on a class  hello, Can a lock be acquired on a class?   hiii,, Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object
Locale class
Locale class  What is the Locale class
Abstract class
Abstract class  what is an Abstract class
printstrim class
printstrim class  discribe PrintStream class

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.