![]() ![]() If you know how to apply and use these time-tested design patterns then you can write better code, I mean the code which is more inextensible, maintainable, and flexible. These Software design patterns provide templates and tricks used to design and solve real-world software problems and tasks. Good knowledge of Software design patterns goes a long way in becoming a better Java developer which every company looks for. This is the easiest method but it has a drawback that instance is created even though it might not be using it by any client.Design patterns in Java interviews are as crucial as multi-threading, collection, and programming questions and one should not neglect it. In eager initialization, the instance of Singleton Class is created at the time of class loading. Question: What is eager initialization in singleton? Question: Can we create a clone of a singleton object? Answer: Yes, it is possible Question: How to prevent cloning of a singleton object? Answer: By throwing an exception within the body of the clone() method. Question: Can you write thread-safe Singleton in Java? There are multiple ways to write thread-safe singleton in Java Question: If the singletons getInstance is not synchronized, how it would behave in multithreaded environment? Answer: Threads can be unpredictable, we can't guarantee when the method is unsynchronized it would give max of two singleton instance. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |