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

What is the Difference Between a Class and an Object in Java ?

How Can We Prevent Busy Waiting in Java ?

Why Java Provides Garbage Collector ?

How Can You Determine If Your Program Has a Deadlock in Java ?

What is the Difference Between sendRedirect and forward in a JSP ...