1z0-895 r java certification

Upload: auddrey

Post on 01-Mar-2016

25 views

Category:

Documents


0 download

TRANSCRIPT

  • QUESTION: 1 A developer needs to deliver a large-scale enterprise application that connects developer chooses an EJB 3.1-compliant application server, which three are true about the EJB business component tier? (Choose three.)

    A. Load-balancing is NOT a guarantee for all EJB 3.1 containers. B. Clustering is guaranteed to be supported by the EJB 3.1 container. C. Thread pooling can be optimized by the Bean Provider programmatically. D. Bean Providers are NOT required to write code for transaction demarcation. E. Support for server fail-over is guaranteed for an EJB 3.1-compliant application server. F. EJB 3.1 compliant components are guaranteed to work within any Java EE 6 application server

    Answer: A, C, F

    Explanation: The EJB tier hosts the business logic of a J2EE application and provides system- level services to the business components problems include state maintenance, transaction management, and availability to local and remote clients. TheEJB 3.1specificationdoes not address "high-end" features like clustering(not B), load- balancing(A)and fail-over(not E). F: The target platformfor EJB isJava EE.

    QUESTION: 2 A developer examines a list of potential enterprise applications and selects the most appropriate technologies to use for each application. For which two applications is EJB an appropriate solution? (Choose two.)

    A. To render a GUI for mobile clients. B. As a container for web-tier components including JSP. C. As a Web service endpoint accessed by non-Java clients. D. To receive and respond to HTTP Post requests directly from a web browser. E. As an online shopping cart which can persist across multiple sessions with a single client.

    Answer: C, E

    QUESTION: 3 Which two statements are true? (Choose two.)

    A. Typically, remotely accessible objects should be coarse-grained. B. If a client accesses an enterprise bean locally such access must be mediated by the EJB

    examworx.com

  • container. C. A given enterprise bean's transaction information is immutable because it is deployed across various containers. D. If a container provides services NOT required by the EJB specification, then that container is NOT considered to be an EJB container. E. An enterprise bean's transaction Information can be accessed by external tools only if the information is contained in an XML deployment descriptor.

    Answer: B, D

    Explanation: D: An EJB container is nothing but the program that runs on the server and implements the EJB specifications. EJB container provides special type of the environment suitable for running the enterprise components. Enterprise beans are used in distributed applications that typically contains the business logic.

    QUESTION: 4 Assume you would like to receive notification from the container as a stateless session bean transitions to and from the ready state. Which of the following life cycle back annotations would you use? (Choose one.)

    A. @PostConstruct, @PostDestroy B. @PostConstruct, @PreDestroy C. @PreConstruct, @PostDestroy D. @PostConstruct, @PostDestroy, @Remove E. @PostConstruct, @PreDestroy, @Remove

    Answer: B

    Explanation: The Lifecycle of a Stateless Session Bean The EJB container typically creates and maintains a pool of stateless session beans, beginning the stateless session beans lifecycle. The container performs any dependency injection and then invokes the method annotated @PostConstruct, if it exists. The bean is now ready to have its business methods invoked by a client. At the end of the lifecycle, the EJB container calls the method annotated @PreDestroy, if it exists. The beans instance is then ready for garbage collection. Lifecycle of a Stateless Session Bean: examworx.com

  • Diagram showing the lifecycle of a stateless session bean. Note:An enterprise bean goes through various stages during its lifetime, or lifecycle. Each type of enterprise bean (stateful session, stateless session, singleton session, or message-driven) has a different lifecycle.

    Reference: http://docs.oracle.com/javaee/6/tutorial/doc/giplj.html

    QUESTION: 5 Which API must an EJB 3.1 container make available to enterprise beans at runtime? (Choose one)

    A. The JXTA 1.1 API B. The MIDP 2.0 API C. The Java SE 6 JNDI API D. The Java SE 5 JDBC API

    Answer: C, D

    QUESTION: 6 A developer wants to write a stateful session bean using the following interface as local business interface: 1. package acme; 2. public interface Bar { 3. public void bar (); 4. } Assuming there is not an ejb-jar.xml file, which code can be inserted into Lines 4-6 below to define the bean with the ejb name of BarBean? 1. package acme; 2. import javax.ejb.*; 3. import java.io.*; 4. 5. 6. 7. }

    examworx.com

  • A. @Stateful public class BarEJB implements Bar { public void bar () {} B. @Stateful (name = Bar) public class Barbean implements Bar { public void bar () {} C. @Stateful public class BarBean implements Serializable, Bar { public void bar () {} D. @Stateful (name = bar) public class BarBean implements Serializable, Bar { public void bar () throws java.rmi.RemoteException {}

    Answer: C

    QUESTION: 7 A developer creates a stateful session bean that is used by many concurrent clients. The clients are written by other development team; 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 omit annotated method. C. Release references to resources in a @preDestroy annotated method. D. Release references to resources in a SPrePassivate annotated method. E. Re-establish references to resources in a @PostActivate annotated method.

    Answer: C, D, E

    QUESTION: 8 A stateful session bean contains a number of instance variables. The types of instance variables A and B are serializable. Instance variable B is a complex type which is populated by many business calls, and can, therefore, not be refilled by the client without starting all over. A helper instance variable C is defined as having a Serializable type, and can hold all the information which is in variable B. for example, B is of type XML-DOM tree and C of Type String. Which two solutions, when combined, maintain the state of the session bean over a passivation and activation by the container? (Choose two.)

    examworx.com

  • A. The value of helper variable C is used to create the value of Instance variable B in the beans no-arg constructor. B. The value of helper variable C is used to create the value of instance variable B in a @postcreate annotated method. C. The value of helper variable C is used to create the value of instance variable B in a @postActivate annotated method. D. Instance variable A must be made null and instance variable B must be converted to a Serializable type and assigned to another instance variable in a @preDestroy annotated method. E. Instance variable A must be defined transient. Instance variable B must be converted to a Serializable type, set to null, and assigned to the instance variable C in a @PrePassivate annotated method.

    Answer: C, E

    QUESTION: 9 A developer writes a stateful session bean FooBean with one remote business interface Foo. Foo defines an integer / setter method pair implemented as: 10. private int value; 11. public void setValue (int i) {value = i; } 12. public int getValue () {return value; } A session bean ClientBean has a business method doSomething and an ejb-ref with ejb- ref-name fooRef that is mapped to FooBeans Foo interface. 11. @Resource private SessionContext SessionCtx; 12. public void doSomething () { 13. Foo foo1 = (Foo) sessionCtx.lookup("fooRef"); 14. Foo foo2 = (Foo) sessionCtx.lookup("fooRef"); 15. foo1.setvalue(1);

    Which statement is true after the code at line 15 completes?

    A. Foo1.getValue () = = 0 and foo2.getValue() = = 0 B. Foo1.getValue () = = 0 and foo2.getValue() = = 1 C. Foo1.getValue () = = 1 and foo2.getValue() = = 0 D. Foo1.getValue () = = 1 and foo2.getValue() = = 1

    Answer: D

    Explanation: Foo1 and Foo2 references the same object.

    QUESTION: 10

    examworx.com

  • A developer writes a stateless session bean FooBean with one remote business interface FooRemote containing one business method foo. Method foo takes a single parameter of application-defined type MyData. 11. public class MyData implements java.io.Serialization { 12. int a; 13. } Methods foo is implemented with the FooBean class as: 11. public void foo (MyData data) { 12. data.a = 2; 13. } Another session bean within the same application has a reference to FooRemote in variable fooRef and calls method foo with the following code: 11. MyData data = new MyData(); 12. data.a = 1; 13. Fooref.foo(data); 14. System.out.printIn(data.a); What is the value of data.a when control reaches Line 14 of the client?

    A. 0 B. 1 C. 2

    Answer: B

    QUESTION: 11 Which two statements are correct about stateless session beans? (Choose two.)

    A. The bean class may declare instance variables. B. The lifetime of the bean instance is controlled by the client. C. The container may use the same bean instance to handle multiple business method invocations at the same time. D. The container may use the same bean instance to handle business method invocations requested by different clients, but not concurrently.

    Answer: A, C

    Explanation: * A:Stateless session beans are EJB's version of the traditional transaction processing applications, which are executed using a procedure call. The procedure executes from beginning to end and then returns the result. Once the procedure is done, nothing about the data that was manipulated or the details of the request are remembered. There is no state. These restrictions don't mean that a stateless session bean can't have instance variables and therefore some kind of internal state. There's nothing that prevents you from keeping a variable that tracks the number of times a bean has been called or that

    examworx.com

  • tracks data for debugging. Aninstance variable can even hold a reference to a live resource like a URL connection for writing debugging data, verifying credit cards, or anything else that might be useful. C:A stateless session bean is relatively easy to develop and also very efficient. Stateless session beans require few server resources because they are neither persistent nor dedicated to one client. Because they aren't dedicated to one client, many EJB objects can use just a few instances of a stateless bean. A stateless session bean does not maintain conversational state relative to the EJB object it is servicing, so it can be swapped freely between EJB objects. As soon as a stateless instance services a method invocation, it can be swapped to another EJB object immediately. Because there is no conversational state, a stateless session bean doesn't require passivation or activation, further reducing the overhead of swapping. In short, they are lightweight and fast! * The Lifecycle of a Stateless Session Bean Because a stateless session bean is never passivated, its lifecycle has only two stages: nonexistent and ready for the invocation of business methods. The EJB container typically creates and maintains a pool of stateless session beans, beginning the stateless session beans lifecycle. The container performs any dependency injection and then invokes the method annotated @PostConstruct, if it exists. The bean is now ready to have its business methods invoked by a client. At the end of the lifecycle, the EJB container calls the method annotated @PreDestroy, if it exists(not B). The beans instance is then ready for garbage collection.

    QUESTION: 12 A developer wants to release resources within a stateless session bean class. The cleanup method should be executed by the container before an instance of the class is removed. The deployment descriptor is NOT used. Which three statements are correct? (Choose three.)

    A. The cleanup method may declare checked exceptions. B. The cleanup method must have no arguments and return void. C. The cleanup method is executed in an unspecified transaction and security context. D. The developer should mark the cleanup method with the @PreDestroy annotation. E. The developer should mark the cleanup method with the @PostDestroy annotation. F. The cleanup method is executed in the transaction and security context of the last business method Invocation.

    Answer: B, C, D

    QUESTION: 13 A developer creates a stateless session bean. This session bean needs data from a remote system. Reading this data takes a long time. Assume that the data will NOT change during the life time of the bean and that the information to connect to the remote system is defined in JNDI. Which statement describes how to manage the data correctly?

    examworx.com

  • A. Read the data in the bean's constructor. B. The data can only be read in the bean's business methods. C. Read the data in a method which is annotated with @PrePassivate. D. Read the data in a method which is annotated with @PostActivate. E. Read the data in a method which is annotated with @PostConstruct.

    Answer: E

    QUESTION: 14 Suppose an EJB named HelloWorldBean is deployed as a standalone ejb-jar. Assuming the HelloworldBean is implemented as follows:

    Which helloWorldBean methods are accessible by another EJB within the same ejb-jar?

    A. All of the methods declared in HelloWorldBean B. All of the methods declared in helloWorld and HelloWorldBean C. All of the public methods declared in HelloWorldBean D. All of the public methods declared in HelloWorld and all of the methods declared in helloWorldBean

    Answer: C

    QUESTION: 15 Given the following stateless session bean:

    examworx.com

  • How would you change the EJB to prevent multiple clients from simultaneously accessing the sayHello method of a single bean instance?

    A. Convert sayHello into a synchronized method B. Execute the call to generateLocalizedHello in a synchronized block C. Convert generateLocalizehello into a synchronized method D. Convert HelloWordBean into a singleton bean E. No changes are needed

    Answer: A

    Explanation: * It is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object. * When a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads.

    Reference: The Java Tutorial,Synchronized Methods

    QUESTION: 16 Given singleton bean FooEJB:

    examworx.com

  • How many distinct FooEJB bean instances will be used to process the code on the lines 101-105?

    A. 0 B. 1 C. 2

    Answer: B

    Explanation: Java has several design patterns Singleton Pattern being the most commonly used. Java Singleton pattern belongs to the family of design patterns, that govern the instantiation process. This design pattern proposes that at any time there can only be one instance of a singleton (object) created by the JVM.

    QUESTION: 17 A developer writes a Singleton bean that holds state for a single coordinate:

    examworx.com

  • An update thread acquires an EJB reference to CoordinateBean and alternates between invoking SetCoordinate (0, 0) and SetCoordinate (1, 1) in a loop. At the same time, ten reader threads each acquire an EJB reference to CoordinateBean and invoke getCoordinate () in a loop. Which represents the set of all possible coordinate values [X, Y] returned to the reader threads?

    A. [0, 0] B. [1, 1] C. [0, 0], [1, 1] D. [0, 0], [0, 1], [1, 0], [1, 1]

    Answer: B

    Explanation: The value could be either [0,0] or [1,1]. Note: Java has several design patterns Singleton Pattern being the most commonly used. Java Singleton patternbelongs to the family of design patterns, that govern the instantiation process. This design pattern proposes that at any time there can only be one instance of a singleton (object) created by the JVM.

    QUESTION: 18 Assume a client will be accessing a Singleton bean. Which client views is a Singleton bean capable of exposing? (Choose two)

    A. Web Service B. Message listener C. EJB 2.x Remote Home D. EJB 3.x local business E. Java Persistence API entity

    Answer: A, B

    Explanation: Singleton session beans are appropriate in the following circumstances. *State needs to be shared across the application. *A single enterprise bean needs to be accessed by multiple threads concurrently. *The application needs an enterprise bean to perform tasks upon application startup and shutdown. *The bean implements a web service.(A) B:An interceptor method you define in a separate interceptor class takes an invocation context as argument: using this context, your interceptor method implementation can

    examworx.com

  • access details of the original session bean business method or message-driven bean message listener method invocation. Singleton Interceptors If your interceptors are stateless, you can use an OC4J optimization extension to the EJB 3.0 specification that allows you to specify singleton interceptors. When you configure a session bean or message-driven bean to use singleton interceptors and you associate the bean with an interceptor class, OC4J creates a single instance of the interceptor class that all bean instances share. This can reduce memory requirements and life cycle overhead. Note: Singleton session beans offer similar functionality to stateless session beans but differ from them in that there is only one singleton session bean per application, as opposed to a pool of stateless session beans, any of which may respond to a client request. Like stateless session beans, singleton session beans can implement web service endpoints.

    Reference: The Java EE 6 Tutorial,What Is a Session Bean? Reference: OracleContainers for J2EE Enterprise JavaBeans Developer's Guide,How do you use an Enterprise Bean in Your Application

    QUESTION: 19 A developer writes a Singleton bean that uses the java Persistence API within a business method:

    Two different concurrently executing caller threads acquire an EJB reference to PersonBean and each invoke the getPerson () method one time. How many distinct transaction are used to process the caller invocations?

    A. 0 B. 1 C. 2

    Answer: B

    Explanation: Only one transaction is required.LockType READallowssimultaneousaccess to singleton beans. Note:READ

    examworx.com

  • public static final LockType READ For read-only operations. Allows simultaneous access to methods designated as READ, as long as no WRITE lock is held.

    Reference: javax.ejb,Enum LockType

    QUESTION: 20 Given the following client-side code that makes use of the session bean Foo: 10. @EJB Foo bean1; 12. @EJB Foo bean2; // more code here 20. boolean testl = beanl.equals(beanl); 21. boolean test2 = beanl.equals(bean2) ; Which three statements are true? (Choose three)

    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 stateless, test1 is true, and test2 is false. E. If Foo is singleton, test1 is true, and test2 is true. F. If Foo is singleton, test1 is true, and test2 is false.

    Answer: B, C

    QUESTION: 21 A developer writes a stateful session bean FooBean with two local business interfaces Foo and bar. The developer wants to write a business method called getBar for interface Foo that returns a Bar reference to the same session bean identity on which the client onvokes getBar. Which code, when inserted on line 12 below implements the getBar method with the wanted behavior? 10. @Resource SessionContext sessionCtx; 11. public Bar getbar () { 12. 13. }

    A. Return (bar) this; B. Return (bar) new FooBarBean(); C. Return (bar) sessionCtx.lookup(FooBarBean) D. Return (bar) sessionCtx.getBusinessObject(Bar.class); E. Return (bar) session Ctx.lookup(java: comp/env/ejb/FooBarBean);

    Answer: D

    examworx.com

  • QUESTION: 22 Given the following code in an EJB session bean:

    Which code, inserted at Line 15, portably looks up the injected resource?

    A. Object obj = ic.lookup (employeeDB); B. Object obj = ic.lookup (dataSource); C. Object obj = ic.lookup (jdbc/employeeDB); D. Object obj = ic.lookup (java: comp/env/employeeDB); E. Object obj = ic.lookup (java: cmp/env/jdbc/employeeDB);

    Answer: E

    QUESTION: 23 A developer is writing client code to access a session bean deployed to a server instance. The client can access the session bean under which of these circumstances? (Choose three)

    A. The client is deployed in the same JVM as the session bean and the session bean has a local interface. B. The client is deployed in the same JVM as the session bean and the session bean exposes a no-interface view. C. The client is deployed in a different JVM from the session bean and the session bean has a local interface. D. The client is deployed in a different JVM from the session bean and the session bean has a remote interface. E. The client is deployed in a different JVM from the session bean and the session bean has a no- interface implementation.

    Answer: A, B, D

    Explanation: D: If your architecture has a requirement whereby the client application (web application or rich client) has to run on a different JavaVirtual Machine (JVM) from the one that is

    examworx.com

  • used to run the session beans in an EJB container, then you need to use the remote interface.

    QUESTION: 24 A developer writes three interceptor classes: AInt, BInt, and CInt. Each interceptor class defines an AroundInvoke method called interceptor. In the ejb-jar.xml descriptor, CInt is declared as the default interceptor. FooBean is a stateless session bean with a local business interface Foo that declares a method Foo (): 10. @Stateless 11. @Interceptors(AInt.class) 12. public class FooBean Implements Foo { 13. 14. @Interceptors (BInt.class) 15. @ExcludeClassInterceptors 16. public void foo () {} 17. }

    What is the interceptor order when the business method foo () is invoked?

    A. BInt B. CInt, BInt C. CInt, AInt, BInt D. BInt, AInt, CInt

    Answer: B

    Explanation: The default Intercepter, CInt, comes first. The class intercepter AInt is excluded by@ExcludeClassInterceptors, so the Method Intercepter BInt would be next in order. Note 1:By default the ordering of interceptors when invoking a method are *External interceptors **Default interceptors, if present **Class interceptors, if present **Method interceptors, if present *Bean class interceptor method Note2:Annotation Type ExcludeClassInterceptors Used to exclude class-level interceptors for a business method or timeout method of a target class.

    Reference: EJB Interceptors http://docs.jboss.org/ejb3/app-server/tutorial/interceptor/interceptor.html

    examworx.com

  • QUESTION: 25 An ejb-jar also contains three interceptor classes: AInt, BInt, CInt. Each interceptor class defines an AroundInvoke method called intercept. The ejb-jar also contains a stateless session bean FooBean with a local business interface Foo that declares a method foo (): 10. @Stateless 11. @Intercaptors ({CInt.class, BInt.class}) 12. public class FooBean implements Foo { 13. 14. public void foo () {} 15. 16. } The ejb-jar contains a META-INF/ejb-jar.xml file with an section: FooBean com.acme.AInt

    What is the interceptor order when the business methodfoo() is invoked?

    A. AInt B. AInt, CInt, BInt C. CInt, BInt, AInt D. AInt, BInt, CInt

    Answer: B

    Explanation: With theinterceptor-orderclauses Aint will be first in the order of interceptors. Within each group (default, class, method) the order of the interceptors are from left to right as defined in the @Interceptors annotation, and then the xml interceptors. In this scenario, with the@Intercaptors ({CInt.class, BInt.class})line, the ordering continues with CInt and BInt. Note 1:By default the ordering of interceptors when invoking a method are *External interceptors **Default interceptors, if present **Class interceptors, if present **Method interceptors, if present *Bean class interceptor method Note 2:You can override the default sort order of the external interceptors by specifiying an interceptor-binding with an interceptor-order specifying the order of the interceptors

    Reference: EJB Interceptors http://docs.jboss.org/ejb3/app-server/tutorial/interceptor/interceptor.html

    examworx.com

  • QUESTION: 26 How many interceptor classes can be applied to a single stateful session bean?

    A. a maximum of one B. any number may be applied C. one for each business method D. one for each business interface

    Answer: B

    Explanation: The @Interceptors annotation can take an array of classes, so you can bind more than one class-level interceptor this way, e.g. @Stateless @Interceptors ({TracingInterceptor.class, SomeInterceptor.class}) public class EmailSystemBean { }

    Reference: EJB Interceptors http://docs.jboss.org/ejb3/app-server/tutorial/interceptor/interceptor.html

    QUESTION: 27 A developer writes an interceptor class called FooInterceptor containing the following AroundInvoke method: 11. @AroundInvoke 12. public Object intercept (InvocationContext ctx) { 13. return intercepted; 14. } FooInterceptor is applied to a business method in a stateless session bean: 11. @Interceptors (FooInterceptor.class) 12. public String testzero(int i) { 13. return (i = = 0) ? zero: not zero 14. } Which describes the result when a client invokes the testzero method with a value of 1?

    A. The interceptor method is NEVER invoked. B. The client receives a return value of zero. C. The client receives a return value of not zero. D. The client receives a return value of intercepted.

    examworx.com

  • Answer: D

    QUESTION: 28 A bean developer wants to write a stateless session bean class that implements the following remote business interface: @Remote Public interface Foo { Void bar () throws Exception; Which bean class method is valid?

    A. @Asynchronous public void bar () throws Exception { . . . } B. @Asynchronous Future bar () { . . .} C. void bar () throws Exception { . . . } D. public void bar () { . . . }

    Answer: B

    Explanation: with EJB 3.1, you can use a simple session EJB with the @Asynchronous annotation on the method which must be called asynchronously. @Stateless @Remote(HelloEjbAsynchronousRemote.class) public class HelloEjbAsynchronous implements HelloEjbAsynchronousRemote { @Asynchronous @Override public Future ejbAsynchronousSayHello(String name){ If your method has a return value, your method has to return an AsyncResult object which is an implementation of Future.

    QUESTION: 29 Which is true about caller security principal propagation for asynchronous EJB method Invocations?

    A. Caller security principal propagates along with an asynchronous EJB method invocation. B. Caller security principal does not propagate along with an asynchronous EJB method invocation. C. Caller security principal propagates along with an asynchronous EJB method invocation only if the target bean has at least one protected method. D. Caller security principal propagates along with an asynchronous EJB method invocation only if the calling bean has at least one protected method.

    examworx.com

  • Answer: D

    Explanation: One important caveat of asynchronous method invocation is that transactions are not propagated to theasynchronous methoda new transaction will be started for the asynchronous method. However, unlike transactions, the security principal will be propagated. Declarative security is based only on the principal and the method being invoked, whereas programmatic security can take state into consideration.

    QUESTION: 30 A bean developer writes a stateless session bean FooEJB with the following asynchronous business method: @Asynchronous public Future fooAsync () { System.out.printIn (begin); int i = 1; System.out.print(end); Return new AsyncResult (i); } Given the following code, where fooRef is an EJB reference to fooEJB: Future fooFuture = fooref.fooAsync(); fooFuture.cancel (true); Which two represents possible system output after all processing has completed? (Choose two)

    A. Begin end B. Begin C. End D. 1 E.

    Answer: D, E

    Explanation: Either it will run and return 1, or it will be cancelled and produce no output. Note:EJB 3.1 can support a return type of java.util.concurrent.Future, where V represents the resultant value of an asynchronous invocation. In case you are unfamiliar with it, the Future interface allows you to do things like cancelling an asynchronous invocation, checking if an invocation is complete, check for exceptions and getting the results of an asynchronous invocation.

    QUESTION: 31 Given two stateless session beans, ABean and BBean:

    examworx.com

  • A client that is not executing within a transaction acquires an EJB reference to ABean and invokes the a() method on time. How many distinct transactions are started by the container after all processing has completed?

    A. 0 B. 1 C. 2 D. 3

    Answer: B

    Explanation: Note:REQUIRED If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context.

    Reference: Enum TransactionAttributeType

    QUESTION: 32 Given this code snippet from a JMS message driven bean class X: examworx.com

  • When this bean class handles a message, which is correct?

    A. After a message delivery the result is 1. B. After a message delivery the result is 2. C. After a message delivery the result is 12. D. After a message delivery an exception is thrown. E. After a message delivery the result is unpredictable. F. This is NOT a compliant JMS message-driven bean.

    Answer: F

    QUESTION: 33 Which statement about message-driven beans is correct?

    A. Each message-driven bean instance will be invoked by only one thread at a time. B. When dispatching messages to message beam instances the container must preserve the order in which messages arrive. C. If a message-driven bean is associated with a JMS queue, each bean instance in the pool will receive each message sent to the queue. D. If a message driven bean is associated with a JMS durable subscription, each bean instance in the pool will receive each message sent to the durable subscription.

    Answer: A

    QUESTION: 34 Given code snippets from two files:

    examworx.com

  • Which four code changes, when used together, create a valid JMS message-driven bean? (Choose four)

    A. Make class MessageDog public B. Make the MessageDog constructor no-arg C. Make the MessageDog constructor public D. Move the onMessage method to class MessageDog. E. Change MessageDog so that it is NOT a subclass of Dog. F. Make class MessageDog implement MessageListner instead of MessageDrivenBean.

    Answer: A, B, C, F

    QUESTION: 35 Which is a valid Postconstruct method in a message-driven bean class?

    A. @PostConstruct public boolean init() { return true; } B. @PostConstruct private static void init () {} C. @PostConstruct private void init () D. @PostConstruct public static void init () {}

    Answer: C

    QUESTION: 36 Which statement is correct about a Java EF client of a message driven bean?

    A. The client can use JNDI to obtain a reference to a message destination. B. The client can use JNDI to obtain a reference to a dependency injection. C. The client can use JNDI to obtain a reference to a message-driven bean instance. D. The client can use JNDI to look up a reference to the message-driven bean's home interface.

    Answer: A

    QUESTION: 37 You are writing an EE component that functions as a message producer. The message producer sends message to a JMS queue. The component environment defines a resource- ref of type javax.jms.ConnectionFactory with the same jms/ConnectionFactory. Which will correctly obtain a connection factory for a queue?

    examworx.com

  • A. Context context = new initialContext(); Connectionfactory confac = (ConnectionFactory) Context.lookup (java: comp/env/jms/ConnectionFactory); B. InitialContext Context = new Context () ; QueueConnectionFactory confac = (QueueConnectionFactory) context.lookup (java: comp/env/jms/Myfactory); C. @Resource (ConnectionFactory) private static QueueConnectionFactory confac; D. @Resource (loopkup = jms/QueueConnectionFactory) private static ConnectionFactoryconfac;

    Answer: D

    Explanation: A connection factory is the object a client uses to create a connection to a provider. A connection factory encapsulates a set of connection configuration parameters that has been defined by an administrator. Each connection factory is an instance of theConnectionFactory, QueueConnectionFactory, or TopicConnectionFactory interface At the beginning of a JMS client program, you usually inject a connection factory resource into a ConnectionFactory object. For example, the following code fragment specifies a resource whose JNDI name is jms/ConnectionFactory and assigns it to a ConnectionFactory object: @Resource(lookup = "jms/ConnectionFactory") private static ConnectionFactory connectionFactory;

    Reference: The Java EE 6 Tutoria,The JMS API Programming Model

    QUESTION: 38 You are writing a client that sends a message to a JMS queue. Which statement is true?

    A. You use a connection factory to create a session. B. When you create a session, you specify whether or not it is transacted. C. When you create a connection, you specify the acknowledgment mode. D. When you create a message producer, you must specify the name of the destination to which you will send messages.

    Answer: A

    Explanation:

    examworx.com

  • Note: The SimpleMessageClient sends messages to the queue that the SimpleMessageBean listens to. The client starts by injecting the connection factory and queue resources: @Resource(mappedName="jms/ConnectionFactory") private static ConnectionFactory connectionFactory; @Resource(mappedName="jms/Queue") private static Queue queue; Next, the client creates the connection, session, and message producer: connection = connectionFactory.createConnection(); session = connection.create Session(false, Session.AUTO_ACKNOWLEDGE); messageProducer = session.createProducer(queue); Finally, the client sends several messages to the queue: message = session.createTextMessage(); for (int i = 0; i < NUM_MSGS; i++) { message.setText("This is message " + (i + 1)); System.out.println("Sending message: " + message.getText()); messageProducer.send(message);

    }

    QUESTION: 39 Which two are true about the client view of a message-driven bean? (Choose two.)

    A. References to message destinations can be infected. B. References to message destinations cannot be looked up in the client's JNDI namespace. C. Clients of a message destination need to know that the destination is listened to by a pool of message consumers, D. Clients of a message destination do NOT need to know that the destination is listened to by a message-driven bean.

    Answer: B, C

    Explanation: Client components do not locate message-driven beans and invoke methods directly on them. Instead, a client accesses a message-driven bean through, for example, JMS by sending messages to the message destination for which the message-driven bean class is the MessageListener.

    Reference: The Java EE 6 Tutorial,What Is a Message-Driven Bean?

    QUESTION: 40 Given the following stateful bean: 10. @Stateful 11. @TransactionAttribute(TransactionAttributeType.SUPPORTS)

    examworx.com

  • 12. public class VideoBean implements video { 13. / / insert code here 14. public void method () {} 15. } Assuming no other transaction-related metadata, which code can be added at line 13 to guarantee that business method methodA will execute only if invoked with an active transaction?

    A. @Transaction Attribute () B. @transaction management (TransactionAttributeType.CONTAINER) C. @Transaction Attribute(transactionAttributeType.MANDATORY) D. @transaction Attribute (TransactionattributeType.RECQUIRES_NEW)

    Answer: C

    QUESTION: 41 Given the stateful session bean:

    Assuming no other transaction-related metadata, which is true?

    A. methodB and methodC have transaction attribute SUPPORTS, which methodD has transaction attribute REQUIRED. B. methodA and methodC have transaction attribute REQUIRES_NEW, while methodB has transaction attribute SUPPORTS. C. methodC, methodD, and methodA have transaction attribute REQUIRED, and methodB has transaction attribute SUPPORTS. D. methodB has transaction attribute SUPPORTS, methodD has transaction attribute REQUIRED, and methodA and methodC have transaction attribute REQUIRES_NEW.

    Answer: C

    QUESTION: 42 Given a set of CMT bean methods with the following transaction attributes:

    Method M1 = SUPPORTS

    examworx.com

  • Method M2 = REQUIRED Method M3 = NOT_SUPPORTED Method M4 = REQUIRES NEW And the following method invocation sequence: Method Ml invokes Method M2 Method M2 invokes Method M3 Method M1 invokes Method M4 If Method Ml is invoked by a method that does NOT have a transaction context, which describes a possible scenario?

    A. Method M1: no transaction Method M2: new transaction Method M3: no transaction Method M4: new transaction B. Method M1: no transaction Method M2: Container throws EJBTransactionRequiredException C. Method M1: new transaction Method M2: runs in same transaction as M1 Method M3: Container throws TransactionNotSupportedException D. Method M1: no transaction Method M2: new transaction Method M3: Container throws TransactionNotSupportedException

    Answer: A

    QUESTION: 43 A stateful session bean needs to restore its conversational state to its initial state if the transaction in which the bean is participating rolls back. Which bean method can be used to do this?

    A. SessionContext.setRollbackOnly B. SessionContext.getUserTransaction C. SessionSynchronization.afterCompletion D. SessionSynchrinization.beforeCompletion

    Answer: C

    Explanation: The afterCompletion method notifies a stateful session bean instance that a transaction commit protocol has completed, and tells the instance whether the transaction has been committed or rolled back. Returns: True if the current transaction is marked for rollback, false otherwise.

    Reference: javax.ejb,Interface SessionSynchronization

    examworx.com

  • QUESTION: 44 A developer implements a session bean which acts as a session facade for an application. This means that clients will only see this session bean's interface which offer the application interface, where are three distinct roles known at development time: "user", "admin", and "guest". The majority of the methods will be used by role "user". All methods must have role permissions active and roles may be added or changed in the future. Which two scenarios are correct? (Choose two.)

    A. The developer annotates the bean class with @PermitAll and annotates the methods used by role "guest" or "admin" individually. B. The developer annotates the bean class with @DenyAll and annotates the methods used by role "user", "guest", or "admin" individually. C. The developer defines individual method permissions for the methods used by roles "user "guest", and "admin" In the deployment descriptor. D. The developer annotates the bean class with @RolesAllowed("user") and annotates the methods used by role "guest" or "admin" individually. E. The developer defines a method permission with method name "*" and role "user" and adds individual method permissions for the methods used by roles "guest" and "admin" in the deployment descriptor.

    Answer: D, E

    QUESTION: 45 A java EE application contains a session bean which uses a security role USER. A group called people is defined an LDAP server. Which two define appropriate EJB role responsibilities? (Choose two.)

    A. The deployer defines and configures the LDAP realm. B. The system administrator defines and configures the LDAP realm. C. The deployer maps the application role USER to the LDAP group people. D. The system administrator maps the application role USER to the LDAP group people.

    Answer: B, C

    QUESTION: 46 An enterprise bean has security permissions set up using declarative security features. Under which two conditions can a client be guaranteed to have permission to Invoke

  • B. The client's principal has been assigned a security role with permission to invoke the method. C. The Application Assembler has set the security-identity deployment descriptor to run- as. D. The Application Assembler has mapped all security role references using the role-link element.

    Answer: A, B

    QUESTION: 47 Given a session bean defines: 11. @Stateless (name = MrBean) 12. public class source SecureBean implements local business, remoteBusiness { Where LocalBusiness is a local business interface and RemoteBusines is a remote business interface. The following deployment descriptor entries represent the only security-related metadata:

    Which is true about the security roles of clients MrBean?

    A. Only LocalBusiness clients must be in role A. B. Only LocalBusiness clients must be in role B. C. Both LocalBusiness and RemoteBusiness Clients must be in role A. D. Both LocalBusiness and RemoteBusiness clients must NOT be in role A.

    Answer: C

    QUESTION: 48 Suppose a developer wants to create an automatic persistent timer that performs data validation every hour. Given the following stateless session bean: @Stateless Public class OrderVerificationBean { Private void verificationExternalOrders ()

    examworx.com

  • {

    examworx.com

  • / / do something } } What is the minimum modification you would need to make to the bean to create the automatic persistent timer?

    A. Modify the verifyExternalOrders methos to look like this: @Schedule private void verifyExternalOrders () { / do something } B. Modify the verifyExternalOrders method to look like this: @Schedule (hour = *) private void verifyExternalOrders () { / / do something } C. Modify the verifyExternalOrders method to look like this: @Schedule (persistent = true) private void verifyExceptionalOrders () { / / do something } D. Modify the verifyExternalOrders method to look like this: @Schedule (hour = *, persistent = true) private void verifyExceptionalOrders () { / / do something }

    Answer: B

    Explanation: Not D:Timers are persistent by default. If the server is shut down or crashes, persistent timers are saved and will become active again when the server is restarted. If a persistent timer expires while the server is down, the container will call the @Timeout method when the server is restarted. Nonpersistent programmatic timers are created by calling TimerConfig.setPersistent(false) and passing the TimerConfig object to one of the timer- creation methods.

    QUESTION: 49 A developer implements a stateless session bean as a timed object. The bean contains two local business methods with the transaction attribute REQUIRED. examworx.com

  • A client begins a UserTransaction and calls the foo local business method. The foo method returns five seconds later. The client rolls back the transaction and then calls the bar local business method. Assuming there have been no other client invocations on the stateless session bean, what is the value of the size variable when control reaches Line?

    A. 0 B. 1 C. -1

    Answer: A

    Explanation: An enterprise bean usually creates a timer within a transaction. If this transaction is rolled back, the timer creation also is rolled back. The transaction will roll back. The creation of the timer will rock back. There will be zero timers. Note:The UserTransaction interface defines the methods that allow an application to explicitly manage transaction boundaries. rollback()rollsback the transaction associated with the current thread. Note 2:size() Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

    Reference: The Java EE 6Tutorial.PartNo: 821 Transactions andTimers

    QUESTION: 50 A developer wants to create an enterprise bean that uses the EJB Timer service. Which two are true? (Choose two.)

    A. Once created, a timer cannot be canceled. B. The bean can be used within a transaction. C. Once created, the timer will survive a container crash. D. The enterprise bean must implement the TimedObject interface.

    examworx.com

  • E. The developer can use either a message-driven bean, stateless session bean, or stateful session bean.

    Answer: B, C

    Explanation: B:An enterprise bean usually creates a timer within a transaction. If this transaction is rolled back,the timer creation also is rolled back. Similarly, if a bean cancels a timer within a transaction that gets rolled back, the timer cancellation is rolled back. C:Timers are persistent by default. If the server is shut down or crashes, persistent timers are saved and will become active again when the server is restarted. If a persistent timer expires while the server is down, the container will call the @Timeout method when the server is restarted.

    Reference: The Java EE 6Tutorial.PartNo: 821 Transactions andTimers

    QUESTION: 51 Suppose developer wants to create an EJB component that performs data validation every hour. Given the following Stateless session bean:

    What is the minimum modification you would need to make to the bean to support notification from the TimerService once the timer expires?

    A. Modify the verify external orders method to look like this: @TimedOut private void verifyExternalOrders () { / / do something

    examworx.com

  • } B. Modify the verify external orders method to look like this: @EjbTimeOut private void verifyExternalOrders () { / / do something } C. Modify the verify external orders method to look like this: @ejbTimeOut private void verifyExternalOrders () { / / do something } D. Modify the verify external orders method to look like this: @TimeOut private void verifyExternalOrders () { / / do something }

    Answer: D

    Explanation: Programmatic Timers When a programmatic timer expires (goes off), the container calls the method annotated @Timeout in the beans implementation class. The @Timeout method contains the business logic that handles the timed event. The @Timeout Method Methods annotated @Timeout in the enterprise bean class must return void and optionally take a javax.ejb.Timer object as the only parameter. They may not throw application exceptions. @Timeout public void timeout(Timer timer) { System.out.println("TimerBean: timeout occurred"); }

    Reference: The Java EE 6 Tutorial,Using the Timer Service

    QUESTION: 52 An enterprise developer needs to modify the order of interceptor method execution specified by the Bean Provider, but does NOT have access to the bean's source code. No deployment descriptor was provided in the EJB jar delivered by the Bean Provider. Which represents the solution to this problem?

    A. No solution is possible under these conditions. B. The Deployer can add metadata annotations to the ejb-jar. C. The Application Assembler can add metadata annotations to the ejb-jar.

    examworx.com

  • D. The System Administrator can add interceptor binding information at runtime, using vendor- specific tools. E. The Application Assembler can add a deployment descriptor to the ejb-jar that includes interceptor binding information.

    Answer: E

    QUESTION: 53 A developer wants to package an enterprise bean FooBean within a .war file: @Stateless public xlass FooBean { public void foo () {} } Which package approach is correct?

    A. / (Root) I META INF / I acme I FooBean.class B. / (Root) I acme I FooBean.class C. / (Root) I WEB INF / I acme I FooBean.class D. / (Root) I WEB INF / I Classes/ I acme I FooBean.class

    Answer: D

    Explanation: To include enterprise bean class files in aWARmodule, the class files should be in the WEB-INF/classes directory. Note:Enterprise beans often provide the business logic of a web application. In these cases, packagingthe enterprise bean within the web applicationsWARmodule simplifies deployment andapplication organization. Enterprise beans may be packaged within aWARmodule as Java programming language class files or within a JAR file that is bundled within theWARmodule.

    Reference: The Java EE 6Tutorial,Packaging Enterprise Beans inWAR Modules

    examworx.com

  • QUESTION: 54 A developer creates a stateless session bean, EmployeeServiceBean, and its interface, EmployeeService. The session bean uses two annotated entity classes, Employee.class and Department.class. Which two package options can the developer use when creating a deployable EAR? The proposed directory structure is listed for each option. (Choose two)

    A. Emp.ear emp-ejb.jar META-INF/persistence.xml EmployeeService.class EmployeeServiceBean.class lib/emp- classes.jar Employee.class Department.class B. Emp.ear META-INF/orm.xml EmployeeService.class EmployeeServiceBean.class Employee.class Department.class C. Emp.ear emp-ejb.jar META-INF/persistence.cml Employee.class Department.class EmployeeService.class EmployeeServiceBean.class D. Emp.ear emp-ejb.jar persistence.xml Employee.class Department.class EmployeeService.class EmployeeServiceBean.class

    Answer: A, C

    QUESTION: 55 Assume you have been tasked with building an ejb-jar containing an EJB application. The EJB application contains local, remote, and web service and-point EJBs that provide reusable services within an enterprise. When the application is deployed clients will access the remote session beans using the global JNDI name java/: ServiceLayer / . All of the EJBs are located in the com.acme.servicelayer package and are deployed as class files. The application uses a maximum of deployment descriptor and annotation configuration?

    A. Name the jar servicelayer.jar with the following structure: / (Root) I META INF / I MANIFEST.MF I classes/ I com/ I acme/ I servicelayer / B. Name the jar servicelayer.jar with the following structure: / (Root) I META INF/ I MANIFEST.MF I ejb jar.xml I classes/ I com/ I acme / I servicelayer/

    examworx.com

  • C. Name the jar servicelayer.jar with the following structure: /(Root) I META INF / I ejb jar.xml I com/ I acme/ I servicelayer/ D. Name the jar servicelayer.jar with the following structure: / (Root) I META INF/ I MANIFEST.MF I ejb-jar.xml I com/ I servicelayer/

    Answer: A

    Explanation: Structure of an Enterprise Bean JAR: Assembly Root ejb-jar.xml glassfish-ejb-jar.xml(optional, not used hereNot D, Not C, not B)) META-INF MANIFEST.MF All .class filesfor this module

    References: The Java EE 6Tutorial,Packaging Enterprise Beans in EJB JAR Modules

    QUESTION: 56 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.

    examworx.com

  • D. A javax.ejb.NoSuchEntityException is thrown.

    Answer: B

    QUESTION: 57 MyMsg is a JMS message-driven bean with container-managed transaction demarcation. FooBean is an EJB 3.x stateless session bean that sends message to the JMS destination with MyMsgBean is associated. MyMsgBeans message listener method has transaction attribute REQUIRED, and is defined as follows: 10. public class MyMsgBean implements javax.jms.messageListener { 11. public void onMessage(javax.jms.Message message) { 12. / / do some work not shown here 13. thrown new RuntimeException(unexpected error . . . ); 14. } Which statement is true about the result of message processing?

    A. FooBean receives javax.ejb.EJBException. B. The container discards the MyMsgBean bean instance. C. FooBean receives the original Runtime Exception thrown from the message listener method. D. The container does NOT roll back the transaction, and FooBean can continue the transaction.

    Answer: C

    Explanation: Note:public interface MessageListener A MessageListener object is used to receive asynchronously delivered messages. Each session must insure that it passes messages serially to the listener. This means that a listener assigned to one or more consumers of the same session can assume that the onMessage method is not called with the next message until the session has completed the last call.

    Reference: Enum Transaction Attribute Type

    QUESTION: 58 Given an JMS message-driven bean, which statement is true about its exception handling?

    A. Its message listener method must NOT throw any checked exception. B. Its message listener method can throw java.rmi.RemoteException.

    examworx.com

  • C. Its message listener method can throw any checked exception except java.rmi.Remote Exception. D. Its message listener method can throw any checked exception that implements java.io.Serializable.

    Answer: A

    QUESTION: 59 Which is a correct way to define a runtime exception as an EJB 3.x application exception?

    A. public class MyAppException extends javax.ejb.EJBException B. @ApplicationException public class MyAppException extends javax.ejb.EJBException C. public class MyAppException extends javax.lang.EJBException D. @ApplicationException public class MyAppException extends javax.lang.EJBException

    Answer: B

    Explanation: Use the @javax.ejb.ApplicationException annotation to specify that an exception class is an application exception thrown by a business method of the EJB. The EJB container reports the exception directly to the client in the event of the application error. Note: java.lang.Object java.lang.Throwable java.lang.Exception java.lang.RuntimeException javax.ejb.EJBException javax.ejb public class EJBException extends java.lang.RuntimeException The EJBException is thrown to report that the invoked business method or callback method could not be completed because of an unexpected error (e.g. the instance failed to open a database connection).

    Example: The following ProcessingException.java file shows how to use the @ApplicationException annotation to specify that an exception class is an application exception thrown by one of the business methods of the EJB: package examples; import javax.ejb.ApplicationException; /*** Application exception class thrown when there was a processing error* with a business method of the EJB. Annotated with the* @ApplicationException annotation.*/ @ApplicationException()public class ProcessingException extends Exception { Reference:Programming WebLogic Enterprise JavaBeans, Version 3.0programming Application Exceptions

    examworx.com

  • QUESTION: 60 A developer writes a stateless session bean with one local business interface and with container- managed transactions. All business methods have transaction attribute REQUIRED. The bean has an injected field sessionCtx of the type Session Context. Which two operations are allowed in a business method of the bean? (Choose two.)

    A. sessionCtx. getEJBObject B. sessionCtx.setRollbackOnly C. sessionCtx. getMessageContext D. sessionCtx. getBusinessObject E. sessionCtx. getEJBLocalObject

    Answer: B, D

    examworx.com

    /ColorImageDict > /JPEG2000ColorACSImageDict > /JPEG2000ColorImageDict > /AntiAliasGrayImages false /CropGrayImages true /GrayImageMinResolution 300 /GrayImageMinResolutionPolicy /OK /DownsampleGrayImages true /GrayImageDownsampleType /Bicubic /GrayImageResolution 300 /GrayImageDepth -1 /GrayImageMinDownsampleDepth 2 /GrayImageDownsampleThreshold 1.50000 /EncodeGrayImages true /GrayImageFilter /DCTEncode /AutoFilterGrayImages true /GrayImageAutoFilterStrategy /JPEG /GrayACSImageDict > /GrayImageDict > /JPEG2000GrayACSImageDict > /JPEG2000GrayImageDict > /AntiAliasMonoImages false /CropMonoImages true /MonoImageMinResolution 1200 /MonoImageMinResolutionPolicy /OK /DownsampleMonoImages true /MonoImageDownsampleType /Bicubic /MonoImageResolution 1200 /MonoImageDepth -1 /MonoImageDownsampleThreshold 1.50000 /EncodeMonoImages true /MonoImageFilter /CCITTFaxEncode /MonoImageDict > /AllowPSXObjects false /CheckCompliance [ /None ] /PDFX1aCheck false /PDFX3Check false /PDFXCompliantPDFOnly false /PDFXNoTrimBoxError true /PDFXTrimBoxToMediaBoxOffset [ 0.00000 0.00000 0.00000 0.00000 ] /PDFXSetBleedBoxToMediaBox true /PDFXBleedBoxToTrimBoxOffset [ 0.00000 0.00000 0.00000 0.00000 ] /PDFXOutputIntentProfile () /PDFXOutputConditionIdentifier () /PDFXOutputCondition () /PDFXRegistryName () /PDFXTrapped /False

    /Description > /Namespace [ (Adobe) (Common) (1.0) ] /OtherNamespaces [ > /FormElements false /GenerateStructure false /IncludeBookmarks false /IncludeHyperlinks false /IncludeInteractive false /IncludeLayers false /IncludeProfiles false /MultimediaHandling /UseObjectSettings /Namespace [ (Adobe) (CreativeSuite) (2.0) ] /PDFXOutputIntentProfileSelector /DocumentCMYK /PreserveEditing true /UntaggedCMYKHandling /LeaveUntagged /UntaggedRGBHandling /UseDocumentProfile /UseDocumentBleed false >> ]>> setdistillerparams> setpagedevice