Singleton pattern restricts the instantiation of a class and ensures that only one instance of the class exists in the java virtual machine
To implement a Singleton pattern, we have different approaches but all of them have the following common concepts.
Private constructor to restrict instantiation of the class from other classes.
Private static variable of the same class that is the only instance of the class.
Public static method that returns the instance of the class, this is the global access point for outer world to get the instance of the singleton class.
Eager initialization
In eager initialization, the instance of Singleton Class is created at the time of class loading, this is the easiest method to create a singleton class but it has a drawback that instance is created even though client application might not be using it.
On this page of the site you can watch the video online Singleton Class | Eager Initialization Approach and its drawbacks with a duration of hours minute second in good quality, which was uploaded by the user Java Solutions 07 June 2020, share the link with friends and acquaintances, this video has already been watched 61 times on youtube and it was liked by 1 viewers. Enjoy your viewing!