proper usage of synchronized singleton? Since there is only one Singleton instance, any instance fiel Singleton pattern in Java. Singleton is a creational design pattern, which ensures that only one object of its kind exists and provides a single point of access to it for any other code. This design pattern is commonly used in caching, Abstract Factory, logging, Prototype, etc. All these ways differs in their implementation of the pattern, but in the end, they all achieve the same end result of a single instance. Any class that needs to be serialized/deserialized must implement the serializable interface. Singleton class restricts the object creation for a class to only one in the java virtual machine. Singleton pattern is a design solution where an application wants to have one and only one instance of any class, in all possible scenarios without any exceptional condition. Java uses singleton design pattern for some of its in-built classes. Uses of Singleton Design Pattern in Java As singleton class is global access of point, so we can use singleton design pattern when we need a global resource in our application and whose implementation is not going to changed by external class. Java Singleton Class Example Using Private Constructor. Now, first of all, what is Singleton and why is it required? - The Singleton's purpose is to control object creation, limiting the number of objects to only one. This issue does not lead to the presence of multiple singleton instances at a time, but when recreated, the instance might differ from its previous version. A singleton might be garbage-collected once no one holds a reference to it. In general, to avoid confusion we may also use the class name as method name while defining this method (Example code:II). Example of Basic Singleton Class. Singleton pattern is a design solution where an application wants to have one and only one instance of any class, in all possible scenarios without any exceptional condition. Simply put, it can result in more than one instance, breaking the pattern’s core principle. It also helps in providing a global access point to the object. While this is a common approach, it’s important to note that it can be problematic in a multithreading scenarios, which is the main reason for using Singletons. The last solution comes from the Effective Java book (Item 3) by Joshua Block and uses an enum instead of a class. This is ignoring you currently have a non-threadsafe implementation because your getInstance isn't synchronized. The class isn't loaded until invocation and so the reference isn't loaded until the class is. Conclusion Full code example in Java with detailed comments and explanation. Let's see the simple example of singleton design pattern using lazy instantiation. The singleton pattern is a design pattern that restricts the instantiation of a class to one object. At the time of writing, this is considered to be the most concise and safe way to write a singleton: public enum EnumSingleton { INSTANCE; // other methods... } 4. A thread-safe singleton class is to make the global access method synchronized. In such case, we create the instance of the class in synchronized method or synchronized block, so instance of the class is created when required. We often need to serialize/deserialize objects in Java. Every class loader might load its version of the singleton.