Interview Questions.

EJB Interview Questions and Answers

fluid

EJB Interview Questions and Answers

Q1. What is EJB?

Ans: EJB stands for Enterprise Java Beans. EJB is an crucial part of a J2EE platform. J2EE platform have factor based architecture to provide multi-tiered, dispensed and tremendously transactional features to corporation degree applications.

EJB offers an architecture to broaden and installation factor based agency applications thinking about robustness, excessive scalability and excessive overall performance. An EJB software may be deployed on any of the software server compliant with J2EE 1.Three trendy specification.

Q2. What are the special kinds of agency beans?

Ans:

Stateless session bean: An instance of those non-chronic EJBs presents a provider without storing an interaction or communication state among strategies. Any example can be used for any customer.

Stateful session bean: An instance of these non-chronic EJBs continues country throughout techniques and transactions. Each instance is associated with a selected patron.

Entity bean: An instance of these continual EJBs represents an object view of the facts, typically rows in a database. They have a primary key as a unique identifier. Entity bean patience can be either box-controlled or bean-controlled.

 

Message-driven bean: An instance of these EJBs is included with the Java Message Service (JMS) to offer the ability for message-pushed beans to act as a widespread JMS message patron and carry out asynchronous processing among the server and the JMS message manufacturer.

Q3. What is a EJB name?

Ans: EJB Calls from Servlets. A servlet can call Enterprise JavaBeans to perform additional processing. A usual utility layout often makes use of servlets as a the front-give up to do the preliminary processing of client requests, with EJBs being called to perform the commercial enterprise good judgment that accesses or updates a database.

Q4. What is JMS?

Ans: Java Message Service is a messaging service to create, send and receive messages asynchronously.

Q5. What are the blessings of EJB?

Ans: Following are the key blessings of EJB:

Simplified improvement of big scale organisation stage software.

Application Server/ EJB field offers maximum of the device stage services like transaction dealing with, logging, load balancing, patience mechanism, exception coping with and so forth. Developer has to focus most effective on enterprise logic of the application.

EJB box manages lifestyles cycle of ejb times as a consequence developer wishes no longer to fear approximately when to create/delete ejb gadgets.

Q6. What is supposed by using EJB box?

Ans: It manages and coordinates the allocation of assets to the packages. Enterprise beans typically include the enterprise good judgment for a J2EE utility. TheEJB server need to offer one or greater EJB boxes. An EJB field manages the employer beans contained inside it.

Q7. What is software structure of EJB?

Ans: Session and Entity EJBs encompass 4 and five components respetively:

A remote interface (a purchaser interacts with it).

A domestic interface (used for developing objects and for affirming enterprise techniques).

A bean object (an item, which clearly performs business common sense and EJB-precise operations).

A deployment descriptor (an XML document containing all statistics required for keeping the EJB) or a hard and fast of deployment descriptors (in case you are the usage of a few box-particular capabilities).

A Primary Key elegance - is best Entity bean precise.

Q8. What is supposed through POJO class in Java?

Ans: Acronym for Plain Old Java Object. POJO, or Plain Old Java Object, is a normalJava object class (this is, now not a JavaBean, EntityBean and so forth.) and does now not serve any other special position nor does it enforce any special interfaces of any of the Javaframeworks.

Following are the important thing components of staying power API in EJB:

Entity: A continual item representing the facts-store record. It is right to be serializable.

EntityManager: Persistence interface to do data operations like upload/delete/replace/locate on continual object(entity). It additionally facilitates to execute queries the use of Query interface.

Persistence unit (staying power.Xml): Persistence unit describes the residences of patience mechanism.

Data Source (*ds.Xml): Data Source describes the statistics-store related homes like connection url. Consumer-call,password and many others.

Q10. What are transaction attributes? 

Ans: The transaction attribute specifies how the Container should manipulate transactions for a method while a purchaser invokes the technique through the enterprise bean’s home or component interface or while the method is invoked as the result of the advent of a JMS message. (Sun's EJB Specification) Below is a listing of transactional attributes:

NotSupported: transaction context is unspecified.

Required: bean's approach invocation is made inside a transactional context. If a customer isn't associated with a transaction, a brand new transaction is invoked routinely.

Supports: if a transactional context exists, a Container acts like the transaction attribute is Required, else - like NotSupported.

RequiresNew: a technique is invoked in a new transaction context.

Mandatory: if a transactional context exists, a Container acts like the transaction attribute is Required, else it throws a javax.Ejb.TransactionRequiredException.

Never: a method executes only if no transaction context is particular.

Q11. What are the strategies of Entity Bean?

Ans: An entity bean includes four companies of methods:

Create methods: To create a brand new instance of a CMP entity bean, and therefore insert information into the database, the create() technique on the bean's domestic interface have to be invoked. They seem like this: EntityBeanClass ejbCreateXXX(parameters), in which EntityBeanClass is an Entity Bean you are attempting to instantiate, ejbCreateXXX(parameters) methods are used for developing Entity Bean times in keeping with the parameters exact and to a few programmer-defined conditions.

A bean's domestic interface might also claim zero or greater create() techniques, each of which have to have corresponding ejbCreate() and ejbPostCreate() methods inside the bean class. These advent techniques are linked at run time, so that after a create() method is invoked on the home interface, the container delegates the invocation to the corresponding ejbCreate() and ejbPostCreate() strategies at the bean elegance.

Finder methods: The strategies inside the home interface that start with "find" are known as the locate techniques. These are used to query the EJB server for unique entity beans, based on the call of the approach and arguments surpassed. Unfortunately, there's no preferred question language defined for find methods, so every dealer will put in force the locate method in another way. In CMP entity beans, the find techniques are not applied with matching methods inside the bean magnificence; containers enforce them while the bean is deployed in a dealer specific manner. The deployer will use vendor unique gear to tell the box how a particular find technique ought to behave. Some vendors will use item-relational mapping equipment to outline the behavior of a discover technique even as others will simply require the deployer to enter the precise SQL command.

There are  primary varieties of locate strategies: single-entity and multi-entity. Single-entity find methods return a far flung connection with the only specific entity bean that suits the locate request. If no entity beans are discovered, the approach throws an ObjectNotFoundException . Every entity bean ought to define the unmarried-entity locate technique with the approach call findByPrimaryKey(), which takes the bean's primary key type as a controversy.

The multi-entity locate strategies go back a collection ( Enumeration or Collection type) of entities that in shape the locate request. If no entities are discovered, the multi-entity discover returns an empty series.

Remove techniques: These strategies (you may have up to two eliminate techniques, or don't have them in any respect) allow the client to bodily take away Entity beans by means of specifying both Handle or a Primary Key for the Entity Bean.

Home techniques: These methods are designed and carried out by way of a developer, and EJB specification would not have any requirements for them except the need to throw a RemoteException is each home technique.

Q12. Can I expand an Entity Bean without enforcing the create() approach within the domestic interface?

Ans: As in line with the specs, there can be 'ZERO' or 'MORE' create() techniques described in an Entity Bean. In instances where create() method is not supplied, the only manner to get entry to the bean is by way of knowing its primary key, and by acquiring a handle to it through using its corresponding finder approach. In those cases, you can create an instance of a bean primarily based on the data present within the table. All one needs to recognize is the number one key of that desk. I.E. A fixed a columns that uniquely perceive a unmarried row in that table. Once this is known, you'll be able to use the 'getPrimaryKey()' to get a far flung connection with that bean, that may further be used to invoke commercial enterprise methods.

Q13. Why an onMessage name in Message-pushed bean is continually a seperate transaction?

Ans: EJB 2.Zero specification: "An onMessage name is continually a separate transaction, because there's by no means a transaction in development whilst the method is called."

Q14. When a message arrives, it's far passed to the Message Driven Bean via the onMessage() method, this is where the commercial enterprise good judgment is going.

Ans: Since there is no assure when the approach is referred to as and while the message might be processed, is the container that is responsible of handling the environment, which includes transactions.

Q15. What is clustering?

Ans: Clustering is grouping machines collectively to transparantly provide company services. Clustering is an important piece to fixing the desires for modern-day large web sites.

The consumer does not recognize the difference among drawing close one server or coming near a cluster of servers

Q16. Why are ejbActivate() and ejbPassivate() included for stateless session bean even though they're never required as it is a nonconversational bean?

Ans: To have a constant interface, in order that there is no special interface which you need to put in force for Stateful Session Bean and Stateless Session Bean. Both Stateless and Stateful Session Bean enforce javax.Ejb.SessionBean and this will no longer be viable if stateless consultation bean is to put off ejbActivate and ejbPassivate from the interface.

Q17. Static variables in EJB ought to now not be relied upon as they may wreck in clusters.Why?

Ans: Static variables are most effective good enough if they're very last. If they are no longer final, they'll smash the cluster. What that means is that in case you cluster your software server (spread it throughout numerous machines) every part of the cluster will run in its own JVM.

Say a way on the EJB is invoked on cluster 1 (we will have two clusters - 1 and 2) that reasons price of the static variable to be expanded to a hundred and one. On the subsequent call to the equal EJB from the identical consumer, a cluster 2 can be invoked to deal with the request. A fee of the static variable in cluster 2 continues to be 100 as it become not accelerated but and therefore your application ceases to be regular. Therefore, static non-final variables are strongly discouraged in EJBs.




CFG