How to Break Singleton Design pattern in Java || Java Interview Questions and Answers | Code Decode

How to Break Singleton Design pattern in Java || Java Interview Questions and Answers | Code Decode

56.233 Lượt nghe
How to Break Singleton Design pattern in Java || Java Interview Questions and Answers | Code Decode
In this video of How to Break Singleton Design pattern of Java Interview Questions and Answers from Code Decode we will demonstrate how to break Singleton Design Pattern. Udemy Course of Code Decode on Microservice k8s AWS CICD link: https://openinapp.co/udemycourse Course Description Video : https://yt.openinapp.co/dmjvd ---------------------------------------------------------------------------------------------------------------------------------------------------------------- Promotional Links Coupon Code: CODE10 Registration link: https://relvl.co/z6a upGrad(BD) https://relvl.co/tl2 Urban Company(BD) https://relvl.co/zhu Vedantu(BD) https://relvl.co/ul4 Curefit(BD) https://relvl.co/dw7 Cred(FD) https://relvl.co/qke Digit(FD) https://relvl.co/g1c Razorpay(BE) https://relvl.co/tbl Yellow Messenger(BE) https://relvl.co/8gp Cred(BE) https://relvl.co/5kq 1mg(BE) https://relvl.co/vqm Digit(BE) https://relvl.co/8m3 --------------------------------------------------------------------------------------------------------------------------------------------------------------- Reflection: Reflection can be caused to destroy singleton property of singleton class After running this class, you will see that hashCodes are different that means, 2 objects of same class are created and singleton pattern has been destroyed. Serialization:- Serialization can also cause breakage of singleton property of singleton classes. Serialization is used to convert an object of byte stream and save in a file or send over a network. Suppose you serialize an object of a singleton class. Then if you de-serialize that object it will create a new instance and hence break the singleton pattern. As you can see, hashCode of both instances is different, hence there are 2 objects of a singleton class. Thus, the class is no more singleton. Above both hashcodes are same hence no other instance is created. Cloning: Cloning is a concept to create duplicate objects. Using clone we can create copy of object. Suppose, we create clone of a singleton object, then it wil create a copy that is there are two instances of a singleton class, hence the class is no more singleton. Two different hashCode means there are 2 different objects of singleton class. Code Decode Playlists Most Asked Core Java Interview Questions and Answers : https://youtube.com/playlist?list=PLyHJZXNdCXscoyL5XEZoHHZ86_6h3GWE1 Advance Java Interview Questions and Answers : https://youtube.com/playlist?list=PLyHJZXNdCXsexOO1VQ4vs-BM2-8CKrixd Java 8 Interview Questions and Answers : https://youtube.com/playlist?list=PLyHJZXNdCXsdeusn4OM33415DCMQ6sUKy Hibernate Interview Questions and Answers : https://youtube.com/playlist?list=PLyHJZXNdCXsdC-p2186C6NO4FpadnCC_q Spring Boot Interview Questions and Answers : https://youtube.com/playlist?list=PLyHJZXNdCXsexOO1VQ4vs-BM2-8CKrixd Angular Playlist : https://www.youtube.com/watch?v=CAl7RQSdq2Q&list=PLyHJZXNdCXsfxRtDwtGkDD_lLfTWc1g0i GIT : https://youtube.com/playlist?list=PLyHJZXNdCXscpl6pxOnL2lRWJlzvzjyZE Subscriber and Follow Code Decode Subscriber Code Decode : https://www.youtube.com/c/CodeDecode?sub_confirmation=1 Linkedin : https://www.linkedin.com/in/codedecodeyoutube/ Instagram : https://www.instagram.com/codedecode25/ #codedecode #breaksingletondesignpattern #javainterviewquestionanswers