JavaBeat FAQs
Sponsors
JAVABEAT
Home
Articles
Tips
QnA
Forums
FAQs Topics Books Topic
Java Java Books
Struts Struts Books
Spring Spring Books
Hibernate Hibernate Books
JBoss Seam Seam Books
J2EE J2EE Books
EJB EJB Books
JSF JSF Books
Servlets Servlets Books
JDBC JDBC Books
RMI RMI Books
JMS JMS Books
JNI JNI Books
Design Patterns Patterns Books
Exception Exception Books
Apache Ant Ant Books
Groovy
Cobertura
Quartz

Enterprise Java Beans(EJB) Interview Questions

EJB FAQs - 1 | EJB FAQs - 2 | EJB FAQs - 3 | EJB FAQs - 4 | EJB FAQs - 5 | EJB FAQs - 6 | EJB FAQs - 7 | EJB FAQs - 8 | EJB FAQs - 9 | EJB FAQs - 10 | EJB FAQs - 11 | EJB FAQs - 12

31) Can beans use stored procedures in a database?
 

Stored procedures can be used by session beans that access the database using JDBC and bean-managed entity beans that use JDBC to manage their own persistence. JDBC provides a call interface for using stored procedures. An example is provided below:

InitialContext cntx = new InitialContext( );
DataSource dataSource = (DataSource) cntx.lookup("java:comp/env/jdbc/mydatabase");
Connection con = dataSource.getConnection( );

CallableStatement storedProcedure = con.prepareCall("{? = call someprocedure [(?,?)]}");

32) Is method overloading allowed in EJB?
 

Yes you can overload methods.

33) How can JMS be used from EJB 1.1?
 

The same as any client would use JMS. At this point there is no integration, but it is planned for a future release of the EJB spec.

34) Can primary keys contain more than one field?
 

Yes, a primary key can have as many fields as the developer feels is necessary, just make sure that each field you specify as the primary key, you also specify a matching field in the bean class. A primary key is simply one or more attributes which uniquely identify a specific element in a database. Also, remember to account for all fields in the equals() and hashCode() methods.

35) How does Container Managed Persistence work with automatically generated database ID fields? Should I map the ID field explicitly or leave it unspecified?
 

In the Deployment Descriptor, map the normal fields appropriately, but don't specify the auto-id field as one of the container managed fields.

36) Let's assume I use a JavaBean as a go-between a JSP and an EJB, and have, say, 50 concurrent clients that need to access the EJB functionality. Will the JSP container actually instantiate 50 instances of the bean, or can it reuse a single instance to access the EJB?
 

It depends on the scope you associate with the JavaBean. If you assign the bean with page (which is the default) scope or request scope, a new bean will be instantiated for each incoming request.

If you assign the bean with session scope, you will still have 50 instances loaded in memory (assuming each incoming request is triggered by a distinct client), although some may have been instantiated from an earlier request from the same client. However, you may not want to use the session scope for a high-volume site as these beans will continue to reside in memory, long after the request has been serviced, consuming valuable resources until they are invalidated either explicitly or due to a session timeout.

You can also assign the bean with application scope, in which case it is instantiated just once before being placed into the servlet context of the container. It can then be accessed at a later time, as long as the server is up and running. Although this may sound like an attractive proposition, do note that you will have to contend with significant multithreading issues. For instance, you'll have to ensure that the bean is accessed in a thread-safe manner from each of the JSP files. While you can do this using explicit synchronization from within the JSP file, do note that your application may take a significant performance hit because of this - especially if you expect tens or hundreds of concurrent clients accessing your pages.

So, in short, your best bet may be to assign the bean with request scope.

37) What happens when two users access an Entity Bean concurrently?
 

Taken from Enterprise JavaBeans by Richard Monson-Haefel, "EJB, by default, prohibits concurrent access to bean instances. In other words, several clients can be connected to one EJB object, but only one client thread can access the bean instance at a time. If, for example, one of the clients invokes a method on the EJB object, no other client can access that bean instance until the method invocation is complete."

So, to answer your question, two users will never access an Entity Bean concurrently.

38) What's the reason for having two interfaces -- EJBHome for creating, finding & removing and EJBObject for implementing business methods. Why not have an single interface which supports both areas of functionality?
 

This design reflects the common "Factory" Design pattern. The EJBHome interface is the Factory that creates EJBObjects. EJBObject instances are the product of the factory. The reason for having two interfaces is because they are both responsible for different tasks. The EJBHome is responsible for creating and finding EJBObjects, whilst the EJBObject is responsible for the functionality of the EJB.

39) Which fields in beans should be public?
 

All Container Managed Fields in an Entity Bean must be public.

Ejb 1.1 spec section 9.4.1 - "The fields must be defined in the entity bean class as public, and must not be defined as transient."

40) How do you implement callbacks in EJB?
 

If your client is an EJB, it can pass a reference to itself to the method of the bean that it is calling. The EJB can then call methods directly on that interface.

If your client is a Java client, your client requires some sort of object that will "listen" for call-backs. This could be either a CORBA or RMI object. Again, you could pass references to these objects to the EJB, which could then invoke methods on the references.

Bookmark This Page : | | | | | | | | | | |
Related Articles
Liferay Portal Enterprise Intranets
ZK Developer’s Guide : Online Media Library
The BIRT Environment and Your First Report
AJAX - The Complete Reference
The Java 6.0 Compiler API
Spring Web Flow - Introduction
Introduction to Spring Web Framework
Integrating Struts With Spring
What's new in Struts 2.0? - Struts 2.0 Framework
Introductiion to Jakarta Struts
more articles
java6 ejb3 jsf hibernate eclipse ajax groovy spring seam java struts webservice j2me guice java5 jca tapestry soa linux ria

Sponsors
Webmaster Hosting Forum
Java Jobs
Latest in DLinks
http://javawave.blogspot.com/2008/04/quartz-job-scheduler-part-ii-example.html
Quartz Job Scheduler -- Part 1 (Setting up development project in Netbeans 6.1 beta)
Flex Messaging with BEA Workshop Studio
SOA and Virtualization: How do They Fit Together?
Introduction to Enterprise Portals - Why they Benefit IT and the Business
BEA WebLogic Operations Control: Application Virtualization for Enterprise Java
Best Practices for Building Production Quality EAR Files
BEA's SOA Reference Architecture - A Foundation for Business Agility
Blueprint for Successful SOA Integration
Guardian - What a tool!

JavaBeat Media (2004-2008), India
javabeat home | About Us
our network : opensource softwares
Copyright © 2007 JavaBeat