Search your topic in Java2share
Home > SCBCD > SCBCD Question Bank
eXTReMe Tracker


3. EJB 3.0 Session Bean Component Contract & Lifecycle (SCBCD)

Q: 1 A developer implements a session bean with a method doStuff which behaves
differently depending on the caller's security role. Only users in security roles "ADMIN" and "USER"
are allowed to call the method. Assume that there is no security-related metadata in the deployment
descriptor. Which two, taken in combination, are appropriate to accomplish this? (Choose two.)

A. Annotate method doStuff with @PermitAll.
B. Annotate method doStuff with @RolesAllowed({"ADMIN","USER"})
C. If EJBContext.getCallerPrincipal returns role "ADMIN", implement the behavior for users in role ADMIN.
D. If EJBContext.isCallerInRole("ADMIN") returns true, implement the behavior defined for users in role
"ADMIN".

Answer: B, D

Q: 02 Given the following client-side code that makes use of the session bean Foo:
10. @EJB Foo bean1;
11. @EJB Foo bean2;
//more code here
20. boolean test1 = bean1.equals(bean1);
21. boolean test2 = bean1.equals(bean2);
Which two statements are true? (Choose two.)

A. If Foo is stateful, test1 is true, and test2 is true.
B. If Foo is stateful, test1 is true, and test2 is false.
C. If Foo is stateless, test1 is true, and test2 is true.
D. If Foo is stateful, test1 is false, and test2 is false.
E. If Foo is stateless, test1 is true, and test2 is false.
F. If Foo is stateless, test1 is false, and test2 is false.

Answer: B, C

Q: 03 A developer creates a stateful session bean that is used by many concurrent
clients. The clients are written by other development teams and it is assumed that these clients might not
remove the bean when ending their session. The number of concurrent sessions will be greater than the
defined bean cache size. The developer must consider that the state of the session bean can be influenced
by either passivation or timeout. Which three actions should the developer take to make the bean behave
correctly in passivation and timeout situations? (Choose three.)

A. Release references to resources in a @Remove annotated method.
B. Re-establish references to resources in an @Init annotated method.
C. Release references to resources in a @PreDestroy annotated method.
D. Release references to resources in a @PrePassivate annotated method.
E. Re-establish references to resources in a @PostActivate annotated method.

Answer: C, D, E

Q: 04 A developer writes a stateful session bean with local business interface Bar
containing method test. Method test is implemented as :
11. @Remove
12. public void test() {}
A business method in a stateless session bean invokes a reference to bean Bar as follows :
11. @EJB Bar bar;
12.
13. public void foo() {
14. bar.test();
15. bar.test();
16. }
Assuming execution reaches Line 15, what is the expected result?

A. Method foo returns without error.
B. A javax.ejb.NoSuchEJBException is thrown.
C. A java.rmi.NoSuchObjectException is thrown.
D. A javax.ejb.NoSuchEntityException is thrown.

Answer: B