How to implement or use the singleton class in java?
Answer Posted / amit sharma
singleton is a design pattern. in this per application only
one object should exist.we implement it as follows:
public class abcd
{
private static abcd instance=null;
protected abcd()
{
//only to defeat instantiation;
}
public static abcd getInstance()
{
if(instance==null)
{
instance=new abcd();
}
return instance;
}
| Is This Answer Correct ? | 11 Yes | 4 No |
Post New Answer View All Answers
Hi Friends, i have searched in google but not clear. can you give bank example with synchronized keyword
my interviewer asked me what technical specification you used how to answer that question
What are the queues in the java collection framework? : java collections
Which server-side script takes the input from JavaScript, can access the database if it needs to, and processes the data.
What are the interfaces in java collections? : java collections
Which sorting algorithm is used by collections.sort() in java ?
Hi frnds how to lock an user when he enter wrong credentials more than 3 time using java or j2ee tech take username and password in a bean no need to connect DB and validate give me some sample application code or links its urgent for me thanks in advance
What is an algorithm in java collection framework? : java collections
What is the use of hashcode in java ?
please mail me the interview question based on java/j2ee
What are the different types of collections views being provided by the map interface? : java collections
What do you understand by synchronization? Why is it important?
Which java collection class can be used to maintain the entries in the order in which they were last accessed?
What is iterator in the java collections framework? : java collections
What are the types of the main implementing classes in the map interfaces? : java collections