Below you can find the complete Java singleton design pattern solution 
What is design pattern ? 
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
What is singleton design pattern ? 
problem: Some times in java we are getting the inconsistent results with multiple objects.
solution: To avoiding this problem we need to use singleton design pattern to create single object ,for example in case of network drivers,printers etc..
What are all the conditions we need to consider while implementing singleton class in Java/J2EE ? 
    we can clone the singleton class .
    we can serialize the singleton class .
    we can create the another object of singleton class  using reflection api in java.
    while developing multithreaded scenario in your application.
Complete Singleton Example Program 
package com.designpatterns.singleton; class SingletonDesinPattern { // private static SingletonDesinPattern instance = null; private static volatile SingletonDesinPattern instance; // volatile variable // stops the object creation from java reflection api private SingletonDesinPattern() { if (SingletonDesinPattern.instance != null) { throw new InstantiationError(" Object creation is not allowed."); } } // stops the cloning protected Object clone() throws CloneNotSupportedException { throw new CloneNotSupportedException("Clone object is not allowed"); } // returns the always single object public static SingletonDesinPattern getSingletonObject() { if (instance == null) { instance = new SingletonDesinPattern(); } return instance; } // stops from multiple threads access at a time public static SingletonDesinPattern getSingletonObjectForMutlilThread() { if (instance == null) { synchronized (SingletonDesinPattern.class) { if (instance == null) instance = new SingletonDesinPattern(); } } return instance; } // stops the serialization protected Object readResolve() { return instance; } public void sayHello() { System.out.println("Hello Boss.."); } } public class TestSingleton { public static void main(String[] args) { // SingletonDesinPattern sdp = new SingletonDesinPattern(); // sdp.sayHello(); SingletonDesinPattern spd1 = SingletonDesinPattern.getSingletonObject(); SingletonDesinPattern spd2 = SingletonDesinPattern.getSingletonObject(); System.out.println("spd1..." + spd1.hashCode()); System.out.println("spd2..." + spd2.hashCode()); // spd1.clone(); } }output spd1...751614647 spd2...751614647 if we try to create multiple references by using above program all the reference variables point to the single object as shown in the below diagram
