1Z0-895 | High quality Oracle 1Z0-895 vce


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

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:

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

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.0 programming Application Exceptions 

Q3. A developer impalements an asynchronous implementation for calculating insurance proposals. The input data for the calculations is made available on a single message queue. Two types of insurance proposals will be calculated: car and life. Message with data for other insurance types are posted on the queue but should be left on the queue by this implementation. 

Which statement is true? 

A. The developer will NOT succeed because all messages will be consumed from the queue. 

B. The developer can implement a push-back mechanism if the message is of the wrong type. 

C. The developer can use a messageSelector to receive only the car and life data message if the JMS body contains selectable data. 

D. The developer can use a messageSelector to receive only the car and life data message if the header contains properties to make selection. 

Answer:

Explanation: A JMS message selector allows a client to specify, by header field references and property references, the messages it is interested in. Only messages whose header and property values match the selector are delivered. What it means for a message not to be delivered depends on the MessageConsumer being used (see QueueReceiver and TopicSubscriber). 

Reference: javax.jms Interface Message 

Q4. 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 <interceptor-binding> section: 

<interceptor-binding> <ejb-name>FooBean</ejb-name> <interceptor-order> <interceptor.class>com.acme.AInt</interceptor-class> </interceptor-order> 

</interceptor.binding> 

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:

Explanation: With the interceptor-order clauses 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 

Q5. Given this code snippet from a JMS message driven bean class X: 

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:

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

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, packaging the enterprise bean within the web application’sWARmodule simplifies deployment and application 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 

Q7. 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: BCD 

Q8. Which statement is true about both stateful session beans and stateless session beans? 

A. Bean instance are NOT required to survive container crashes. 

B. Any bean instance must be able to handle concurrent invocations from different threads. 

C. A bean with bean-managed transactions must commit or roll back any transaction before returning from a business method. 

D. The container passivates and actives them using methods annotated with @PrePassivate and @PostActivate annotations. 

Answer: AC 

Explanation: 

Note: 

* Session beans can either be stateful or stateless. With stateful beans, the EJB container saves internal bean data during and in between method calls on the client’s behalf. With stateless beans, the clients may call any available instance of an instantiated bean for as long as the EJB container has the ability to pool stateless beans. This enables the number of instantiations of a bean to be reduced, thereby reducing required resources. 

Incorrect: 

B: Stateful session beans maintain state both within and between transactions. Each stateful session bean is therefore associated with a specific client. 

D: @PrePassivate(javax.ejb.PrePassivate) : 

If a stateful session bean instance is idle for too long, the container might passivate it and store its state to a cache. 

The method tagged by this annotation is called before the container passivates the bean instance. 

This annotation is only applicable to stateful session beans. 

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

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

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 Note 2: 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