|
|
| java |
Expert:chandrasekhar
can you please send complete information about singleton class and where it can be used and how it can be used? |
| Answers |
hai friend singleton class means,We have to create one object for one class. By using private constuctor(i.e, we have to diclare your default constuctor as private).With this we can get singleton java class.That mean that java class will allow one object to access that class. With this we can avoid multithreading.This Singleton java class will use in Bank applications and in credit card transaction logic etc. to avoid multiple transaction at a time(to avoid multithreading).
Thanks you friend
|
Hi,
Code for Singleton Design Pattern
public class SingletonPattern{ private static SingletonPattern instance; private SingletonPattern(){} public static synchronized SingletonPattern getInstance(){ if (instance == null) { instance = new SingletonPattern(); } return instance; } public static void main(String arg[]){ System.out.println("The output of two instance:"); SingletonPattern sp=new SingletonPattern(); System.out.println("First Instance: "+sp.getInstance()); sp=new SingletonPattern(); System.out.println("Second Instance:"+sp.getInstance()); } }
Thanks
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|