What are the Main Uses of Singleton Design Pattern in Java ?

Some of the main uses of Singleton design pattern in Java are as follows...

Runtime : In JDK, java.lang.Runtime is a singleton-based class. There is only one instance of Runtime in an application. This is the only class that interfaces with the environment/machine in which Java process is running.

Enum : In Java, enum construct is also based on Singleton pattern. Enum values can be accessed globally in same way by all classes.

Properties : In an application it makes sense to keep only one copy of the properties that all classes can access. This can be achieved by making properties class Singleton so that every class gets same copy of properties.

Spring : In Spring framework, all the beans are by default Singleton per container. So there is only one instance of bean in a Spring IoC container. But Spring also provides options to make the scope of a bean prototype in a container.



You May Interest

How Will You Pass Information From One JSP to Another JSP ?

What is the Use of Interceptor Design Pattern in Java ?

Why Do We Use Static Initializers in Java ?

What is the Use of Jsp:useBean in JSP ?

What is a WeakHashMap in Java ?