Vous êtes sur la page 1sur 6

www.sbabamca.wordpress.

com
EJB INTERVIEW QUESTIONS AND ANSWERS
1) Wha are E!erpr"se Ja#a Bea!s$
Enterprise Java Beans (EJB) is a specification which defines a component architecture for
developing distributed systems. Applications written using the Enterprise JavaBeans
architecture are resusable,scalable, transactional, and secure. Enterprise Java Bean's allow
the developer to only focus on implementing the business logic of the application.
%) &ow ma!' 'pes o( E!erpr"se bea!s are here a!d wha are he'$
here are ! types EJB's and they are"
#. Entity Bean's
$. %ession Bean's
!. &essage 'riven Bean's(&'B's)
)) &ow ma!' 'pes o( E!"' bea!s are here a!d wha are he'$
here are $ types Entity bean's and they are"
#. (ontainer &anaged )ersistence((&)) Entity Bean's
$. Bean &anaged )ersistence(B&)) Entity Bean's
*) &ow ma!' 'pes o( Sess"o! bea!s are here a!d wha are he'$
here are $ types %ession bean's and they are"
#. %tatefull %ession Bean's
$. %tateless %ession Bean's
+) &ow ma!' 'pes o( ,DB-s are here a!d wha are he'$
here are no different *inds of &essage driven beans.
.) &ow "s a e!erpr"se bea! d"((ere! (rom a /a#a bea!$
Both the enterprise bean and the +ava bean are designed to be highly reusable. But other
than being reusable there is no similarity between them. Java bean is mostly a simple
client,side component whereas enterprise bean is a comple- server side component.
0) &ow ma!' /a#a ("1es sho21d a de#e1oper code o de#e1op a sess"o! bea!$
! +ava files has to be provided by the developer. hey are"
#) an .ome /nterface
$) a 0emote /nterface
!) And a %ession Bean implementation class.
3) E4p1a"! he ro1e o( &ome I!er(ace.
.ome interface contains factory methods for locating, creating and removing instances of
EJB's.
5) E4p1a"! he ro1e o( Remoe I!er(ace.
0emote interface defines the business methods callable by a client. All methods defined
in the remote interface must throw 0emoteE-ception.
16) Wha "s he !eed (or a separae &ome "!er(ace a!d Remoe I!er(ace. 7a!-
www.sbabamca.wordpress.com
www.sbabamca.wordpress.com
he' be de("!ed "! o!e "!er(ace$
EJB doesn't allow the client to directly communicate with an enterprise bean. he client
has to use home and remote interfaces for any communication with the bean.
he .ome /nterface is for communicating with the container for bean's life cycle
operations li*e creating, locating,removing one or more beans. 1hile the remote interface
is used for remotely accessing the business methods.
11) Wha are ca11bac8 mehods$
(allbac* methods are bean's methods, which are called by the container. hese are called
to notify the bean, of it's life cycle events.
1.) &ow w"11 'o2 ma8e a sess"o! bea! as sae(21 or sae1ess$
1e have to specify the it in the deployment descriptor(e+b,+ar.-ml) using 2session,type3
tag.
1%) Wha "s mea! b' Ac"#a"o!$
he process of transferring an enterprise bean from secondary storage to memory.
1)) Wha "s mea! b' 9ass"#a"o!$
he process of transferring an enterprise bean from memory to secondary storage.
1*) Wha "s a re:e!ra! E!"' Bea!$
An re,entrant Entity Bean is one that can handle multiple simultaneous, interleaved, or
nested invocations which will not interfere with each other.
1+) Wh' are e/bAc"#ae;) a!d e/b9ass"#ae;) "!c12ded (or sae1ess sess"o! bea!
e#e! ho2<h he' are !e#er re=2"red as " "s a !o!co!#ersa"o!a1 bea!$
o have a consistent interface, so that there is no different interface that you need to
implement for %tateful %ession Bean and %tateless %ession Bean. Both %tateless and
%tateful %ession Bean implement +ava-.e+b.%essionBean and this would not be possible if
stateless session bean is to remove e+bActivate and e+b)assivate from the interface.
10) Wha "s a! EJB7o!e4$
EJB(onte-t is an ob+ect that allows an enterprise bean to invo*e services provided by the
container and to obtain the information about the caller of a client,invo*ed method.
13) E4p1a"! he ro1e o( EJB 7o!a"!er$
EJB (ontainer implements the EJB component contract of the J$EE architecture. /t
provides a runtime environment for enterprise beans that includes security, concurrency,
life cycle management, transactions, deployment, naming, and other services. An EJB
(ontainer is provided by an EJB %erver.
15) Wha are E!"' Bea!-s$
Entity Bean is an enterprise bean that represents persistent data maintained in a database.
An entity bean can manage its own persistence or can delegate this function to its
container. An entity bean is identified by a primary *ey. /f the container in which an
www.sbabamca.wordpress.com
www.sbabamca.wordpress.com
entity bean is hosted crashes, the entity bean, its primary *ey, and any remote references
survive the crash.
.6) Wha "s a 9r"mar' >e'$
)rimary 4ey is an ob+ect that uni5uely identifies an entity bean within a home.
.6) 7a! we spec"(' pr"m""#e daa 'pe be as a pr"mar' 8e'$
)rimitive data type cannot be directly used as primary *ey, it should be wrapped using a
wrapper class.
.1) Wha "s a Dep1o'me! Descr"por$
'eployment 'escriptor is a 6&7 file provided with each module and application that
describes how they should be deployed. he deployment descriptor directs a deployment
tool to deploy a module or application with specific container options and describes
specific configuration re5uirements that a deployer must resolve.
..) Wha are he !ew (ea2res ha were "!rod2ced "! EJB #ers"o! ..6
spec"("ca"o!$
1. New 7,9 ,ode1. /t is based on a new contract called the abstract persistence schema,
that will allow to the container to handle the persistence automatically at runtime.
.. EJB Q2er' ?a!<2a<e. /t is a s5l,based language that will allow the new persistence
schema to implement and e-ecute finder methods.
%. ,essa<e Dr"#e! Bea!s. /t is a new bean type, that is introduced to handle
asynchronous messaging.
). ?oca1 "!er(aces. Enabales beans in the same EJB (ontainer to communicate directly.
*. e/b&ome mehods. Entity beans can declare e+b.ome methods that perform
operations related to the EJB component but that are not specific to a bean instance.
.%) Wha are he d"((ere!ce-s bewee! a ?oca1 I!er(ace a!d a Remoe I!er(ace$
7ocal /nterfaces are new mechanism introduced in EJB $.8 specification which enables
components in the same container to bypass 0&/ and call each other's methods directly.
/n general, direct local method calls are faster than remote method calls. he downside is
a loss of fle-ibility" because bean and client must run in the same container, the location
of the bean is not transparent to the client (as it is with remote interfaces). remote
interfaces pass parameters by value, while local interfaces pass them by reference.
.)) 7a! a bea! be de("!ed boh as a ?oca1 a!d a Remoe$
9es.
.*) Wha are e/b&ome mehods or &ome B2s"!ess ,ehods$
EJB $.8 allows entity beans to declare e+b.ome methods in the home interface. hese
methods perform operations that are not specific to a particular bean instance.
.+) Wha "s a ra!sac"o!$
A transaction is a se5uence of operations that must all complete successfully, or leave
system in the state it had been before the transaction started.
www.sbabamca.wordpress.com
www.sbabamca.wordpress.com
.0) Wha do mea! b' A7ID proper"es o( a ra!sac"o!$
A(/' is the acronym for the four properties guaranteed by transactions" atomicity,
consistency, isolation, and durability.
.3) Where w"11 'o2 me!"o! wheher he ra!sac"o! "s co!a"!er ma!a<ed or bea!
ma!a<ed$
ransaction management is specified in the deployment descriptor(e+b,+ar.-ml) using
2transaction,type3 tag.
.5) Wha are co!a"!er ma!a<ed ra!sac"o!s$
/n an enterprise bean with container,managed transactions, the EJB container sets the
boundaries of the transactions. 9ou can use container,managed transactions with any
type of enterprise bean" session, entity, or message,driven. (ontainer,managed
transactions simplify development because the enterprise bean code does not e-plicitly
mar* the transaction's boundaries. he code does not include statements that begin and
end the transaction.
%6) Wha mehods are resr"ced be"!< ca11ed "!s"de a mehod deca1red as co!a"!er
ma!a<ed$
1e should not invo*e any method that might interfere with the transaction boundaries set
by the container. he list of restricted methods are as follows"
#) he commit, setAuto(ommit, and rollbac* methods of +ava.s5l.(onnection
$) he get:serransaction method of +ava-.e+b.EJB(onte-t
!) Any method of +ava-.transaction.:serransaction
%1) Wha are bea! ma!a<ed ra!sac"o!s$
;or bean,managed transactions, the bean specifies transaction demarcations using
methods in the +ava-.transaction.:serransaction interface. Bean,managed transactions
include any stateful or stateless session beans with a transaction,type set to Bean. Entity
beans cannot use bean,managed transactions.
;or stateless session beans, the entering and e-iting transaction conte-ts must match. ;or
stateful session beans, the entering and e-iting transaction conte-ts may or may not
match. /f they do not match, EJB container maintains associations between the bean and
the nonterminated transaction.
%ession beans with bean,managed transactions cannot use the set0ollbac*<nly and
get0ollbac*<nly methods of the +ava-.e+b.EJB(onte-t interface.
%.) Wha "s he d"((ere!ce bewee! co!a"!er ma!a<ed a!d bea! ma!a<ed
ra!sac"o!$
/n container,managed transaction, the transaction boundaries are defined by the container
while in bean managed transaction, the transaction boundaries are defined by the bean.
Entity Beans transactions are always container managed.
www.sbabamca.wordpress.com
www.sbabamca.wordpress.com
%.) Wh' e!"' bea!-s ra!sac"o! ca!- be ma!a<ed b' he bea!$
Entity bean's represent the data and responsible for the integrity of the data. Entity bean's
doesn't represent business operations to manage transactions. %o there is no re5uirement
for an entity bean managing it's transaction.
%%) &ow ma!' 'pes o( ra!sac"o! ar"b2es are a#a"1ab1e "! EJB a!d wha are
he'$
here = types of ransaction Atributes defined in EJB. hey are as follows"
1. NoS2ppored @ /f the method is called within a transaction, this transaction is
suspended during the time of the method e-ecution.
.. Re=2"red @ /f the method is called within a transaction, the method is e-ecuted in the
scope of this transaction> otherwise, a new transaction is started for the e-ecution of the
method and committed before the method result is sent to the caller.
%. Re=2"resNew @ he method will always be e-ecuted within the scope of a new
transaction. he new transaction is started for the e-ecution of the method, and
committed before the method result is sent to the caller. /f the method is called within a
transaction, this transaction is suspended before the new one is started and resumed when
the new transaction has completed.
). ,a!daor'@ he method should always be called within the scope of a transaction,
else the container will throw the ransaction0e5uired e-ception.
*. S2ppors @ he method is invo*ed within the caller transaction scope> if the caller does
not have an associated transaction, the method is invo*ed without a transaction scope.
+. Ne#er @ he client is re5uired to call the bean without any transaction conte-t> if it is
not the case, a +ava.rmi.0emoteE-ception is thrown by the container.
%)) &ow ma!' 'pes o( Iso1a"o! ?e#e1-s are a#a"1ab1e "! EJB a!d wha are he'$
%*) Are we a11owed o cha!<e he ra!sac"o! "so1a"o! proper' "! m"dd1e o( a
ra!sac"o!$
?o. 9ou cannot change the transaction isolation level in the middle of transaction.
%+) Are e!erpr"se bea!s a11owed o 2se Thread.s1eep;)$
Enterprise beans are restricted from invo*ing multithreading thread functionality.
%0) 7a! a bea! be aached o more ha! o!e JNDI !ame$
9es. A same bean can be deployed multiple times in the same server with different J?'/
names.
%3) 7a! a c1"e! pro<ram d"rec1' access a! E!erpr"se bea!$
?o. EJB (lients never access an EJB directly. he container insulates the beans from
direct access from client applications. Every time a bean is re5uested, created, or deleted,
the container manages the whole process.
%5) Whe! "s a! app1"ca"o! sa"d o be d"sr"b2ed$
An application is distributed when its components are running in separate runtime
www.sbabamca.wordpress.com
www.sbabamca.wordpress.com
environments(J@&'s), usually on different platforms connected via a networ*.
'istributed applications are usually of ! types. hey are "
#. two tier (client and a server)
$.three tier (client and a middleware and a server)
!. multitier (client and multiple middleware and multiple servers).
)6) Wha "s a! EAR ("1e$
EA0 is Enterprise Archive file. A archive file that contains a J$EE application.
)1) Wha do mea! b' b2s"!ess mehod$
A method of an enterprise bean that implements the business logic or rules of an
application.
).) Wha "s a ("!der mehod$
A method defined in the home interface and invo*ed by a client to locate an entity bean.
www.sbabamca.wordpress.com

Vous aimerez peut-être aussi