SlideShare a Scribd company logo
1 of 31
EJB
Enterprise Java Bean
• EJB (Enterprise Java Bean) is used to develop
scalable, robust and secured enterprise
applications in java.
• Unlike RMI, middleware services such as security,
transaction management etc. are provided by EJB
Container to all EJB applications.
• The current version of EJB is EJB 3.2. The
development of EJB 3 is faster than EJB 2 because
of simplicity and annotations such as @EJB,
@Stateless, @Stateful, @ModelDriven,
@PreDestroy, @PostConstruct etc.
What is EJB
• EJB is an acronym for enterprise java bean. It
is a specification provided by Sun
Microsystems to develop secured, robust and
scalable distributed applications.
• To get information about distributed
applications, visit RMI Tutorial first.
• To run EJB application, you need
an application server (EJB Container) such as
Jboss, Glassfish, Weblogic, Websphere etc.
What is EJB
• It performs:
• life cycle management,
• security,
• transaction management, and
• object pooling.
• EJB application is deployed on the server, so it is
called server side component also.
• EJB is like COM (Component Object Model)
provided by Microsoft. But, it is different from
Java Bean, RMI and Web Services.
When use Enterprise Java Bean?
• Application needs Remote Access. In other
words, it is distributed.
• Application needs to be scalable. EJB
applications supports load balancing,
clustering and fail-over.
• Application needs encapsulated business
logic. EJB application is separated from
presentation and persistent layer.
Types of Enterprise Java Bean
• There are 3 types of enterprise bean in java.
• Session Bean
• Session bean contains business logic that can be
invoked by local, remote or webservice client.
• Message Driven Bean
• Like Session Bean, it contains the business logic but it is
invoked by passing message.
• Entity Bean
• It encapsulates the state that can be persisted in the
database. It is deprecated. Now, it is replaced with JPA
(Java Persistent API).
Difference between RMI and EJB
RMI EJB
In RMI, middleware services
such as security, transaction
management, object pooling
etc. need to be done by the
java programmer.
In EJB, middleware services are
provided by EJB Container
automatically.
RMI is not a server-side
component. It is not required to
be deployed on the server.
EJB is a server-side component,
it is required to be deployed on
the server.
RMI is built on the top of socket
programming.
EJB technology is built on the
top of RMI.
EJB and Webservice
• In EJB, bean component and bean client both
must be written in java language.
• If bean client need to be written in other
language such as .net, php etc, we need to go
with webservices (SOAP or REST). So EJB with
web service will be better option.
Disadvantages of EJB
• Requires application server
• Requires only java client. For other language
client, you need to go for webservice.
• Complex to understand and develop ejb
applications.
Session Bean
• Session bean encapsulates business logic only,
it can be invoked by local, remote and
webservice client.
• It can be used for calculations, database
access etc.
• The life cycle of session bean is maintained by
the application server (EJB Container).
Types of Session Bean
• There are 3 types of session bean.
• 1) Stateless Session Bean: It doesn't maintain
state of a client between multiple method
calls.
• 2) Stateful Session Bean: It maintains state of
a client across multiple requests.
• 3) Singleton Session Bean: One instance per
application, it is shared between clients and
supports concurrent access.
Stateless Session Bean
• Stateless Session bean is a business object that
represents business logic only. It doesn't have
state (data).
• In other words, conversational state between
multiple method calls is not maintained by the
container in case of stateless session bean.
• The stateless bean objects are pooled by the EJB
container to service the request on demand.
• It can be accessed by one client at a time. In case
of concurrent access, EJB container routes each
request to different instance.
Annotations used in Stateless Session
Bean
• There are 3 important annotations used in
stateless session bean:
• @Stateless
• @PostConstruct
• @PreDestroy
Life cycle of Stateless Session Bean
• There is only two states of stateless session bean: does not
exist and ready. It is explained by the figure given below.
Life cycle of Stateless Session Bean
EJB Container creates and maintains a pool of
session bean first. It injects the dependency if
then calls the @PostConstruct method if any.
Now actual business logic method is invoked by
the client. Then, container calls @PreDestory
method if any. Now bean is ready for garbage
collection.
Stateful Session Bean
• Stateful Session bean is a business object that
represents business logic like stateless session
bean. But, it maintains state (data).
• In other words, conversational state between
multiple method calls is maintained by the
container in stateful session bean.
Annotations used in Stateful Session
Bean
There are 5 important annotations used in
stateful session bean:
• @Stateful
• @PostConstruct
• @PreDestroy
• @PrePassivate
• @PostActivate
JMS
• JMS (Java Message Service) is an API that
provides the facility to create, send and read
messages. It provides loosely coupled, reliable
and asynchronous communication.
• JMS is also known as a messaging service.
Understanding Messaging
• Messaging is a technique to communicate
applications or software components.
• JMS is mainly used to send and receive
message from one application to another.
Requirement of JMS
• Generally, user sends message to application.
But, if we want to send message from one
application to another, we need to use JMS
API.
• Consider a scenario, one application A is
running in INDIA and another application B is
running in USA. To send message from A
application to B, we need to use JMS.
Advantage of JMS
• 1) Asynchronous: To receive the message,
client is not required to send request.
Message will arrive automatically to the client.
• 2) Reliable: It provides assurance that
message is delivered.
Messaging Domains
• There are two types of messaging domains in
JMS.
• Point-to-Point Messaging Domain
• Publisher/Subscriber Messaging Domain
Point-to-Point (PTP) Messaging
Domain
• In PTP model, one message is delivered to
one receiver only. Here, Queue is used as a
message oriented middleware (MOM).
• The Queue is responsible to hold the message
until receiver is ready.
• In PTP model, there is no timing
dependency between sender and receiver.
Publisher/Subscriber (Pub/Sub)
Messaging Domain
• In Pub/Sub model, one message is delivered
to all the subscribers. It is like broadcasting.
Here, Topic is used as a message oriented
middleware that is responsible to hold and
deliver messages.
• In PTP model, there is timing
dependency between publisher and
subscriber.
JMS Programming Model
Message Driven Bean
A message driven bean (MDB) is a bean that contains business
logic. But, it is invoked by passing the message. So, it is like
JMS Receiver.
MDB asynchronously receives the message and processes it.
A message driven bean receives message from queue or topic,
so you must have the knowledge of JMS API.
A message driven bean is like stateless session bean that
encapsulates the business logic and doesn't maintain state.
Entity Bean in EJB 3.x
• Entity bean represents the persistent data stored in the
database. It is a server-side component.
• In EJB 2.x, there was two types of entity beans: bean
managed persistence (BMP) and container managed
persistence (CMP).
• Since EJB 3.x, it is deprecated and replaced by JPA (Java
Persistence API) that is covered in the hibernate
tutorial.
• In hibernate tutorial, there are given hibernate with
annotation examples where we are using JPA
annotations. The JPA with Hibernate is widely used
today.
enterprise java bean

More Related Content

What's hot (20)

Java rmi
Java rmiJava rmi
Java rmi
 
JVM
JVMJVM
JVM
 
Introduction to java beans
Introduction to java beansIntroduction to java beans
Introduction to java beans
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Servlets
ServletsServlets
Servlets
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
 
Java beans
Java beansJava beans
Java beans
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
Java servlets
Java servletsJava servlets
Java servlets
 
Java beans
Java beansJava beans
Java beans
 
RichControl in Asp.net
RichControl in Asp.netRichControl in Asp.net
RichControl in Asp.net
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 

Similar to enterprise java bean

EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionKelum Senanayake
 
J2 ee container & components
J2 ee container & componentsJ2 ee container & components
J2 ee container & componentsKeshab Nath
 
Connecting ejb with mule
Connecting ejb with muleConnecting ejb with mule
Connecting ejb with muleRuman Khan
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questionsguest346cb1
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecturetayab4687
 
Session 2 Tp2
Session 2 Tp2Session 2 Tp2
Session 2 Tp2phanleson
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...SSA KPI
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006achraf_ing
 

Similar to enterprise java bean (20)

Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 
Introcution to EJB
Introcution to EJBIntrocution to EJB
Introcution to EJB
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
EJB.docx
EJB.docxEJB.docx
EJB.docx
 
Java j2eeTutorial
Java j2eeTutorialJava j2eeTutorial
Java j2eeTutorial
 
J2 ee container & components
J2 ee container & componentsJ2 ee container & components
J2 ee container & components
 
Connecting ejb with mule
Connecting ejb with muleConnecting ejb with mule
Connecting ejb with mule
 
UNIT 4.pptx
UNIT 4.pptxUNIT 4.pptx
UNIT 4.pptx
 
EJB 2
EJB 2EJB 2
EJB 2
 
Ejb notes
Ejb notesEjb notes
Ejb notes
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejb
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
 
Session 2 Tp2
Session 2 Tp2Session 2 Tp2
Session 2 Tp2
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006
 
EJB 3.0 and J2EE
EJB 3.0 and J2EEEJB 3.0 and J2EE
EJB 3.0 and J2EE
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

enterprise java bean

  • 1. EJB
  • 2. Enterprise Java Bean • EJB (Enterprise Java Bean) is used to develop scalable, robust and secured enterprise applications in java. • Unlike RMI, middleware services such as security, transaction management etc. are provided by EJB Container to all EJB applications. • The current version of EJB is EJB 3.2. The development of EJB 3 is faster than EJB 2 because of simplicity and annotations such as @EJB, @Stateless, @Stateful, @ModelDriven, @PreDestroy, @PostConstruct etc.
  • 3. What is EJB • EJB is an acronym for enterprise java bean. It is a specification provided by Sun Microsystems to develop secured, robust and scalable distributed applications. • To get information about distributed applications, visit RMI Tutorial first. • To run EJB application, you need an application server (EJB Container) such as Jboss, Glassfish, Weblogic, Websphere etc.
  • 4. What is EJB • It performs: • life cycle management, • security, • transaction management, and • object pooling. • EJB application is deployed on the server, so it is called server side component also. • EJB is like COM (Component Object Model) provided by Microsoft. But, it is different from Java Bean, RMI and Web Services.
  • 5. When use Enterprise Java Bean? • Application needs Remote Access. In other words, it is distributed. • Application needs to be scalable. EJB applications supports load balancing, clustering and fail-over. • Application needs encapsulated business logic. EJB application is separated from presentation and persistent layer.
  • 6. Types of Enterprise Java Bean • There are 3 types of enterprise bean in java. • Session Bean • Session bean contains business logic that can be invoked by local, remote or webservice client. • Message Driven Bean • Like Session Bean, it contains the business logic but it is invoked by passing message. • Entity Bean • It encapsulates the state that can be persisted in the database. It is deprecated. Now, it is replaced with JPA (Java Persistent API).
  • 7. Difference between RMI and EJB RMI EJB In RMI, middleware services such as security, transaction management, object pooling etc. need to be done by the java programmer. In EJB, middleware services are provided by EJB Container automatically. RMI is not a server-side component. It is not required to be deployed on the server. EJB is a server-side component, it is required to be deployed on the server. RMI is built on the top of socket programming. EJB technology is built on the top of RMI.
  • 8. EJB and Webservice • In EJB, bean component and bean client both must be written in java language. • If bean client need to be written in other language such as .net, php etc, we need to go with webservices (SOAP or REST). So EJB with web service will be better option.
  • 9. Disadvantages of EJB • Requires application server • Requires only java client. For other language client, you need to go for webservice. • Complex to understand and develop ejb applications.
  • 10. Session Bean • Session bean encapsulates business logic only, it can be invoked by local, remote and webservice client. • It can be used for calculations, database access etc. • The life cycle of session bean is maintained by the application server (EJB Container).
  • 11. Types of Session Bean • There are 3 types of session bean. • 1) Stateless Session Bean: It doesn't maintain state of a client between multiple method calls. • 2) Stateful Session Bean: It maintains state of a client across multiple requests. • 3) Singleton Session Bean: One instance per application, it is shared between clients and supports concurrent access.
  • 12. Stateless Session Bean • Stateless Session bean is a business object that represents business logic only. It doesn't have state (data). • In other words, conversational state between multiple method calls is not maintained by the container in case of stateless session bean. • The stateless bean objects are pooled by the EJB container to service the request on demand. • It can be accessed by one client at a time. In case of concurrent access, EJB container routes each request to different instance.
  • 13. Annotations used in Stateless Session Bean • There are 3 important annotations used in stateless session bean: • @Stateless • @PostConstruct • @PreDestroy
  • 14. Life cycle of Stateless Session Bean • There is only two states of stateless session bean: does not exist and ready. It is explained by the figure given below.
  • 15. Life cycle of Stateless Session Bean EJB Container creates and maintains a pool of session bean first. It injects the dependency if then calls the @PostConstruct method if any. Now actual business logic method is invoked by the client. Then, container calls @PreDestory method if any. Now bean is ready for garbage collection.
  • 16. Stateful Session Bean • Stateful Session bean is a business object that represents business logic like stateless session bean. But, it maintains state (data). • In other words, conversational state between multiple method calls is maintained by the container in stateful session bean.
  • 17. Annotations used in Stateful Session Bean There are 5 important annotations used in stateful session bean: • @Stateful • @PostConstruct • @PreDestroy • @PrePassivate • @PostActivate
  • 18. JMS • JMS (Java Message Service) is an API that provides the facility to create, send and read messages. It provides loosely coupled, reliable and asynchronous communication. • JMS is also known as a messaging service.
  • 19. Understanding Messaging • Messaging is a technique to communicate applications or software components. • JMS is mainly used to send and receive message from one application to another.
  • 20. Requirement of JMS • Generally, user sends message to application. But, if we want to send message from one application to another, we need to use JMS API. • Consider a scenario, one application A is running in INDIA and another application B is running in USA. To send message from A application to B, we need to use JMS.
  • 21. Advantage of JMS • 1) Asynchronous: To receive the message, client is not required to send request. Message will arrive automatically to the client. • 2) Reliable: It provides assurance that message is delivered.
  • 22. Messaging Domains • There are two types of messaging domains in JMS. • Point-to-Point Messaging Domain • Publisher/Subscriber Messaging Domain
  • 23. Point-to-Point (PTP) Messaging Domain • In PTP model, one message is delivered to one receiver only. Here, Queue is used as a message oriented middleware (MOM). • The Queue is responsible to hold the message until receiver is ready. • In PTP model, there is no timing dependency between sender and receiver.
  • 24.
  • 25. Publisher/Subscriber (Pub/Sub) Messaging Domain • In Pub/Sub model, one message is delivered to all the subscribers. It is like broadcasting. Here, Topic is used as a message oriented middleware that is responsible to hold and deliver messages. • In PTP model, there is timing dependency between publisher and subscriber.
  • 26.
  • 28. Message Driven Bean A message driven bean (MDB) is a bean that contains business logic. But, it is invoked by passing the message. So, it is like JMS Receiver. MDB asynchronously receives the message and processes it. A message driven bean receives message from queue or topic, so you must have the knowledge of JMS API. A message driven bean is like stateless session bean that encapsulates the business logic and doesn't maintain state.
  • 29.
  • 30. Entity Bean in EJB 3.x • Entity bean represents the persistent data stored in the database. It is a server-side component. • In EJB 2.x, there was two types of entity beans: bean managed persistence (BMP) and container managed persistence (CMP). • Since EJB 3.x, it is deprecated and replaced by JPA (Java Persistence API) that is covered in the hibernate tutorial. • In hibernate tutorial, there are given hibernate with annotation examples where we are using JPA annotations. The JPA with Hibernate is widely used today.