Singleton is a design pattern used to limit the number of a class instances to one (or may be more)
and restricting any user wants a new object to use the already constructed object eliminating multiple copies of the same object

if we made a class like this

public class Resource
{
	private int value;

	public Resource()
	{
		this.value = 0;
	}
	
	public void setValue(int value)
	{
		this.value = value;
	}
	
	public void getValue()
	{
		return this.value;
	}
}

we can use it by making instance of it

Resource r1 = new Resource();
Resource r2 = new Resource();

r1.setValue(5);
int value = r2.getValue();

we make two instances of the class with different data values

what we need:
we want to create only one object of that class and give it to any one wants an instance of that class
so we ‘d have only one object and many references to it

Disallow making instances
we can make so by defining the constructor as private, thus allowing only making new instances within the same class (not outside it)

Solution 1
we can fix this problem by providing a static member of the same type of our class inside the class itself
we will make a static method to return the static member.
the static method ‘d be responsible also for creating only one instance of our object

public class Resource
{
	private static Resource instance;
	private static Resource getInstance()
	{
		if(instance == null)
			instance = new Reource();
		return instance;
	}
	
	private int value;
	
	private Resource()
	{
		value = 0;
	}
	
	public void setValue(int value)
	{
		this.value = value;
	}
	
	public void getValue()
	{
		return this.value;
	}

}

suppose we have a small scenario of two objects trying to make a new copies of our class

Resource r1 = Resource.getInstance();
Resource r2 = Resource.getInstance();

r1.setValue(5);
int value = r2.getValue();

the constructor of Resource is private so we can’t use the new keyword
we have only a static method called getInstance that returns an object of type resource

initially the instance static variable is null

in the first line we call the getInstance method
it checks for the instance if it’s null, and it finds it null
so it execute the line after if, it creates new object of the Resource class ( here we can make so because we are in the same class so we can access private members including our private constructor )
after creating the object it assigns it to the static instance variable
then the getInstnce method return a new a reference to the static instance variable

in the second step

** INCOMPLETE