Without Book Interview Questions and Answers | Online Test | Moct Test
Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Institute Training Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

EJB Interview Questions and Answers

Ques 11. What are transaction isolation levels in EJB?

Ans. Transaction_read_uncommitted, Transaction_read_committed, Transaction_repeatable_read.

Is it helpful? Add Comment View Comments
Ques 12. What do you mean by EJB?
Ans. 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.
Is it helpful? Add Comment View Comments
Ques 13. What are the different types of EJB?
Ans. Mainly three types of EJB, Entity Bean, Session Bean and Message Driven Bean(MDB).

Types of EJB:

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 behavior.

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 ,online reservation we use stateful session bean

Message Driven Beans: these beans are work as a listener for messaging services like JMS .
Is it helpful? Add Comment View Comments
Ques 14. Explain the life cycle method of EJB?
Ans. Life Cycle of Entity Bean:

First stage is Does Not Exist Stage then Container creates the instance of EJB and call SetEntityContext() method which will set all entity context to bean and now it will become available on pool ,to get a particular identity of an EJB object it has to move from Pooled stage to ready stage which is done by calling the create () method which in turns call ejbCreate() and ejbPostCreate() method .
There is another way by which directly entity bean can move to pooled stage to ready stage thatís is call ejbActivate() method.now we are ready to invoke the business method of entity bean .After completion of business method if we want to move again in pooled stage from ready stage we can call remove() method which in turns call ejbRemove() or directly call ejbPassivate () method.
At the end container remove the instance of EJBfrom pool and call unSetEntityContext().

Life Cycle of Stateful Session Bean :

Stateful session beans life cycle starts when client call create() method.The container create the instance of session bean and call setSessionContext() and ejbCreate() method
Now the stateful session bean is ready to serve the client request after serving the request if it is not used after a long time container can move this bean to passive stage by calling the ejbPassivate() method.similarly when bean is in passive stage and client invoke the business method the container call ejbActivate() method to move bean from passive stage to active or ready stage.
At the end of life cycle client call remove() method and container will call ejbRemove() method and bean is ready for garbage collection.

Life Cycle of Stateless session bean :

Stales session bean has short life cycle it can have two stage does not exist and ready stage. ejb container create the instance of stateless session bean and call setSessionContext () and ejbCreate() method.Now the bean is ready to invoke business method on this.it will not maintain the state so remove () method is been called after completion of business method which in turns call ejbRemove () and now its ready for garbage collection.
Life cycle of Message Driven bean:

MDBs have same life cycle like stateless session bean. setMessageDrivenContext() method and ejbCreate() method is called by container to create the instance of MDB.now its ready to receive message .and at the end of lifecycle client will call remove () method
which in turns call ejbRemove () and now its ready for garbage collection.
Is it helpful? Add Comment View Comments
Ques 15. can we have static initializer Block in EJB?
Ans. Purpose of Static initializer block is to initialize some static fields before any execution of constructor or method or we can say creation of object. According to EJB Spec itís a violation if static field are used and they are non final .

"EJB Spec":
Enterprise bean are not allowed to read or write the non final fields.

But technically,from the point of java its correct but if in EJB we use static initializer block to initialize static field then because EJB components are used in distributed environment mean to say if single JVM then it will be ok but if run on different JVM then it will be a problem if we change or update the value in on environment then only the instance running on same JVM have new value .thatís why static blocks are avoided and also all static field should be final.
And same thing we can achieve in ejbCreate(), setSessionContext() or setEntityContext() methods.
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2017 WithoutBook