• +91 9971497814
  • info@interviewmaterial.com

EJB Interview Questions Answers

Question 1 : Are enterprise beans allowed to use Thread.sleep()?

Answer 1 : Enterprise beans make use of the services provided by the EJB container, such as life-cycle management. To avoid conflicts with these services, enterprise beans are restricted from performing certain operations: Managing or synchronizing threads

Question 2 : Can a Session Bean be defined without ejbCreate() method?

Answer 2 : The ejbCreate() methods is part of the bean’s lifecycle, so, the compiler will not return an error because there is no ejbCreate() method. However, the J2EE spec is explicit: · the home interface of a Stateless Session Bean must have a single create() method with no arguments, while the session bean class must contain exactly one ejbCreate() method, also without arguments. · Stateful Session Beans can have arguments (more than one create method)

Question 3 : Can Entity Beans have no create() methods?

Answer 3 : Yes. In some cases the data is inserted NOT using Java application, so you may only need to retrieve the information, perform its processing, but not create your own information of this kind.

Question 4 : Can I invoke Runtime.gc() in an EJB?

Answer 4 : You shouldn’t. What will happen depends on the implementation, but the call will most likely be ignored.

Question 5 : Can i map more than one table in a CMP?

Answer 5 : No, you cannot map more than one table to a single CMP Entity Bean. CMP has been, in fact, designed to map a single table.

Question 6 : Can the primary key in the entity bean be a Java primitive type such as int?

Answer 6 : The primary key can’t be a primitive type–use the primitive wrapper classes, instead. For example, you can use java.lang.Integer as the primary key class, but not int (it has to be a class, not a primitive)

Question 7 : Does stateless Session bean create() method contain any parameters?

Answer 7 : Stateless SessionBean create() method doesnot contain any parameters and the syntax is as follows: public interface XSessionEJBHome extends EJBHome { XSessionEJB create() throws RemoteException, CreateException; }

Question 8 : How can I access EJB from ASP?

Answer 8 : We can use the Java 2 Platform, Enterprise Edition Client Access Services (J2EETM CAS) COM Bridge 1.0, currently downloadable from Sun

Question 9 : How can I call one EJB from inside of another EJB?

Answer 9 : EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance reference, and so forth.

Question 10 : How does a servlet communicate with a JSP page?

Answer 10 : The following code snippet shows how a servlet instantiates a bean and initializes it with FORM data posted by a browser. The bean is then placed into the request, and the call is then forwarded to the JSP page, Bean1.jsp, by means of a request dispatcher for downstream processing.

EJB Contributors


Share your email for latest updates


Our partners