Difference why Singelton Class and Static Class

Can anyone tell me the difference between a singleton class and a Static class, as with both mechanism we can create only single instance per of a class.
I would appreciate if someone can explain me the difference with example.

Who is Participating?
objectsConnect With a Mentor Commented:
theres really no such thing as a singleton class. A psuedo singleton is mostly implemented using static.

There is nothing as a Static class in Java. You should make your a class singleton when you only want a single instance of the class in your application.
Also , you should make a class singleton when you do not want to maintain the state of its instances. For example, every object of the following class will have a different state.

class Point {
int x,
int y

However, if you have a class whose state is not be maintained, then you should make it singleton. For example

class PointUtil {
public Point isAbove(Point a, Point b) (...);
public Point isOnRight(Point a, Point b) (...);

Such classes you should make singleton, as two instances of this function will be of no use.

You can also achieve the same by having all functions as static but static functions are loaded at startup , so you are better off making it a singleton.
All Courses

From novice to tech pro — start learning today.