LNT EJB 2012 solved questions

Posted by Stephen thangaraj at 16:31
EJB Basic Questions
What is EJB?
EJB stands for Enterprise Java Beans and is widely-adopted server side component architecture for J2EE. It enables rapid development of critical application that are versatile, reusable and portable across middleware while protecting IT investment and preventing vendor lock-in. It contains the application's business logic and live business data.
 What are the different kinds of enterprise beans?
 Different kind of enterprise beans are:
Session bean- It is a non-persistent object that implements some business logic running on the server. They are of two types session bean stateless and stateful.
Entity bean-It is used to represent data in the database. It provides an object-oriented interface.
Message-driven bean- They are enterprise beans that receive and process JMS messages. It doesn’t even have any interface.  
What is an EJB Context?
EJBContext is an interface that is implemented by the container, and is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects fill the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions.
How EJB Invocation happens? How can we call one EJB from inside of another EJB?
It retrieves Home Object reference from Naming Service via JNDI and Return Home Object reference to the client. This is how EJB Invocation happens.
EJBs can be clients of other EJBs. It j works in this way also. JNDI is used to locate the Home Interface of the other bean, and then instance references are acquire and so forth.
What is an EJB object?
 EJB objects are used to access the Business logic methods defined by the
user in the bean. It is created by the container when create() method is called by the Home interface. Client gets the reference of the object using JNDI, and their request invokes the business method on bean via the EJB object. The object implements Component Interface.
How can we integrate EJB and hibernate? How can we call hibernate DAO methods in session bean?
Hibernate is used to perform OR (object relational) mapping. it is alternate to DAO.servlets--->ejbSEssionbean(to store businesslogic)--->ejb entity bean(to maintain persistence logic)here we use hibernate instead of entity bean. This integration procedure separates business logic from persistence logic.To call DAO we use callback methods ejbcreate(), ejbload() to clear previousdatas in database,ejbstore()to store new datas using primary key value.
 What is bean managed transaction?
If a developer doesn’t want a Container to manage transactions, it’s possible to implement all database operations manually by writing the appropriate JDBC code. This often leads to productivity increase, but it makes an Entity Bean incompatible with some databases and it enlarges the amount of code to be written. All transaction management is explicitly performed by a developer.
 What is EJB QL?
 EJB QL is a Query Language provided for navigation across a network of enterprise beans and dependent objects defined by means of container managed persistence. EJB QL is used for queries of two types of finder methods that are defined in the home interface of an entity bean and which return entity objects.
Select methods, are not exposed to the client, but are used by the Bean Provider to select persistent values maintained by the Persistence Manager or to select entity objects related to the entity bean.
The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes?
The EJB container maintains an instance pool, which uses these instances for the EJB Home reference irrespective of the client request. While referring the EJB Object classes the container creates a separate instance for each client request. The instance pool maintenance is up to the implementation of the container. Most of the container providers implement the pooling functionality to increase the performance of the application server.
What is the difference between ejbStore() and ejbLoad()?What are the key benefits of the EJB technology?
The difference is : ejbStore() will be called before ejbPassivate() and is used to store the object to persistent database.ejbLoad() will be called before ejbActivate() and is used to retrieve the object from persistence data store.
Keys benefits are: Rapid application development, Broad industry adoption, Application portability, Protection of IT investment.
What are the constraints or drawbacks of container managed EJB’s?
Ans.> CMP in beans depends a lot on the EJB vendor implementation and utilities. With some implementations, container-managed entity beans can only be mapped to one table, while other implementations offer multiple table mappings to a single bean. The bottom line, it depends on the container provider being used.
 Is it possible to share an HttpSession between a JSP and EJB? What happens when we change a value in the HttpSession from inside an EJB?
 We can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as "passed-by-value", that means that it is read-only in the EJB. If anything is altered from inside the EJB, it would not be reflected back to the HttpSession of the Servlet Container.
Static variables in EJB should not be relied upon as they may break in clusters. Why?
 Static variables are only fine if they are final otherwise they will break the cluster, each part of the cluster will run in its own JVM.Eg.a method on the EJB is invoked on cluster 1 (we will have two clusters - 1 and 2) that causes value of the static variable to be increased to 101. On the subsequent call to the same EJB from the same client, a cluster 2 may be invoked to handle the request. A value of the static variable in cluster 2 is still 100 because it was not increased yet and therefore our application stops to be consistent.

click the Below link download this file 

If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!

Kindly Bookmark and Share it:



Have any question? Feel Free To Post Below:


© 2011. All Rights Reserved | Interview Questions | Template by Blogger Widgets

Home | About | Top