I'm a newbie in JAVA.
When I read about singleton pattern, It need an instance first run.
Something like that:
public class Singleton {
private static final Singleton instance = new Singleton();
private Singleton(){}
public static Singleton getInstance(){
return instance;
}
}
But I also write something like that:
public class Singleton {
public Singleton(){}
//methods,....
}
So I have some question:
1) Why we need an instance in singleton? what's the purpose? 2) Why the constructor in singleton is private? How we can intialize input for this class?
I know my question is very basic, and hear so noop.
But please help me to explain them.
Thanks & Best Regards