SlideShare a Scribd company logo
1 of 5
 Introduction
 Java Bean vs Basic Java Class
 A bean is java class,but a java class does not have a bean.
 A Java Bean is a java class that should follow following conventions:-
1.It should have a default constructor.
2.It should have a serializable.
3.It should provide methods to set and get the values of the properties, known as
getter and setter methods.
 Why use Java Bean ?
 It is reusable software component.
 A bean encapsulates many objects into one object, so we can access this object from multiple places.
 Morever,it provides the easy maintenance.
 Bean Life Cycle
 The life cycle of a spring bean is easy to understand.
 When a beam is instantiated,it may be required to perform some initialization to get it into a usable state.
 Similarly,when the beam is no longer required and is removed from the container,some cleanup may be required.
 Life Cycle Methods :-
I) public void init()
II) public void destroy()
I) You can add custome code during bean initialization
• Calling custom business logic methods.
• Setting up handles to resources (db,sockets,file,etc.)
II) You can add custome code during bean destruction
• Calling custom business logic methods.
• Clean up handles to resources (db,sockets,files,etc.)
 Bean Life Cycle
We can choose custom method name instead of init() and destroy(). Here, we will use init() method to execute all its code as the
spring container starts up and the bean is instantiated, and destroy() method to execute all its code on closing the container.
Bean Life Cycle Process Flow
 Ways to implement the Life Cycle of Bean
There are 3 ways to Implements:-
[1]By XML
[2]By Programmatic Approach
[3]Using Annotations
[1]By XML
 In this approach, in order to avail custom init() and destroy() method for a bean we have to register these two
methods inside Spring XML configuration file while defining a bean. Therefore, the following steps are followed:
a) Firstly, we need to create a bean ,write the init() and destroy() methods in the class.
b) We need to configure the spring XML file need to register the init() and destroy() methods in it.
Ways to Implement the Life Cycle Bean
[2]BY Programmatic Approach:-
 To provide the facility to the created bean to invoke custom init() method on the startup of a spring container and to invoke the
custom destroy() method on closing the container,
 We need to implement our bean with two interfaces namely InitializingBean, DisposableBean and will have to override
afterPropertiesSet() and destroy() method.
 afterPropertiesSet() method is invoked as the container starts and the bean is instantiated whereas, the destroy() method is
invoked just after the container is closed.
[3]Using Annotations
 To provide the facility to the created bean to invoke custom init() method on the startup of a spring container and to invoke the
custom destroy() method on closing the container.
 We need annotate init() method by @PostConstruct annotation and destroy() method by @PreDestroy annotation.

More Related Content

Similar to Introduction of Life Cycle.pptx

02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
Dhiraj Champawat
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
phanleson
 
Spring training
Spring trainingSpring training
Spring training
shah_d_p
 
Spring framework
Spring frameworkSpring framework
Spring framework
Ajit Koti
 
Spring Fa Qs
Spring Fa QsSpring Fa Qs
Spring Fa Qs
jbashask
 
Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3
phanleson
 

Similar to Introduction of Life Cycle.pptx (20)

Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
 
1-introduction to ejb
1-introduction to ejb1-introduction to ejb
1-introduction to ejb
 
Spring training
Spring trainingSpring training
Spring training
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Week2 아주 작은 빈 이야기
Week2 아주 작은 빈 이야기Week2 아주 작은 빈 이야기
Week2 아주 작은 빈 이야기
 
Spring 3.0 dependancy injection
Spring 3.0 dependancy injectionSpring 3.0 dependancy injection
Spring 3.0 dependancy injection
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Java beans
Java beansJava beans
Java beans
 
Spring Fa Qs
Spring Fa QsSpring Fa Qs
Spring Fa Qs
 
Javabean1
Javabean1Javabean1
Javabean1
 
Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3
 
Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample
 
Console to GUI
Console to GUIConsole to GUI
Console to GUI
 
Unit iv
Unit ivUnit iv
Unit iv
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Azure Pipelines
Azure PipelinesAzure Pipelines
Azure Pipelines
 
Spring framework
Spring frameworkSpring framework
Spring framework
 

Recently uploaded

Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
amitlee9823
 
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
amitlee9823
 
Internship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkInternship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmk
SujalTamhane
 
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
amitlee9823
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
ZurliaSoop
 
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night StandCall Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
amitlee9823
 

Recently uploaded (20)

Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
CFO_SB_Career History_Multi Sector Experience
CFO_SB_Career History_Multi Sector ExperienceCFO_SB_Career History_Multi Sector Experience
CFO_SB_Career History_Multi Sector Experience
 
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
 
Dubai Call Girls Kiki O525547819 Call Girls Dubai Koko
Dubai Call Girls Kiki O525547819 Call Girls Dubai KokoDubai Call Girls Kiki O525547819 Call Girls Dubai Koko
Dubai Call Girls Kiki O525547819 Call Girls Dubai Koko
 
Guide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWNGuide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWN
 
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
 
Internship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkInternship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmk
 
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
 
Rearing technique of lac insect and their management
Rearing technique of lac insect and their managementRearing technique of lac insect and their management
Rearing technique of lac insect and their management
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
 
Booking open Available Pune Call Girls Ambegaon Khurd 6297143586 Call Hot In...
Booking open Available Pune Call Girls Ambegaon Khurd  6297143586 Call Hot In...Booking open Available Pune Call Girls Ambegaon Khurd  6297143586 Call Hot In...
Booking open Available Pune Call Girls Ambegaon Khurd 6297143586 Call Hot In...
 
Miletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdfMiletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdf
 
TEST BANK For Evidence-Based Practice for Nurses Appraisal and Application of...
TEST BANK For Evidence-Based Practice for Nurses Appraisal and Application of...TEST BANK For Evidence-Based Practice for Nurses Appraisal and Application of...
TEST BANK For Evidence-Based Practice for Nurses Appraisal and Application of...
 
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night StandCall Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
 
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big BoodyDubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
 
Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...
Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...
Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...
 
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Nandini Layout Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...
Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...
Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...
 
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls DubaiDark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
 

Introduction of Life Cycle.pptx

  • 1.  Introduction  Java Bean vs Basic Java Class  A bean is java class,but a java class does not have a bean.  A Java Bean is a java class that should follow following conventions:- 1.It should have a default constructor. 2.It should have a serializable. 3.It should provide methods to set and get the values of the properties, known as getter and setter methods.  Why use Java Bean ?  It is reusable software component.  A bean encapsulates many objects into one object, so we can access this object from multiple places.  Morever,it provides the easy maintenance.
  • 2.  Bean Life Cycle  The life cycle of a spring bean is easy to understand.  When a beam is instantiated,it may be required to perform some initialization to get it into a usable state.  Similarly,when the beam is no longer required and is removed from the container,some cleanup may be required.  Life Cycle Methods :- I) public void init() II) public void destroy() I) You can add custome code during bean initialization • Calling custom business logic methods. • Setting up handles to resources (db,sockets,file,etc.) II) You can add custome code during bean destruction • Calling custom business logic methods. • Clean up handles to resources (db,sockets,files,etc.)
  • 3.  Bean Life Cycle We can choose custom method name instead of init() and destroy(). Here, we will use init() method to execute all its code as the spring container starts up and the bean is instantiated, and destroy() method to execute all its code on closing the container. Bean Life Cycle Process Flow
  • 4.  Ways to implement the Life Cycle of Bean There are 3 ways to Implements:- [1]By XML [2]By Programmatic Approach [3]Using Annotations [1]By XML  In this approach, in order to avail custom init() and destroy() method for a bean we have to register these two methods inside Spring XML configuration file while defining a bean. Therefore, the following steps are followed: a) Firstly, we need to create a bean ,write the init() and destroy() methods in the class. b) We need to configure the spring XML file need to register the init() and destroy() methods in it.
  • 5. Ways to Implement the Life Cycle Bean [2]BY Programmatic Approach:-  To provide the facility to the created bean to invoke custom init() method on the startup of a spring container and to invoke the custom destroy() method on closing the container,  We need to implement our bean with two interfaces namely InitializingBean, DisposableBean and will have to override afterPropertiesSet() and destroy() method.  afterPropertiesSet() method is invoked as the container starts and the bean is instantiated whereas, the destroy() method is invoked just after the container is closed. [3]Using Annotations  To provide the facility to the created bean to invoke custom init() method on the startup of a spring container and to invoke the custom destroy() method on closing the container.  We need annotate init() method by @PostConstruct annotation and destroy() method by @PreDestroy annotation.