Enterprise Java Beans EJB

Enterprise java bean is a server side component which runs on application server or we call container, developed for the purpose of distributed and enterprise level application .container will provide support for system level services like Transaction Management, security which make developer task easy and he can focus on business logic.

Mainly three types of EJB, Entity Bean, Session Bean and Message Driven Bean(MDB).

Entity Bean: it represents an entity which is mapped with database or we can say it makes OR object Relational mapping with Database. Entity bean typically represent table in RDBMS and each instance represent row in the table.
 Two types of entity bean:
·          CMP Entity bean: Container managed entity bean its responsibility of container to manage the bean persistence behavior.
·          BMP Entity bean: Programmer manage the bean persistence behaviour.

Session bean: Session bean is responsible for developing business logic it makes the client server relationship so session beans exist till there is a session exist between client and server, it doesn't contain persistent business concept.
 Types of session bean
·          Stateless session bean: when there is not need to maintain state of a particular client stateless session bean is used .They alive for short period of time.
       For example if we are validating the credit card we can use stateless session bean.
·          Stateful session bean: stateful session bean maintain the conversational state of client over the series of method call before the bean instance goes to passive state conversational state is saved to persistence area like Hard disk and again when same client send a request and bean instance come into the active state it will come out from hard disk to main memory.
      For Example when we do online banking transaction or online reservation we use stateful session bean
Message Driven Beans: these beans are work as a listener for messaging services like JMS .



Can we run EJB in web server like Tomcat ?
One of the tricky interview question on EJB. No you can not run EJB in web server like Tomcat. You need application server like Glassfish, WebLogic or Websphere to run Enterprise Java beans.

What are the services provided by EJB container ?
Container is one of the main reason why Programmer should use Enterprise Java beans. EJB container provide several useful services like :
1) life cycle management of Enterprise Java beans (EJB).
2) Container manged transaction
3) Container managed persistent
4) Security etc

What is main difference between EJB 2.0 and EJB 3.0 ?
Simple answer is use of Java annotation, ease of development etc.

Can you name few annotation used in EJB 3.0 and what does the do ?
This is another simple EJB 3.0 interview question which can be easily answer if you have coded few EJB 3.0 beans. Some annotations used are @EJB, @PreDestory,  @PostConstruct etc.

No comments:

Post a Comment