1Z0-895 | What Actual 1Z0-895 practice test Is?


Q21. Given the following stateful bean: 

10. @Stateful 

11. @TransactionAttribute(TransactionAttributeType.SUPPORTS) 

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. @TransactionAttribute () 

B. @transactionmanagement(TransactionAttributeType.CONTAINER) 

C. @TransactionAttribute(transactionAttributeType.MANDATORY) 

D. @transactionAttribute(TransactionattributeType.RECQUIRES_NEW) 

Answer:

Q22. Which three methods can Bean Developer use in any EJB compliant container implementing the full Java EE6 product? (Choose three.) 

A. Class.getClassLoader 

B. FileInputStream.read 

C. DataSource.getConnection 

D. EJBContext.getCallerPrincipal 

E. Executors.newSingleThreadExecutor 

F. QueueConnection.createQueueSession 

Answer: BCD 

Explanation: D: Use EJBContext. getCallerPrincipal() to obtain the java.security.Principal that identifies the caller. 

Incorrect: 

A: Do not load native libraries. 

E: Not allowed: Starting, stopping, or managing threads in any way. That restriction eliminates the possibility of conflicts with the EJB container's responsibilities of managing locking, threading, and concurrency issues. 

Reference: Programming restrictions on EJB 

Reference: javax.ejb Interface EJBContext 

Q23. 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. } 

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:

Q24. 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:

Q25. 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: AB 

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 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: Oracle Containers for J2EE Enterprise JavaBeans Developer's Guide, How do you use an Enterprise Bean in Your Application 

Q26. 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? 

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:

Q27. 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: CE 

Q28. Assume an EJB application is comprised of the following EJB fragment: 

You have been asked to convert the type of InventoryReportBean into a singleton session bean. How would you achieve this task? 

Exhibit C: 

Exhibit D: 

A. Keep InventoryReportBean as it is, modifying the internal structure to function as a singleton 

B. Change the @Stateless annotation of InventoryReportBean to @Singleton 

C. Create an ejb-jar.xml file, and override the annotation configuration information as in exhibit C above. 

D. Create an ejb-jar.xml file, and override the annotation configuration information as in exhibit D above. 

Answer:

Explanation: Note the line with <override-type> 

Q29. 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. 

MyMsgBean’s 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 RuntimeException thrown from the message listener method. 

D. The container does NOT roll back the transaction, and FooBean can continue the transaction. 

Answer:

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 TransactionAttributeType 

Q30. You are writing a client that sends a message to a JMS queue. The client includes the following code snippet: 

A. The message can be consumed by durable subscriber. 

B. In the first line, the argument to the createProducer method needs to be cast to a Destination. 

C. The message is sent using non-default deliver mode, priority, and expiration time values. 

D. You could add more name-value pairs to the message body of the MapMessage if they were required by your application. 

Answer:

Explanation: createMapMessage 

MapMessage createMapMessage() throws JMSException Creates a MapMessage object. A MapMessage object is used to send a self-defining set of name-value pairs, where names are String objects and values are primitive values in the Java programming language. 

Reference: javax.jms, Interface Session