EJB (Enterprise JavaBeans) is a collection of server side methods which is used for wrapping business logic. Code and data variables within EJB are hidden from programmers. A container is used for running an EJB in an application server. Container is used for providing different services like memory management, network and database access, etc.
Types of EJB:
1) Entity bean: Entity bean is used for specifying a business object. Each entity bean is associated with a particular row of a table. An application created by using entity bean has more object oriented codes.
2) Session bean: Session beans are used to specify individual user sessions in the application server. Each active user is associated with a session bean. An application created by using session bean has more procedural codes. Session beans are further classified as:
a) Stateless session bean: In this type of a session bean, status information is not maintained when methods are called. Actions are performed with a single user at a time and single request at a time. A request to the bean does not depend on previous requests. It decreases the processing overhead in a database and thus performance is increased.
b) Stateful session bean: In this type of a session bean, status information is maintained when methods are called. The bean remembers the state of requests from the previous calls. The state information is stored by using private instance variables. It increases the processing overhead in a database and thus performance is decreased.