310-091 Sun Certified Bus. Component Developer Java EE Test Set 7

The ejb-jar file format is a contract between which two EJB role pairs? (Choose two.)

A. Deployer and System Administrator

B. Application Assembler and Deployer

C. Bean Provider and Application Assembler

D. Bean Provider and EJB Container Provider

E. EJB Server Provider and EJB Container Provider

F. Application Assembler and EJB Container Provider


Options are :

  • B,A
  • E,C
  • B,F
  • B,C

Answer : B,C

310-091 Sun Certified Bus. Component Developer Java EE Test Set 8

FooBean and BarBean are both EJB 3.0 stateless session beans with container-managed

transaction demarcation. All business methods in the two beans have transaction attribute

REQUIRED. The business method foo in FooBean invokes the business method bar in BarBean.

Given :

10. public class BarBean {

11. public void bar() {

12. throw new EJBException("unexpected error...");

13. }

Which statement is true about the result of this method invocation assuming execution reaches

Line 12?



Options are :

  • The container might roll back the transaction.
  • FooBean.foo method receives javax.ejb.EJBTransactionRolledbackException.
  • The BarBean bean instance is in the ready state for the next invocation.
  • FooBean.foo method receives javax.transaction.InvalidTransactionException.

Answer : FooBean.foo method receives javax.ejb.EJBTransactionRolledbackException.

Which two class types must be implicitly or explicitly denoted in the persistence.xml descriptor as

managed persistence classes to be included within a persistence unit? (Choose two.)

A. Entity classes

B. Interceptor classes

C. Embedded classes

D. Entity listener classes


Options are :

  • A,C
  • A,B
  • B,C
  • A,D

Answer : A,C

Given code snippets from two files:

7. public class Dog {

8. public void onMessage(Message m) { System.out.print("1 "); }

9. }

and

10. @MessageDriven

11. class MessageDog extends Dog implements MessageDrivenBean {

12. MessageDog(Message m) { System.out.print("2 "); }

13. }

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 MessageListener instead of MessageDrivenBean.


Options are :

  • A,B,C,F
  • D,B,C,F
  • A,B,C,D
  • A,D,C,F

Answer : A,B,C,F

310-091 Sun Certified Bus. Component Developer Java EE Test Set 9

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?



Options are :

  • The intercept method is NEVER invoked.
  • The client receives a return value of "zero".
  • The client receives a return value of "not zero".
  • The client receives a return value of "intercepted".

Answer : The client receives a return value of "intercepted".

The Java Persistent API defines certain rules for persistent entities. These rules are required by

the persistent provider to manage entities at runtime. Which statement is correct, assuming NO

mapping descriptor is used?



Options are :

  • A field without a transient modifier must be annotated as @Persistent to be stored in the database.
  • A field without a transient modifier must be annotated as @Transient to NOT be stored in the database.
  • Entities must implement the interface PersistentEntity to be managed by the persistent provider.
  • Entities must extend a persistent base class.

Answer : A field without a transient modifier must be annotated as @Transient to NOT be stored in the database.

Consider a deep inheritance hierarchy consisting of Java Persistence entity classes, non-entities,

and mapped superclasses. Which statement is correct, assuming NO mapping descriptor is

present?



Options are :

  • The primary key must either be defined in the topmost entity class of the inheritance hierarchy or it can be defined in a superclass if this class is annotated as @MappedSuperclass.
  • An entity class must NOT be extended by a non-entity class.
  • Only the root class in an inheritance hierarchy can be annotated wtith @MappedSuperclass.
  • An entity class must NOT inherit from a non-entity class.

Answer : The primary key must either be defined in the topmost entity class of the inheritance hierarchy or it can be defined in a superclass if this class is annotated as @MappedSuperclass.

310-110 Sun Certified Mobile Application Developer for J2ME Set 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".


Options are :

  • B,D
  • B,C
  • C,D
  • B,A

Answer : B,D

Which method always throws an exception when invoked on a container-managed entity

manager?



Options are :

  • the flush method
  • the lock method
  • the close method
  • the clear method

Answer : the close method

Which statement describes a component definition that is allowed by the EJB 3.0 specification?



Options are :

  • A stateful session bean that is a Web service endpoint.
  • A message-driven bean that has one message listener interface and is a Web service endpoint.
  • A stateless session bean that has three local business interfaces and is a Web service endpoint.
  • A stateful session bean that has one remote business interface and is a Web service endpoint.

Answer : A stateless session bean that has three local business interfaces and is a Web service endpoint.

310-110 Sun Certified Mobile Application Developer for J2ME Set 11

A developer writes a stateful session bean called FooBean.

Which code can be inserted before Line 11 of the FooBean class to define a TYPE-level

environment dependency on a JMS Topic?

11. public class FooBean {

12.

13. public void foo() {}

14.

15. }



Options are :

  • @Resource private Topic topic;
  • @Resource(type=Topic.class)
  • @Resource(name="topicRef") private static Topic topic;
  • @Resource(name="topicRef", type=Topic.class)

Answer : @Resource(name="topicRef", type=Topic.class)

Given a stateless session bean with container-managed transaction demarcation, from which two

methods can a developer access another enterprise bean? (Choose two.)

A. bean constructor

B. Timeout callback method

C. PreDestroy lifecycle callback method

D. PostConstruct lifecycle callback method

E. business method from the business interface


Options are :

  • B,D
  • B,E
  • B,C
  • B,A

Answer : B,E

A developer is working on a user registration application using EJB 3.0. A business method

registerUser in stateless session bean RegistrationBean performs the user registration. The

registerUser method executes in a transaction context started by the client. If some invalid user

data causes the registration to fail, the client invokes registerUser again with corrected data using

the same transaction. Which design can meet this requirement?



Options are :

  • Have registerUser method throw javax.ejb.EJBTransactionRequiredException after registration fails.
  • Create an application exception with the rollback attribute set to false and have registerUser method throw it after registration fails.
  • Have registerUser method call EJBContext.setRollbackOnly() method after registration fails.
  • Have registerUser method throw EJBException without marking the transaction for rollback, after registration fails.

Answer : Create an application exception with the rollback attribute set to false and have registerUser method throw it after registration fails.

310-110 Sun Certified Mobile Application Developer for J2ME Set 12

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 a business method

on the enterprise bean? (Choose two.)

A. The Application Assembler has marked the enterprise bean method as unchecked.

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.


Options are :

  • A,B
  • A,D
  • C,B
  • A,C

Answer : A,B

Which statement about an entity instance lifecycle is correct?



Options are :

  • A managed entity instance is the instance associated with a persistence context.
  • A removed entity instance is NOT associated with a persistence context.
  • A detached entity instance is an instance with no persistent identity.
  • A new entity instance is an instance with a fully populated state.

Answer : A managed entity instance is the instance associated with a persistence context.

A developer wants to achieve the following two behaviors for an EJB 3.0 session bean:

(1) If the client calls a business method with a transaction context, the container will invoke the

enterprise bean's method in the client's transaction context.

(2) If the client calls a business method without a transaction context, the container will throw the

javax.ejb.EJBTransactionRequiredException.

Which transaction attribute should be used?



Options are :

  • REQUIRES_NEW
  • MANDATORY
  • SUPPORTS
  • NOT_SUPPORTED
  • REQUIRED

Answer : MANDATORY

310-110 Sun Certified Mobile Application Developer for J2ME Set 2

The deployment descriptor for a stateless session bean that uses the isCallerInRole method reads

as follows:

3. <security-role-ref>

4. <role-name>manager</role-name>

5. <role-link>humanresources</role-link>

6. <security-role-ref>

16. <security-role>

17. <description>

18. Is allowed to view and update all employee records.

19. </description>

20. <role-name>humanresources</role-name>

21. </security-role>

Which two roles are responsible for creating this deployment descriptor? (Choose two.)

A. Deployer

B. Bean Provider

C. System Administrator

D. Application Assembler


Options are :

  • B,C
  • B,A
  • C,D
  • B,D

Answer : B,D

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

Method M1=SUPPORTS

Method M2=REQUIRED

Method M3=NOT_SUPPORTED

Method M4=REQUIRES_NEW

And the following method invocation sequence:

Method M1 invokes Method M2

Method M2 invokes Method M3

Method M1 invokes Method M4

If Method M1 is invoked by a method that does NOT have a transaction context, which describes a

possible scenario?



Options are :

  • Method M1: new transaction Method M2: runs in same transaction as M1 Method M3: Container throws TransactionNotSupportedException
  • Method M1: no transaction Method M2: new transaction Method M3: Container throws TransactionNotSupportedException
  • Method M1: no transaction Method M2: Container throws EJBTransactionRequiredException
  • Method M1: no transaction Method M2: new transaction Method M3: no transaction Method M4: new transaction

Answer : Method M1: no transaction Method M2: new transaction Method M3: no transaction Method M4: new transaction

A developer is modifying an existing Java EE application that uses the JDBC API to access a

database. This code must be used but cannot be changed, and new code needs to be added that

uses the Java Persistence API.

Both parts of the code will execute in the same JTA transaction.

Which method of the EntityManager interface should the new code use to ensure that the data

read by JDBC statements includes the state of managed entities?



Options are :

  • Call lock at the beginning of each business method.
  • Call refresh on each changed entity.
  • Call flush at the end of each business method.
  • Call find before accessing any managed entity.

Answer : Call flush at the end of each business method.

310-110 Sun Certified Mobile Application Developer for J2ME Set 3

A developer wants to create a Java Persistence query that returns valid U.S. phone numbers

(formatted as "123-456-7890" or "800-RUN-EJB3") from a collection of differently formatted

international phone numbers. The developer needs only those numbers that begin with 303.

Which WHERE clause is correct?



Options are :

  • WHERE addr.phone LIKE '303%'
  • WHERE addr.phone LIKE '303-_-_'
  • WHERE addr.phone LIKE '303-%-%'
  • WHERE addr.phone LIKE '303-%%%-%%%%'
  • WHERE addr.phone LIKE '303-___-____'
  • WHERE addr.phone LIKE '303_'

Answer : WHERE addr.phone LIKE '303-___-____'

A developer writes an enterprise application and packages it into an enterprise archive (EAR).

The application contains one persistence unit with unit name "FooPU". The application also

contains an ejb-jar with one stateless session bean. Which code, when added to the stateless

session bean class, injects a container-managed persistence context at runtime?



Options are :

  • @PersistenceContext(unitName="persistence/FooPU") EntityManager em;
  • @PersistenceContext EntityManager em;
  • @Resource(unitName="FooPU") EntityManager em;
  • @PersistenceUnit(unitName="FooPU") EntityManager em;

Answer : @PersistenceContext EntityManager em;

310-110 Sun Certified Mobile Application Developer for J2ME Set 4

Which statement about the combination of mapping defaults, annotations, and XML descriptors is

correct?



Options are :

  • The mapping information for an entity class specified by annotations and in XML descriptors must be distinct.
  • Some annotations, like the @Entity annotation, must always be processed by the persistence provider.
  • If multiple entity listeners are defined, the order in which they are invoked can be defined or overwritten in the XML descriptor.
  • All mapping annotations must always be processed by the persistence provider.

Answer : If multiple entity listeners are defined, the order in which they are invoked can be defined or overwritten in the XML descriptor.

A Java EE 5 Application server has four different security realms for user management. One of the

security realms is custom made. This realm supports only individual user entries, no grouping of

users, and is used by the application. Which two statements are true? (Choose two.)

A. EJB developers cannot use the isCallerInRole method.

B. The annotation @RunAs("AAA") can still be used for this application.

C. All security roles need a role-link entry in the deployment descriptor.

D. All security roles can be mapped successfully to individual users in the realm.


Options are :

  • B,C
  • A,D
  • B,A
  • B,D

Answer : B,D

FooBean is an EJB 3.0 session bean that can make valid use of UserTransaction. Which is

guaranteed to work in an EJB container for FooBean to obtain the UserTransaction object?



Options are :

  • Perform JNDI lookup with name "java:/UserTransaction" on an InitialContext.
  • Invoke a method on a SessionContext that returns a UserTransaction object.
  • Use the @TransactionManagement annotation to inject an instance variable of type UserTransaction in a bean class.
  • Perform JNDI lookup with the name "jdbc/UserTransaction" on an InitialContext.

Answer : Invoke a method on a SessionContext that returns a UserTransaction object.

310-110 Sun Certified Mobile Application Developer for J2ME Set 5

A developer writes a session bean which uses several configurable constants. The constants are

all defined as String types in JNDI. This cannot be changed because existing code is using the

same JNDI information. One of the constants is a date, represented in string format. This date

constant is used in multiple business methods of this session bean, actually as a Date object.

Converting strings to dates is an expensive operation; therefore, the developer wants to do as little

converting as possible.

Which two scenarios can be used to prevent converting from String to Date in every business

method? (Choose two.)

A. Load the date string in an instance Date type variable by annotation of the instance variable

and let the container autoconvert it to a Date type automatically.

B. Load the date string in an instance String type variable by annotation of this instance variable

and convert it to a Date type object in the beans constructor.

C. Load the date string in an instance String type variable by annotation of this instance variable

and convert it to a Date type object in a @PostConstruct annotated method.

D. Load the date string in an instance Date type variable by annotation of a setter method that

takes a String and which carries out the conversion and assigns the value to the instance variable.


Options are :

  • A,D
  • C,B
  • C,D
  • C,A

Answer : C,D

A developer writes client code that runs in a Java EE container and accesses an EJB 3.0 stateful

session bean. Which three statements are correct? (Choose three.)

A. The client can obtain a reference to the bean's business interface through JNDI lookups.

B. The client can obtain a reference to the bean's business interface through dependency

injection.

C. If the client calls a business method after the bean instance has been removed an exception

will occur.

D. After obtaining a reference to the bean's business interface, the client must call the create

method before it may call business methods.

E. After the bean instance has been passivated, the client needs to re-obtain a reference to the

bean's business interface to activate the bean instance.


Options are :

  • A,B,D
  • D,B,C
  • A,B,C
  • A,B,E

Answer : A,B,C

A developer has obtained a container-managed entity manager in a stateless session bean. Which

two statements are correct? (Choose two.)

A. Invoking the flush method without a transaction will throw an exception.

B. Invoking the clear method without a transaction will throw an exception.

C. Invoking the persist method without a transaction will throw an exception.

D. Invoking the find method for an entity that does NOT exist will throw an exception.


Options are :

  • A,C
  • A,B
  • D,C
  • A,D

Answer : A,C

310-110 Sun Certified Mobile Application Developer for J2ME Set 6

A session bean calls the setRollbackOnly method on the EJBContext interface within a business

method with an active transaction. Which two are correct? (Choose two.)

A. The transaction timeout is immediately disabled.

B. The container will ensure that the transaction will never commit.

C. The bean must have started the current transaction for this to be legal.

D. The bean must have bean-managed transaction demarcation for this to be legal.

E. The bean must have container-managed transaction demarcation for this to be legal.


Options are :

  • B,E
  • B,D
  • B,C
  • B,A

Answer : B,E

Which two APIs must an EJB 3.0 container make available to enterprise beans at runtime?

(Choose two.)

A. The JXTA 1.1 API

B. The MIDP 2.0 API

C. The Java SE 6 API

D. The Java SE 5 JNDI API

E. The Java SE 5 JDBC API


Options are :

  • D,A
  • D,B
  • D,C
  • D,E

Answer : D,E

Given an EJB 3.0 JMS message-driven bean, which statement is true about its exception

handling?



Options are :

  • Its message listener method must NOT throw any checked exception.
  • Its message listener method can throw any checked exception that implements java.io.Serializable.
  • Its message listener method can throw any checked exception except java.rmi.RemoteException.
  • Its message listener method can throw java.rmi.RemoteException.

Answer : Its message listener method must NOT throw any checked exception.

310-110 Sun Certified Mobile Application Developer for J2ME Set 7

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions