Notes
Untitled
Content of the notes (4)
Page 1
Singleton class:
1. One Object
2. Return the same object whenever we create a new instance
We use Singleton class to prevent the creation of multiple classes.
Page 2
Eagle initialization: instance created at the starting of the server in web application.
Lazy initialization: instance created during first user call.
Page 3
Factory method: it's like a class calling constructor similarliy singleton class calls factory initialization.
Returns the object of the class.
Example :
1. Runtime run = Runtime.getRuntime();
2. Calender c1 = Calender.getinstance();
Here new operator is not used to create object. But we call static method: getRuntime() and getInstance(). this return object of this classes.
Page 4
Steps to Create Singleton Class:
1. create a static variable object of type class.
2. private constructor_name(){}
3. Creating a public method known as getInstance( ) in which we will create a instance and return the object
Information
- Description
- Note on Untitled, created by vivek singh on 04/06/2019.
- Created by
- vivek singh
- Views
- 0
- Rating