Sunteți pe pagina 1din 9

Search Tech Interviews

ew
n
ervT
iItsech Search
Prepare for job interviews with the questions and answers asked by high-tech employers

.NET C++ Da ta ba se G e ne ra l Ha rdwa re Ja va Ne two rking Puz z le s SAP ABAP Te sting Unix/Linux VB We b de v Windo ws

Java > > EJB inte rvie w que s tions

EJB interview questions


By admin | O c to be r 10 , 20 0 4

1. Is is pos s ible for an EJB clie nt to mars hal an obje ct of clas s java.lang.Clas s to an EJB? -
Technically yes , s pec. compliant NO ! - The enterpris e bean mus t not attempt to query a clas s to
obtain information about the declared members that are not otherwis e acces s ible to the enterpris e
bean becaus e of the s ecurity rules of the Java language.
2. Is it le gal to have s tatic initializ e r blocks in EJB? - Although technically it is legal, s tatic
initializ er blocks are us ed to execute s ome piece of code before executing any cons tructor or
method while ins tantiating a clas s . Static initializ er blocks are als o typically us ed to initializ e s tatic
fields - which may be illegal in EJB if they are read/write - In EJB this can be achieved by including
the code in either the ejbCreate(), s etSes s ionContext() or s etEntityContext() methods .

3. Is it pos s ible to s top the e xe cution of a me thod be fore comple tion in a S e s s ionBe an? -
Stopping the execution of a method ins ide a Ses s ion Bean is not pos s ible without writing code Ads by G o o g le
ins ide the Ses s ion Bean. This is becaus e you are not allowed to acces s Threads ins ide an EJB.
4. What is the de fault trans action attribute for an EJB? - There is no default trans action Free C# c ode g enerator
attribute for an EJB. Section 11.5 of EJB v1.1 s pec s ays that the deployer mus t s pecify a value for C re ate database & re po rting apps straig ht fro m yo ur
the trans action attribute for thos e methods having container managed trans action. In WebLogic, database ! T ry it
PDFmyURL.com
the default trans action attribute for EJB is SUPPO RTS. www.iro ns peed.co m
5. What is the diffe re nce be twe e n s e s s ion and e ntity be ans ? Whe n s hould I us e one or the
othe r? - An entity bean repres ents pers is tent global data from the databas e; a s es s ion bean Software Eng ineers Needed
repres ents trans ient us er-s pecific data that will die when the us er dis connects (ends his s es s ion). Wo rk fo r the le ade r in e ducatio nal te chno lo g y. Make
Generally, the s es s ion beans implement bus ines s methods (e.g. Bank.trans ferFunds ) that call a diffe re nce !
entity beans (e.g. Account.depos it, Account.withdraw) www.IXL .co m/Jo bs
6. Is the re any de fault cache manage me nt s ys te m with Entity be ans ? In othe r words
whe the r a cache of the data in databas e will be maintaine d in EJB ? - Caching data from a Merg ers & Ac quisitions
databas e ins ide the Application Server are what Entity EJB’s are us ed for.The ejbLoad() and 1# On-De mand. 17849 +Wo rld C lie nts! Fre e Guide Or
ejbStore() methods are us ed to s ynchroniz e the Entity Bean s tate with the pers is tent Visit Us Online No w.
s torage(databas e). Trans actions als o play an important role in this s cenario. If data is removed www.DataSiteDeal.co m/M&A
from the databas e, via an external application - your Entity Bean can s till be “alive” the EJB
container. When the trans action commits , ejbStore() is called and the row will not be found, and
the trans action rolled back.
Job Interview Question Articles
7. Why is e jbFindByPrimaryKe y mandatory? - An Entity Bean repres ents pers is tent data that is
C# Interview Q ues tions and Ans wers
s tored outs ide of the EJB Container/Server. The ejbFindByPrimaryKey is a method us ed to locate
Q TP Interview Q ues tions and Ans wers
and load an Entity Bean into the container, s imilar to a SELECT s tatement in SQ L. By making this
C++ Interview Q ues tions and Ans wers
method mandatory, the client programmer can be as s ured that if they have the primary key of the
PHP Interview Q ues tions and Ans wers
Entity Bean, then they can retrieve the bean without having to create a new bean each time - which
XML Interview Q ues tions and Ans wers
would mean creating duplications of pers is tent data and break the integrity of EJB.
JavaScript Interview Q ues tions and Ans wers
8. Why do we have a re move me thod in both EJBHome and EJBObje ct? - With the EJBHome
As p.Net Interview Q ues tions and Ans wers
vers ion of the remove, you are able to delete an entity bean without firs t ins tantiating it (you can
J2EE Interview Q ues tions and Ans wers
provide a PrimaryKey object as a parameter to the remove method). The home vers ion only works
ABAP Interview Q ues tions and Ans wers
for entity beans . O n the other hand, the Remote interface vers ion works on an entity bean that you
Perl Interview Q ues tions and Ans wers
have already ins tantiated. In addition, the remote vers ion als o works on s es s ion beans (s tateles s
Java Interview Q ues tions and Ans wers
and s tateful) to inform the container of your los s of interes t in this bean.
9. How can I call one EJB from ins ide of anothe r EJB? - EJBs can be clients of other EJBs . It
jus t works . Us e JNDI to locate the Home Interface of the other bean, then acquire an ins tance
Resources
reference, and s o forth.
Technology Q ues tion and Ans wer Webs ite
10. What is the diffe re nce be twe e n a S e rve r, a Containe r, and a Conne ctor? - An EJB s erver
How to dance around the s alary-expectation ques tion
is an application, us ually a product s uch as BEA WebLogic, that provides (or s hould provide) for
10 mis takes managers make during job interviews
concurrent client connections and manages s ys tem res ources s uch as threads , proces s es ,
ID Maker
memory, databas e connections , network connections , etc. An EJB container runs ins ide (or within)
Stupid interview ques tions
an EJB s erver, and provides deployed EJB beans with trans action and s ecurity management, etc.
How to Ans wer Thes e Tricky Interview Q ues tions
The EJB container ins ulates an EJB bean from the s pecifics of an underlying EJB s erver by
Seven tips for writing an online profile for LinkedIn,
providing a s imple, s tandard API between the EJB bean and its container. A Connector provides
MySpace or Facebook
the ability for any Enterpris e Information Sys tem (EIS) to plug into any EJB s erver which s upports
Video s urveillance
the Connector architecture. See Sun’s J2EE Connectors for more in-depth information on
Ink cartridges
Connectors .
PDFmyURL.com
Connectors .
Laptop computers
11. How is pe rs is te nce imple me nte d in e nte rpris e be ans ? - Pers is tence in EJB is taken care of
Affordable life ins urance
in two ways , depending on how you implement your beans : container managed pers is tence
Ink cartridges
(CMP) or bean managed pers is tence (BMP) For CMP, the EJB container which your beans run
under takes care of the pers is tence of the fields you have declared to be pers is ted with the
databas e - this declaration is in the deployment des criptor. So, anytime you modify a field in a
Tutorials
CMP bean, as s oon as the method you have executed is finis hed, the new data is pers is ted to the
AJAX Tutorials
databas e by the container. For BMP, the EJB bean developer is res pons ible for defining the
Dealing with your job
pers is tence routines in the proper places in the bean, for ins tance, the ejbCreate(), ejbStore(),
Getting a job
ejbRemove() methods would be developed by the bean developer to make calls to the databas e.
JavaScript tutorials
The container is res pons ible, in BMP, to call the appropriate method on the bean. So, if the bean
Job interview tips from Yahoo! HotJobs
is being looked up, when the create() method is called on the Home interface, then the container is
MySQ L tutorials
res pons ible for calling the ejbCreate() method in the bean, which s hould have functionality ins ide
Retiring from your job
for going to the databas e and looking up the data.
Ruby on Rails tutorials
12. What is an EJB Conte xt? - EJBContext is an interface that is implemented by the container, and
Salary guide for IT jobs
it is als o a part of the bean-container contract. Entity beans us e a s ubclas s of EJBContext called
Self-employment
EntityContext. Ses s ion beans us e a s ubclas s called Ses s ionContext. Thes e EJBContext objects
TechInterviews guides in PDF
provide the bean clas s with information about its container, the client us ing the bean and the bean
Unders tanding pointers
its elf. They als o provide other functions . See the API docs and the s pec for more details .
XML Tutorials
13. Is me thod ove rloading allowe d in EJB? - Yes you can overload methods
XUL tutorials
14. S hould s ynchroniz ation primitive s be us e d on be an me thods ? - No. The EJB s pecification
s pecifically s tates that the enterpris e bean is not allowed to us e thread primitives . The container is
res pons ible for managing concurrent acces s to beans at runtime.
RSS Feeds
15. Are we allowe d to change the trans action is olation prope rty in middle of a trans action?
All pos ts
- No. You cannot change the trans action is olation level in the middle of trans action.
All comments
16. For Entity Be ans , What happe ns to an ins tance fie ld not mappe d to any pe rs is te nt
s torage , whe n the be an is pas s ivate d? - The s pecification infers that the container never
s erializ es an ins tance of an Entity bean (unlike s tateful s es s ion beans ). Thus pas s ivation s imply
involves moving the bean from the “ready” to the “pooled” bin. So what happens to the contents
of an ins tance variable is controlled by the programmer. Remember that when an entity bean is
pas s ivated the ins tance gets logically dis as s ociated from it’s remote object. Be careful here, as the
functionality of pas s ivation/activation for Stateles s Ses s ion, Stateful Ses s ion and Entity beans is
completely different. For entity beans the ejbPas s ivate method notifies the entity bean that it is
being dis as s ociated with a particular entity prior to reus e or for dereference.
17. What is a Me s s age Drive n Be an, what functions doe s a me s s age drive n be an have and
how do the y work in collaboration with JMS ? - Mes s age driven beans are the lates t addition
to the family of component bean types defined by the EJB s pecification. The original bean types
include s es s ion beans , which contain bus ines s logic and maintain a s tate as s ociated with client
s es s ions , and entity beans , which map objects to pers is tent data. Mes s age driven beans will

PDFmyURL.com
provide as ynchrony to EJB bas ed applications by acting as JMS mes s age cons umers . A mes s age
bean is as s ociated with a JMS topic or queue and receives JMS mes s ages s ent by EJB clients or
other beans . Unlike entity beans and s es s ion beans , mes s age beans do not have home or remote
interfaces . Ins tead, mes s age driven beans are ins tantiated by the container as required. Like
s tateles s s es s ion beans , mes s age beans maintain no client-s pecific s tate, allowing the container
to optimally manage a pool of mes s age-bean ins tances . Clients s end JMS mes s ages to mes s age
beans in exactly the s ame manner as they would s end mes s ages to any other JMS des tination.
This s imilarity is a fundamental des ign goal of the JMS capabilities of the new s pecification. To
receive JMS mes s ages , mes s age driven beans implement the javax.jms .Mes s ageLis tener
interface, which defines a s ingle “onMes s age()” method. When a mes s age arrives , the container
ens ures that a mes s age bean corres ponding to the mes s age topic/queue exis ts (ins tantiating it if
neces s ary), and calls its onMes s age method pas s ing the client’s mes s age as the s ingle argument.
The mes s age bean’s implementation of this method contains the bus ines s logic required to
proces s the mes s age. Note that s es s ion beans and entity beans are not allowed to function as
mes s age beans .
18. Doe s RMI-IIOP s upport code downloading for Java obje cts s e nt by value acros s an IIOP
conne ction in the s ame way as RMI doe s acros s a JRMP conne ction? - Yes . The JDK 1.2
s upport the dynamic clas s loading.
19. The EJB containe r imple me nts the EJBHome and EJBObje ct clas s e s . For e ve ry re que s t
from a unique clie nt, doe s the containe r cre ate a s e parate ins tance of the ge ne rate d
EJBHome and EJBObje ct clas s e s ? - The EJB container maintains an ins tance pool. The
container us es thes e ins tances for the EJB Home reference irres pective of the client reques t. while
refering the EJB O bject clas s es the container creates a s eparate ins tance for each client reques t.
The ins tance pool maintainence is up to the implementation of the container. If the container
provides one, it is available otherwis e it is not mandatory for the provider to implement it. Having
s aid that, yes mos t of the container providers implement the pooling functionality to increas e the
performance of the application s erver. The way it is implemented is again up to the implementer.
20. What is the advantage of putting an Entity Be an ins tance from the “Re ady S tate ” to
“Poole d s tate ”? - The idea of the “Pooled State” is to allow a container to maintain a pool of
entity beans that has been created, but has not been yet “s ynchroniz ed” or as s igned to an
EJBO bject. This mean that the ins tances do repres ent entity beans , but they can be us ed only for
s erving Home methods (create or findBy), s ince thos e methods do not relay on the s pecific values
of the bean. All thes e ins tances are, in fact, exactly the s ame, s o, they do not have meaningful
s tate. Jon Thorarins s on has als o added: It can be looked at it this way: If no client is us ing an
entity bean of a particular type there is no need for cachig it (the data is pers is ted in the databas e).
Therefore, in s uch cas es , the container will, after s ome time, move the entity bean from the
“Ready State” to the “Pooled s tate” to s ave memory. Then, to s ave additional memory, the
container may begin moving entity beans from the “Pooled State” to the “Does Not Exis t State”,
becaus e even though the bean’s cache has been cleared, the bean s till takes up s ome memory jus t
PDFmyURL.com
being in the “Pooled State”.
21. Can a S e s s ion Be an be de fine d without e jbCre ate () me thod? - The ejbCreate() methods is
part of the bean’s lifecycle, s o, the compiler will not return an error becaus e there is no
ejbCreate() method. However, the J2EE s pec is explicit: the home interface of a Stateles s Ses s ion
Bean mus t have a s ingle create() method with no arguments , while the s es s ion bean clas s mus t
contain exactly one ejbCreate() method, als o without arguments . Stateful Ses s ion Beans can have
arguments (more than one create method) s tateful beans can contain multiple ejbCreate() as long
as they match with the home interface definition. You need a reference to your EJBO bject to
s tartwith. For that Sun ins is ts on putting a method for creating that reference (create method in the
home interface). The EJBO bject does matter here. Not the actual bean.
22. Is it pos s ible to s hare an HttpS e s s ion be twe e n a JS P and EJB? What happe ns whe n I
change a value in the HttpS e s s ion from ins ide an EJB? - You can pas s the HttpSes s ion as
parameter to an EJB method, only if all objects in s es s ion are s erializ able.This has to be cons ider
as “pas s ed-by-value”, that means that it’s read-only in the EJB. If anything is altered from ins ide
the EJB, it won’t be reflected back to the HttpSes s ion of the Servlet Container.The “pas s -by-
reference” can be us ed between EJBs Remote Interfaces , as they are remote references . While it IS
pos s ible to pas s an HttpSes s ion as a parameter to an EJB object, it is cons idered to be “bad
practice (1)” in terms of object oriented des ign. This is becaus e you are creating an unneces s ary
coupling between back-end objects (ejbs ) and front-end objects (HttpSes s ion). Create a higher-
level of abs traction for your ejb’s api. Rather than pas s ing the whole, fat, HttpSes s ion (which
carries with it a bunch of http s emantics ), create a clas s that acts as a value object (or s tructure)
that holds all the data you need to pas s back and forth between front-end/back-end. Cons ider the
cas e where your ejb needs to s upport a non-http-bas ed client. This higher level of abs traction will
be flexible enough to s upport it. (1) Core J2EE des ign patterns (2001)
23. Is the re any way to re ad value s from an e ntity be an without locking it for the re s t of the
trans action (e .g. re ad-only trans actions )? We have a ke y-value map be an which
de adlocks during s ome concurre nt re ads . Is olation le ve ls s e e m to affe ct the databas e
only, and we ne e d to work within a trans action. - The only thing that comes to (my) mind is
that you could write a ‘group acces s or’ - a method that returns a s ingle object containing all of
your entity bean’s attributes (or all interes ting attributes ). This method could then be placed in a
‘Requires New’ trans action. This way, the current trans action would be s us pended for the duration
of the call to the entity bean and the entity bean’s fetch/operate/commit cycle will be in a s eparate
trans action and any locks s hould be releas ed immediately. Depending on the granularity of what
you need to pull out of the map, the group acces s or might be overkill.
24. What is the diffe re nce be twe e n a “Coars e Graine d” Entity Be an and a “Fine Graine d”
Entity Be an? - A ‘fine grained’ entity bean is pretty much directly mapped to one relational table,
in third normal form. A ‘coars e grained’ entity bean is larger and more complex, either becaus e its
attributes include values or lis ts from other tables , or becaus e it ‘owns ’ one or more s ets of
dependent objects . Note that the coars e grained bean might be mapped to a s ingle table or flat
PDFmyURL.com
file, but that s ingle table is going to be pretty ugly, with data copied from other tables , repeated
field groups , columns that are dependent on non-key fields , etc. Fine grained entities are generally
cons idered a liability in large s ys tems becaus e they will tend to increas e the load on s everal of the
EJB s erver’s s ubs ys tems (there will be more objects exported through the dis tribution layer, more
objects participating in trans actions , more s keletons in memory, more EJB O bjects in memory,
etc.)
25. What is EJBDocle t? - EJBDoclet is an open s ource JavaDoc doclet that generates a lot of the
EJB related s ource files from cus tom JavaDoc comments tags embedded in the EJB s ource file.

This e ntry wa s po ste d in Java. Bo o kma rk the permalink . Post a comment o r le a ve a tra c kba c k: Trackback URL.

« Good ques tions as ked during Java interview Java Web development interview ques tions »

Ads by G o o g le

J ava Code Analyzer Software Eng ineers


Ide ntify De fe cts in Yo ur Java Needed
Apps w/C o ve rity S o lutio ns - Wo rk fo r the le ade r in
Fre e T rial. e ducatio nal te chno lo g y.
www.co verity.co m/java-co de- Make a diffe re nce !
quality www.IXL .co m/Jo bs

8 C O M M E N T S O N E J B I N T E R V I E W Q U E S T I O N S

something
Po s te d 11/30 /2 0 0 4 at 5 :2 0 am | Permalink

I want to know what are the trans actions us ed when there is one to many relations hip
between two tables

PDFmyURL.com
suman
Po s te d 11/30 /2 0 0 4 at 5 :2 3 am | Permalink

what is the difference between EJBContext and Ses s ionContext objects ?

Ravi KM
Po s te d 3/14 /2 0 0 5 at 1:5 8 am | Permalink

With res pect to the ques tion rais ed by s uman, the difference between EJBContext and
Ses s ionContext objects are clearly mentioned in the ans wer to Q ues tion 12. Ses s ion
beans us e a s ubclas s of EJBContext, called Ses s ionContext.

Hope this helps ,


Ravi KM

venkat
Po s te d 3/17/2 0 0 5 at 2 :0 3 am | Permalink

how to communicate a s es s ion bean or an entity bean from a js p page

how to pos ition the jar files of s truts in an apache s erver

Randy
Po s te d 3/18 /2 0 0 5 at 12 :2 5 am | Permalink

When a value in a table changes will the value in the CMP Entity bean change as well

PDFmyURL.com
sasi
Po s te d 6 /14 /2 0 0 5 at 7:12 am | Permalink

how to connect a entity bean from a s es s ion bean?

LC
Po s te d 6 /2 9 /2 0 0 5 at 8 :35 am | Permalink

Why does the EJB architecture need Home and Remote interface? What is s ignificance of
both? Can both clas s res ide on different JVM?

Praful
Po s te d 1/2 /2 0 0 7 at 4 :4 3 am | Permalink

How to us e Ses s ionContext in EJB?

P O S T A C O M M E N T

Your email is never publis hed nor s hared. Required fields are marked *

Nam e * Em ail *

We b s ite

PDFmyURL.com
Co m m e n t

Post Comment

Po we re d by WordPress. Built o n the Thematic Theme Framework .

PDFmyURL.com

S-ar putea să vă placă și