What is singleton class? Where is it used?

What is singleton class? Where is it used?

- The purpose of singleton is to control the object creation, limiting the number of the objects to one only.

- Since it has only one instance any instance fields of a singleton will occur only once per class like the static fields.

- They have access control to resources as the database connections or the sockets.

- A class is defined as singleton class, if and only if it can create only one object.

- This class is useful when only one object is to be used in the application.

The following are some of the uses of singleton class.

1. The access of the object is controlled.
2. When "just-in-time" instantiation is needed and needed globally.
Difference between a public and a non-public class
Difference between a public and a non-public class - A class with access specifier ‘public’ can be accessed across the packages. A package is like a folder in GUI....
What is Bootstrap, Extension and System Class loader in Java?
What is Bootstrap, Extension and System Class loader? - The Bootstrap class loader loads key Java classes. Bootstrap class loader loads the basic classes from......
Define JDBC
Define JDBC - The JDBC API defines interfaces and classes for making database connections. Using JDBC, you can send SQL....
Post your comment