Why singleton pattern is better than creating singleton class with static instance?



Why singleton pattern is better than creating singleton class with static instance?..

Answer / Mohammad Aakib

The Singleton pattern ensures that only one instance of a class exists, enforces thread-safety, and provides a global point of access to the object. Creating a singleton class with static instance does not enforce thread-safety and may lead to inconsistent behavior in multi-threaded environments.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

AWT event listeners extends what interface?

1 Answers  


Name the components that are termed to be Heavy-weight component but available in Light-weight components?

1 Answers  


Where is the singleton class used?

1 Answers   Cap Gemini,


How many types of constructors are used in java?

1 Answers  


What is inheritance?

5 Answers   Accenture, Hexaware, Syntel,


How is string stored in java?

1 Answers  


How are variables stored in memory?

1 Answers  


Q) I have a ArrayList object, in that object i have added 5 integer values, 5 float values, 5 string values. Now question is how can delete particular type of data ( i.e all int values or all float values or string values) in that list object at a time?

3 Answers   Aricent,


What is better - 'bit-shift a value' or 'multiply by 2'?

1 Answers   DELL,


What is flag in python?

1 Answers  


How does finally block differ from finalize() method?

1 Answers  


Tell me the difference between an applet and a Japplet?

1 Answers  


Categories