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

A developer creates the following session bean:

10. @Stateless

11. @RolesAllowed("SECRET")

12. public class MyBean implements MyInterface {

13. public void methodA() {}

14. @PermitAll

15. public void methodB() {}

16. @DenyAll

17. public void methodC() {}

18. }

No deployment descriptor is supplied. Which two statements are true? (Choose two.)

A. A user in the role "SECRET" will be able to access all of the methods.

B. A user in the role "FOO" will be able to access methodA and methodB.

C. A user without any role will be able to access methodB but NOT methodA.

D. A user in the role "SECRET" will be able to access methodA and methodB.

E. A user in the role "SYSADM" will be able to access methodA, methodB, and methodC.


Options are :

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

Answer : C,D

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

An enterprise developer has received ejb-jars from multiple Bean Providers and wants to combine

them into a single ejb-jar as well as altering the method permissions on some of the beans without

recompiling any of the code contained in the ejb-jar. Which is correct?



Options are :

  • Either a Deployer or System Administrator role may perform this task.
  • Application Assembler is the most appropriate role to perform this task.
  • This problem cannot be solved using an EJB 3.0-compliant approach.
  • Bean Provider is the only role that can perform this task.
  • Deployer is the most appropriate role to perform this task.

Answer : Application Assembler is the most appropriate role to perform this task.

A Java EE 5 application contains a session bean which uses a security role USER. A group called

people is defined in 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.


Options are :

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

Answer : B,C

A developer wants to create a Java Persistence query that will include a subquery. Which three

are true? (Choose three.)

A. Subqueries can be used in a FROM clause.

B. Subqueries can be used in a WHERE clause.

C. The ANY expression can be used only with a subquery.

D. The EXISTS expression can be used only with a subquery.

E. The MEMBER expression can be used only with a subquery.


Options are :

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

Answer : B,C,D

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

A developer wants to perform programmatic access control inside EJB 3.0 session beans. This is

needed because some permissions can be determined only at application runtime. Which method

achieves this goal?



Options are :

  • javax.interceptor.InvocationContext.getTarget()
  • javax.ejb.EJBContext.getRollbackOnly()
  • java.lang.SecurityManager.checkAccess(Thread t)
  • javax.servlet.http.HttpServletRequest.getUserPrincipal()
  • javax.ejb.SessionContext.isCallerInRole(String roleName)

Answer : javax.ejb.SessionContext.isCallerInRole(String roleName)

A developer wants to implement a relationship between Company and Department entity classes.

Every department belongs to one company, and one company has several departments. In this

application it is essential to quickly determine which company a department belongs to and to also

easily access all departments of a given company. Which two declarations provide a solution to

these requirements? (Choose two.)

A. In class Department:

@ManyToOne

private Company company;

B. In class Department:

@OneToMany

private Company company;

C. In class Department:

@OneToMany(mappedBy="department")

private Collection<Company> companies;

D. In class Company:

@ManyToOne(mappedBy="company")

private Collection<Department> departments;

E. In class Company:

@OneToMany(mappedBy="company")

private Collection<Department> departments;


Options are :

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

Answer : A,E

A developer's objective is to end the persistence context associated with an application-managed

entity manager. Which statement is correct?



Options are :

  • Invoke the flush method of the entity manager.
  • Invoke the close method of the entity manager.
  • Invoke the clear method of the entity manager.
  • Invoke the remove method of the entity manager.

Answer : Invoke the close method of the entity manager.

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

The Java Persistence API defines EntityTransaction interface. Which statement is correct?



Options are :

  • It is used to control transactions on JTA entity managers.
  • All methods of this interface will throw IllegalStateException if a transaction is NOT active.
  • Calling getTransaction method on a closed entity manager will throw an IllegalStateException.
  • It is used to control transactions on resource-local entity managers.

Answer : It is used to control transactions on resource-local entity managers.

A User entity is in a one-to-many relationship with a Book entity. Assume that a developer has a

function fetchBook(String title) that fetches a Book entity with the given title title. Also assume that

the developer has an entity manager em. Which query can be used to return the user that holds

the book titled "Java"?



Options are :

  • em.createQuery("SELECT u FROM User u where :great IN u.books.title").setParameter("great","Java")
  • em.createQuery("SELECT u FROM User u where :great IN u.books").setParameter("great",fetchBook("Java"))
  • em.createQuery("SELECT u FROM User u where :great MEMBER OF u.books").setParameter("great",fetchBook("Java"))
  • em.createQuery("SELECT u FROM User u where :great MEMBER OF u.books.title").setParameter("great","Java")

Answer : em.createQuery("SELECT u FROM User u where :great MEMBER OF u.books").setParameter("great",fetchBook("Java"))

A developer is implementing an EJB 3.0 message-driven bean that will be associated with a JMS

topic. The bean must NOT miss any messages published to the topic, even if the EJB server is

down for some time. Which is correct?



Options are :

  • Clients must take care of resending messages to the topic in case of missing message acknowledgements.
  • The developer should set the activation config property subscriptionDurability to value NonDurable.
  • The developer does NOT need to do anything, because as long as the EJB server is down no client can publish messages to the topic.
  • The developer should set the activation config property subscriptionDurability to value Durable.

Answer : The developer should set the activation config property subscriptionDurability to value Durable.

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

Which two can be specified by both the Bean Provider and the Application Assembler? (Choose

two.)

A. security roles

B. enterprise bean type

C. transaction attributes

D. session bean's state-management type

E. enterprise bean's remote home interface

F. enterprise bean's local business interface


Options are :

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

Answer : A,C

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



Options are :

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

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

A developer wants to create a portable EJB 3.0 application that includes the following class

definition for the Entity Account:

11. @Entity

12. @EntityListeners(com.acme.AlertMonitor.class)

13. public class Account {

14. // more code here

15. @PrePersist

16. protected void validateCreate() {/* more code here */}

17. }

Which statement is correct?



Options are :

  • Methods of the class com.acme.AlertMonitor annotated with callback annotations must take an Object or Account instance as the only argument.
  • The above class definition is NOT correct. An entity cannot define a callback method like PrePersist and use the EntityListeners annotation at the same time.
  • The validateCreate method can invoke the EntityManager.flush operation.
  • The validateCreate method may NOT throw runtime exceptions.

Answer : Methods of the class com.acme.AlertMonitor annotated with callback annotations must take an Object or Account instance as the only argument.

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

Given the following stateless session bean implementation classes:

10. @TransactionAttribute(TransactionAttributeType.MANDATORY)

11. public class MySuper {

12. public void methodA() {}

13. public void methodB() {}

14. }

10. @Stateless

11. public class MyBean extends MySuper implements MyInt {

12. public void methodA() {}

13.

14. @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

15. public void methodC() {}

16. }

10. @Remote()

11. public interface MyInt {

12. public void methodA();

13. public void methodB();

14. public void methodC();

15. }

Assuming no other transaction-related metadata, what are the transaction attributes of methodA,

methodB, and methodC respectively?



Options are :

  • REQUIRED, REQUIRES_NEW, and REQUIRES_NEW
  • MANDATORY, MANDATORY, and REQUIRES_NEW
  • REQUIRED, MANDATORY, and REQUIRES_NEW
  • MANDATORY, MANDATORY, and MANDATORY

Answer : REQUIRED, MANDATORY, and REQUIRES_NEW

A Java Persistence application uses entities mapped to tables from two datasources in the same

transaction. What statement is correct?



Options are :

  • This is NOT possible.
  • The entities must be packaged using two different persistence.xml files.
  • The entities must be packaged into two persistence units.
  • The entities can be packaged into a single persistence unit

Answer : The entities must be packaged into two persistence units.

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.Serializable {

12. int a;

13. }

Method foo is implemented within 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.println(data.a);

What is the value of data.a when control reaches Line 14 of the client ?



Options are :

  • 0
  • 1
  • 2
  • 5

Answer : 1

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

The Java Persistence API defines a notion of propagation of a persistence context. Which

statement is correct?



Options are :

  • Persistence context propagation results in cloning of all managed instances for use by another instance of an entity manager.
  • Persistence context propagation avoids the need for the application to pass references of entity manager instances.
  • Persistence context propagation is NOT supported for message-driven beans.
  • Persistence context propagation is supported for any type of an entity manager.

Answer : Persistence context propagation avoids the need for the application to pass references of entity manager instances.

A developer wants to create a portable EJB 3.0 application that includes the following class

definition for the Entity Account:

11. @Entity

12. @EntityListeners(com.acme.AlertMonitor.class)

13. public class Account {

14. // more code here

15. @PrePersist

16. protected void validateCreate() {/* more code here */}

17. }

Which statement is correct?



Options are :

  • The validateCreate method can invoke the EntityManager.flush operation.
  • The validateCreate method may NOT throw runtime exceptions.
  • Methods of the class com.acme.AlertMonitor annotated with callback annotations must take an Object or Account instance as the only argument.
  • The above class definition is NOT correct. An entity cannot define a callback method like PrePersist and use the EntityListeners annotation at the same time.

Answer : Methods of the class com.acme.AlertMonitor annotated with callback annotations must take an Object or Account instance as the only argument.

Which three statements are true about EJB 3.0 containers? (Choose three.)

A. Remote argument passing semantics conform to Java RMI-IIOP.

B. The JAXB 2.0 API is guaranteed to be available for all bean types.

C. The Java 2D API is guaranteed to be available for session beans.

D. javax.naming.InitialContext is guaranteed to provide a JNDI name space.

E. The Java Telephony API is guaranteed to be available for session and message beans.

F. javax.transaction.UserTransaction cannot be used by beans when bean-managed transaction

demarcation is used.


Options are :

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

Answer : A,B,D

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

A Reader entity has a one-to-many, bidirectional relationship with a Book entity. Two Reader

entities are persisted, each having two Book entities associated with them. For example, reader1

has booka and bookb, while reader2 has bookc and bookd. Which query returns a Collection of

fewer than four elements?



Options are :

  • SELECT r FROM Book b INNER JOIN b.reader r
  • SELECT r from Book b LEFT JOIN b.reader r LEFT JOIN FETCH r.books
  • SELECT b.reader FROM Book b
  • SELECT r FROM Reader r INNER JOIN r.books b

Answer : SELECT r FROM Reader r INNER JOIN r.books b

The bean class of an EJB Web service endpoint has one method annotated with @WebMethod.

Which two types can be legally returned from that method? (Choose two.)

A. java.util.Date

B. javax.ejb.Timer

C. an array of java.lang.String

D. an EJB 3.0 local business interface reference

E. an EJB 3.0 remote business interface reference


Options are :

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

Answer : A,C

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

The syntax of the ORDER BY clause is defined in the Java Persistence API as:

orderby_clause ::=ORDER BY orderby_item {, orderby_item}*

Which statement is correct about the use of ORDER BY clauses?



Options are :

  • The ordering must be specified if two or more orderby_item methods are provided.
  • Fields or properties of any type can be specified as an orderby_item.
  • Only literals can be specified as an orderby_item.
  • If two orderby_item methods are provided the left orderby_item has the higher precedence.

Answer : If two orderby_item methods are provided the left orderby_item has the higher precedence.

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.
  • Have registerUser method call EJBContext.setRollbackOnly() method after registration fails.
  • Have registerUser method throw EJBException without marking the transaction for rollback, after registration fails.
  • Create an application exception with the rollback attribute set to false and have registerUser method throw it after registration fails.

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

Which is the valid use of the javax.ejb.Init annotation?



Options are :

  • to annotate a bean class inside the ejb-jar archive to act as a bootstrap EJB which is loaded into the container before any other EJBs
  • to annotate a method in a stateful session bean class so that the container will invoke it after the EJB is deployed and started
  • to specify the correspondence of a method on a stateful session bean class with a create method of the adapted home interfaces
  • for a client to invoke the method annotated with @Init to initialize a newly created stateful session bean instance with user-specific data

Answer : to specify the correspondence of a method on a stateful session bean class with a create method of the adapted home interfaces

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

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

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

A developer has created an application-managed entity manager. Which statement is correct?



Options are :

  • A new persistence context begins when the entity manager is invoked in the context of a JTA transaction.
  • A new persistence context begins when the entity manager is created.
  • A new persistence context begins when the entity manager is invoked in the context of a resource-local transaction.
  • A new persistence context begins when a new JTA transaction begins.

Answer : A new persistence context begins when the entity manager is created.

Using bean-managed transaction demarcation, under which two circumstances must the container

roll back a transaction? (Choose two.)

A. A stateful session bean invokes UserTransaction.getRollbackOnly.

B. A stateful session bean throws an uncaught application exception from a business method.

C. A stateful session bean begins a transaction in a business method but does NOT complete it

before returning.

D. A stateless session bean begins a transaction in a business method but does NOT complete it

before returning.

E. A message-driven bean begins a transaction in a message listener method but does NOT

complete it before returning.


Options are :

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

Answer : D,E

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,C
  • A,B
  • D,B
  • A,D

Answer : A,B

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 :

  • 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.
  • Perform JNDI lookup with name "java:/UserTransaction" on an InitialContext.
  • Invoke a method on a SessionContext that returns a UserTransaction object.

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

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,C
  • B,D
  • B,A
  • A,D

Answer : B,D

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

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions