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

The execution of the find method in the following code throws an exception:

11. em.find(Customer.class, custId);

12. //Where em is a reference to a extended scoped entity manager.

Which scenario can cause the exception?



Options are :

  • The data type of custId is NOT a valid type for the Customer entity primary key.
  • The entity corresponding to the requested primary key has been removed.
  • The find method was called without a transaction.
  • The entity corresponding to the requested primary key has been detached.

Answer : The data type of custId is NOT a valid type for the Customer entity primary key.

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

Given two entities with a many-to-many bidirectional association between them:

11. @Entity public class Employee {

12. Collection projects;

13. // more code here

14. }

and

11. @Entity public class Project{

12. Set<Employee> emps;

13. // more code here

14. }

What set of annotations correctly defines the association?



Options are :

  • @ManyToMany on the projects field, @ManyToMany(mappedBy="projects") on the emps field
  • @ManyToMany(mappedBy="emps") on the projects field, @ManyToMany on the emps field
  • @ManyToMany(targetEntity=Project.class) on the projects field, @ManyToMany(mappedBy="projects") on the emps field
  • @ManyToMany(targetEntity=Project.class) on the projects field, @ManyToMany on the emps field

Answer : @ManyToMany(targetEntity=Project.class) on the projects field, @ManyToMany(mappedBy="projects") on the emps field

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 :

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

The Java Persistence API defines the semantics of the remove operation and the entity lifecycle

states. Which statement is true when the remove method is invoked on an entity X?



Options are :

  • If X is a detached entity an IllegalArgumentException will be thrown.
  • If X is a new entity it will be removed from the database.
  • If X is a removed entity it becomes managed.
  • The remove method is always cascaded to related entities.

Answer : If X is a detached entity an IllegalArgumentException will be thrown.

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

Given:

11. @PersistenceContext EntityManager em;

12. public boolean test(Order o) {

13. boolean b = false;

14. o = em.merge(o);

15 em.remove(o);

16. o = em.merge(o);

17. b = em.contains(o);

18. return b;

19. }

Which statement is correct?



Options are :

  • The method will return FALSE.
  • The method will throw an exception.
  • The Order instance will be removed from the database.
  • The method will return TRUE.

Answer : The method will throw an exception.

Which two are programming restrictions in the EJB 3.0 specification? (Choose two.)

A. An enterprise bean must NOT attempt to load a native library.

B. An enterprise bean must NOT declare static fields as final.

C. An enterprise bean must NOT attempt to create a new security manager.

D. An enterprise bean must NOT propagate a RuntimeException to the container.

E. An enterprise bean must NOT attempt to obtain a javax.naming.InitialContext.


Options are :

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

Answer : A,C

Given :

public class MyException extends Exception { }

The business interface Foo declares a method work():

1. public void work() throws MyException;

The bean class FooBean contains the following:

10. @Stateless

11. @Remote(Foo.class)

12. public class FooBean {

13. public void work() throws MyException {

14. //do some work not shown here

15. throw new MyException();

16. }

Assuming there is no deployment descriptor, which statement is true when the work() method is

invoked by a client with an existing transaction context and execution reaches Line 15?



Options are :

  • The client receives javax.ejb.EJBTransactionRequiredException.
  • The container does not roll back the transaction.
  • The container marks the transaction for rollback by calling the EJBContext.setRollbackOnly method.
  • The client receives javax.ejb.EJBTransactionRolledbackException.

Answer : The container does not roll back the transaction.

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

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

handling?



Options are :

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

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

A developer has obtained a container-managed entity manager with transaction scoped

persistence context. Assume there is no persistence context associated with the entity manager.

When does a new persistence context begins?



Options are :

  • when the entity manager is created
  • when the entity manager is created in the scope of an active resource local transaction
  • when a JTA transaction begins
  • when the entity manager is invoked in the scope of an active JTA transaction

Answer : when the entity manager is invoked in the scope of an active JTA transaction

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 :

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

Answer : B,E

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

OldBarBean is a stateless session bean written to the EJB 2.1 API with remote home interface.

OldBarHome and remote component interface OldBar. FooBean is a stateless session bean

written to the EJB 3.0 API.

OldBarBean and FooBean are the only EJBs packaged in the ejb-jar. The FooBean portion of the

ejb-jar.xml also declares an ejb-ref whose ejb-ref-name is ejb/oldBar. The ejb-ref is linked to

OldBarBean. There are no other ejb dependencies defined.

A business method foo in FooBean needs to access OldBarBean.

Which is portable code to achieve this goal?



Options are :

  • public void foo() { try { InitialContext ic = new InitialContext(); Object obj = ic.lookup("ejb/oldBar"); OldBarHome oldBarHome = (OldBarHome) PortableRemoteObject.narrow(obj, OldBarHome.class); OldBar oldBar = oldBarHome.create();
  • @Remote private OldBar oldBar;
  • public void foo() { try { InitialContext ic = new InitialContext(); OldBarHome oldBarHome = (OldBarHome) ic.lookup("ejb/oldBar"); OldBar oldBar = oldBarHome.create();
  • @EJB private OldBarHome oldBarHome; public void foo() { try { OldBar oldBar = oldBarHome.create();

Answer : @EJB private OldBarHome oldBarHome; public void foo() { try { OldBar oldBar = oldBarHome.create();

Which statement about the JoinTable annotation is true?



Options are :

  • If the name attribute is not specified it is derived from the names of the primary keys of the two entities involved in the association.
  • It must be applied to a unidirectional many-to-one association.
  • It can be applied to the owning side of a many-to-many association.
  • It must be applied to the owning side of a unidirectional one-to-many association.

Answer : It can be applied to the owning side of a many-to-many association.

The execution of the find method in the following code throws an exception:

11. em.find(Customer.class, custId);

12. //Where em is a reference to a extended scoped entity manager.

Which scenario can cause the exception?



Options are :

  • The entity corresponding to the requested primary key has been removed.
  • The find method was called without a transaction.
  • The data type of custId is NOT a valid type for the Customer entity primary key.
  • The entity corresponding to the requested primary key has been detached.

Answer : The data type of custId is NOT a valid type for the Customer entity primary key.

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

A developer is implementing an EJB 3.0 JMS message-driven bean with bean-managed

transactions. Which two statements are true? (Choose two.)

A. The message receipt is part of the user transaction.

B. Message acknowledgement is automatically handled by the container.

C. Messages are always processed in the order they were sent to the queue.

D. Two messages read from the same queue may be processed at the same time within the same

EJB container.


Options are :

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

Answer : B,D

Which two are true about the Java EE 5 client-view of a message-driven bean? (Choose two.)

A. References to message destinations can be injected.

B. As of EJB 3.0, 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.


Options are :

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

Answer : A,D

Given:

11. @PersistenceContext EntityManager em;

12. public boolean test(Order o) {

13. boolean b = false;

14. o = em.merge(o);

15 em.remove(o);

16. o = em.merge(o);

17. b = em.contains(o);

18. return b;

19. }

Which statement is correct?



Options are :

  • The Order instance will be removed from the database.
  • The method will throw an exception.
  • The method will return FALSE.
  • The method will return TRUE.

Answer : The method will throw an exception.

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

Given the method invocation sequence:

Method 1 calls Method 2

Method 2 calls Method 3

Method 1 calls Method 4

And the transaction scope:

Method 1: Transaction A

Method 2: Transaction A

Method 3: Transaction A

Method 4: Transaction B

Assuming Method 1 is invoked by a client without an existing transaction context, which set of

transaction attributes will support this scope?



Options are :

  • Method 1: REQUIRES_NEW Method 2: MANDATORY Method 3: SUPPORTS Method 4: SUPPORTS
  • Method 1: NEVER Method 2: SUPPORTS Method 3: REQUIRED Method 4: REQUIRES_NEW
  • Method 1: MANDATORY Method 2: REQUIRED Method 3: SUPPORTS Method 4: REQUIRES_NEW
  • Method 1: REQUIRES_NEW Method 2: MANDATORY Method 3: SUPPORTS Method 4: REQUIRES_NEW

Answer : Method 1: REQUIRES_NEW Method 2: MANDATORY Method 3: SUPPORTS Method 4: REQUIRES_NEW

Which statement about entity manager is true?



Options are :

  • An entity manager injected into session beans can use either JTA or resource-local transaction control.
  • A container-managed entity manager must be a JTA entity manager.
  • An entity manager obtained through resource injection in a stateful session bean can use a resource-local EntityTransaction for transaction control.
  • An entity manager created by calling the EntityManagerFactory.createEntityManager method always uses JTA transaction control.

Answer : A container-managed entity manager must be a JTA entity manager.

Bean Provider has been asked to write a stateless session bean, MyBean with a single method

breakout. A System Administrator guarantees that all clients accessing the bean will be identified

by mutual SSL authentication. The Bean Provider's task is to ensure that breakout always logs

identity information of the client that invoked it. Which solution would satisfy this requirement?



Options are :

  • Use the isCallerInRole method on an injected SessionContext to determine the required information.
  • Ensure that the breakout method is appropriately annotated with @RolesAllowed.
  • Access the identity information in the X.509 certificate used to authenticate the user from within breakout.
  • Use the getCallerPrincipal method on an injected SessionContext to determine the required information.

Answer : Use the getCallerPrincipal method on an injected SessionContext to determine the required information.

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

A developer writes two session beans which cooperate. The first session bean, ShoppingCart,

collects orders and is implemented as a stateful session bean. The second session bean,

CalculateDiscount, is implemented as a stateless session bean and runs on a different server.

ShoppingCart contains the method getTotalPrice, which calculates the total price of the order in

the ShoppingCart, including discounts. Discounts are calculated by CalculateDiscount using the

information on the ShoppingCart bean, combined with data from a database. Which scenario can

accomplish this?



Options are :

  • The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean. CalculateDiscount accesses the ShoppingCart instance by JNDI lookup.
  • The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean passing its reference obtained from the SessionContext.getBusinessObject method.
  • The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean passing the this reference.
  • The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean. CalculateDiscount accesses the state of ShoppingCart by dependency injection.

Answer : The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean passing its reference obtained from the SessionContext.getBusinessObject method.

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 :

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

Answer : B,C

Given:

10. @Stateless

11. public void SecureBean01 implements Secure01 {

23. @AllowRoles("ADMIN")

24. public void methodA() {}

10. @Stateless

11. public void SecureBean02 implements Secure02 {

23. @AllowRoles("administrator")

24. public void methodB() {}

Which deployer action permits a user authenticated as "John" to call both methodA on

SecureBean01 and methodB on SecureBean02?



Options are :

  • The deployer defines a common role and maps role "ADMIN" and role "administrator" using security-role-ref entries to this role. This common role is mapped to user "John".
  • The deployer maps both role "ADMIN" and role "administrator" to user "John".
  • The deployer replaces "administrator" by "ADMIN" in the source code of SecureBean02 and maps "ADMIN" to user "John".
  • The deployer overrides the method permission of SecureBean02. methodB in the ejb-jar.xml deployment descriptor and maps "ADMIN" to user "John".

Answer : The deployer maps both role "ADMIN" and role "administrator" to user "John".

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

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 :

  • Create an application exception with the rollback attribute set to false and have registerUser method throw it after registration fails.
  • Have registerUser method throw EJBException without marking the transaction for rollback, after registration fails.
  • Have registerUser method throw javax.ejb.EJBTransactionRequiredException after registration fails.
  • Have registerUser method call EJBContext.setRollbackOnly() method 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 Java Persistence query uses the aggregate function correctly, assuming that chairs field is

of type int?



Options are :

  • SELECT c FROM Chair c WHERE LOCATE (c.type, 'lazyboy') > -1
  • SELECT r FROM Room r WHERE r.chairs > AVG(r.chairs)
  • SELECT ANY(r.chairs) FROM Room r
  • SELECT NEW Integer(MAX(r.chairs)) FROM Room r

Answer : SELECT NEW Integer(MAX(r.chairs)) FROM Room r

A developer wants to create a Java Persistence query to perform a bulk update operation on five

different entity classes. All of these classes have a field called name. These classes have the

following relationships:

Harrier extends Dog and Dog extends Animal

Vet extends Doctor

What is the minimum possible number of operations required to change the value of the name

field for all of the entities in all five classes?



Options are :

  • 5
  • 2
  • 4
  • 3
  • 1

Answer : 2

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

A developer writes a stateless session bean with a constructor, a PostConstruct method, a

PreDestroy method, and this business method:

11. public String hello() {

12. return "hello";

13. }

The container invokes the hello method on an instance of the bean. Which is true about that bean

instance when control reaches Line 12?



Options are :

  • The constructor has NOT been invoked.
  • The PostConstruct method has been invoked.
  • Both the PostConstruct and PreDestroy methods have been invoked.
  • The PreDestroy method has been invoked.

Answer : The PostConstruct method has been invoked.

A session bean's business method throws an exception during execution. Which two are

responsibilities of the Bean Provider when throwing the exception? (Choose two.)

A. For application exceptions, ensure that if the current transaction commits there will be no loss

of data integrity.

B. For application exceptions, ensure that the current transaction will commit.

C. For system errors, when the client is remote, throw a java.rmi.RemoteException that wraps the

original exception.

D. For checked exceptions from which the bean cannot recover, throw an EJBException that

wraps the original exception.


Options are :

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

Answer : A,D

A developer wants to create a JMS message-driven bean that responds to javax.jms.TextMessage

messages. Which two statements are true? (Choose two.)

A. The developer must implement the ejbCreate method.

B. The developer does NOT need to create a business interface for the bean.

C. The developer must implement a method that declares javax.jms.TextMessage as an

argument.

D. The message-driven bean class must implement methods of the javax.jms.MessageListener

interface.

E. The message-driven bean class must implement methods of the javax.ejb.MessageDrivenBean

interface.


Options are :

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

Answer : B,D

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

Given:

A session bean Foo uses container-managed transactions

The container throws a javax.transaction.TransactionRolledBackException when the doStuff

method runs

Which transaction attribute can the doStuff method have for this to occur?



Options are :

  • REQUIRES_NEW
  • NEVER
  • NOT_SUPPORTED
  • MANDATORY

Answer : MANDATORY

According to the Java Persistence API, a managed entity instance X becomes removed by

invoking the remove method on it or when it is a target of a cascaded remove operation. Which

statement is true?



Options are :

  • If X is a new entity the remove operation is cascaded to entities referenced by X.
  • A removed entity X will be guaranteed to be removed from the database when the remove method returns.
  • After an entity has been removed its state will be restored to the Java defaults.
  • If a detached entity Y references X the IllegalStateException will be thrown.

Answer : If X is a new entity the remove operation is cascaded to entities referenced by X.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions