Multiple choice java

Client programs that access EJBs make use of the Java Naming and Directory Interface (JNDI). To get access to a Person entity bean, which methods can be used? (2 correct answers). Assume the following code is used to establish the initial context: Propert

  1. PersonHome ph = ctx.lookup("java:comp/env/ejb/Person");

  2. PersonLocalHome ph=(PersonLocalHome)ctx.lookup("java:comp/env/ejb/PersonLocalHome");

  3. PersonHome ph = ctx.lookup("java:comp/env/ejb/PersonHome");

  4. PersonHome ph = javax.rmi.PortableRemoteObject.narrow(ctx, PersonHome.class)

  5. PersonHome ph = (PersonHome)javax.rmi.PortableRemoteObject.narrow(ctx,PersonHome.class)

Reveal answer Fill a bubble to check yourself
B,E Correct answer
Explanation

For EJB 2.x, local home interfaces are looked up via JNDI and directly cast (option B). Remote home interfaces require PortableRemoteObject.narrow() for proper RMI/IIOP type narrowing (option E). The code is truncated but shows the correct narrow() pattern.

AI explanation

For a bean's local interface, JNDI lookup returns the object directly, so casting it straight to PersonLocalHome is all that's needed — no PortableRemoteObject.narrow() call. For the remote interface, however, RMI-IIOP requires PortableRemoteObject.narrow() to properly convert the returned stub before casting it to PersonHome; a plain cast on a remote lookup can fail across a network boundary. The other options either look up the wrong JNDI name or skip narrowing when it's required for a remote reference.