Computer Knowledge

Java Enterprise and Web Technologies

2,183 Questions

Java enterprise and web technologies questions focus on J2EE architecture, web services like SOAP, and servlet functionalities. These topics frequently appear in IT officer and specialist scale examinations. Regular practice ensures familiarity with enterprise application components.

HttpServlet methodsSOAP and web servicesEJB architecture rolesJ2EE componentsJSP servlet callingUDDI concepts

Java Enterprise and Web Technologies Questions

Multiple choice technology programming languages
  1. Once acquired, the home interface can be used only once.

  2. Each instance of a session bean has its own EJBHome object.

  3. The InitialContext must be narrowed before it can be used to get the

  4. Only remote clients need to get the home interface; local clients can get to the

  5. The local client can use the home interface to remove the bean instance.

  6. None of the above.

Reveal answer Fill a bubble to check yourself
F Correct answer
Explanation

All listed statements are FALSE: home interfaces can be reused (not single-use), session beans share one EJBHome (not per-instance), InitialContext narrowing is implementation-specific (not universal), and local clients DO need home interfaces for certain operations. Therefore F (None of the above) is correct.

Multiple choice technology programming languages
  1. L can pass its reference for B as a return value of a method call from R.

  2. R can pass its reference for B as a parameter in a method call to L.

  3. L cannot call methods on R. Doesn’t this depend on what R actually is, and where it is located

  4. L cannot call methods on B.

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

In EJB, remote references (R) can be passed to local clients (L) because remote interfaces are designed for network serialization. However, local references (L) cannot be passed to remote clients - local interfaces are not serializable and exist only within the same JVM. Option C correctly notes that whether L can call methods on R depends on R's actual type and location - this isn't about the local/remote client distinction but about the specific object being referenced. L can always call methods on B since that's its designated session bean.

Multiple choice technology programming languages
  1. A local client can remove the bean by invoking a method on the home interface

  2. Only a remote client can use the remove() method in the component interface.

  3. A stateful session bean is created by the container when the client invokes a create() method on the home interface.

  4. A create call from a client on a stateless session bean may not result in creating any instance of the bean. The container can create stateless session bean instances before any call from the client.

  5. A remove call from a client on a stateless session bean instance results in removing the instance.

Reveal answer Fill a bubble to check yourself
C,D Correct answer
Explanation

A stateful bean is instantiated when the client calls create on its home interface, and a stateless bean’s create call may not result in a new instance because the container can pool instances. The other statements misstate removal semantics or client capabilities.

Multiple choice technology programming languages
  1. setSessionContext()

  2. ejbCreate() method of a stateless session bean

  3. ejbCreate() method of a stateful session bean

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The isCallerInRole() method requires an established security context, which is available only after setSessionContext() has been called. For stateless session beans, ejbCreate() is called BEFORE setSessionContext(), so the security context isn't available yet. For stateful session beans, setSessionContext() is called BEFORE ejbCreate(), making the security context available. The setSessionContext() method itself cannot call isCallerInRole() because the context is still being initialized.

Multiple choice technology programming languages
  1. Call ejbCreate().

  2. Implement javax.ejb.SessionBean.

  3. Implement javax.ejb.EJBContext.

  4. Implement ejbRemove().

  5. Implement setSessionContext().

Reveal answer Fill a bubble to check yourself
A,C Correct answer
Explanation

The EJB container is responsible for calling lifecycle methods like ejbCreate() when a client invokes a create method. The container also provides implementations of context interfaces like EJBContext (specifically SessionContext for session beans). The bean developer is responsible for implementing the SessionBean interface, setSessionContext(), and ejbRemove() methods - these are part of the bean class code.

Multiple choice technology programming languages
  1. An ejbRemove() call from the container removes the bean instance and puts it out for the garbage collector.

  2. An ejbCreate() call is made by the container only when a client invokes a create method.

  3. You can get the security information about a client from inside the ejbCreate() method.

  4. The container will call the setSessionContext() method only once.

  5. All of the above.

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

Option A is incorrect because the container manages stateful session beans in a pool - ejbRemove() makes the instance eligible for pooling, not immediate garbage collection. Option B is incorrect because stateful session beans can be created through various means including dependency injection or lookups, not just explicit client create calls. Option C is incorrect because security context isn't available in ejbCreate() for stateless beans. Option D is correct - setSessionContext() is called exactly once per bean instance when it's first created.

Multiple choice technology programming languages
  1. ejbRemove()

  2. ejbPassivate()

  3. setSessionContext()

  4. ejbCreate()

  5. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

During setSessionContext(), the bean is still being initialized and doesn't have access to other beans or their methods. The security context and environment resources are not yet fully available. In ejbCreate(), ejbRemove(), and ejbPassivate(), the bean is fully initialized and can interact with other beans. This restriction applies specifically to the context initialization phase.

Multiple choice technology programming languages
  1. javax.ejb.NoSuchObjectLocalException for the local client

  2. javax.ejb.NoSuchObjectException for the remote client

  3. javax.ejb.RemoveException

  4. javax.ejb.ObjectNotFoundException

  5. java.rmi.NoSuchObjectException for the remote client

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

When a client invokes a session bean that no longer exists, the exception depends on the client type. Local clients receive javax.ejb.NoSuchObjectLocalException. Remote clients receive java.rmi.NoSuchObjectException (a RemoteException subtype). Option B's NoSuchObjectException and Option C's RemoveException are incorrect exception types. Option D's ObjectNotFoundException is typically for database operations, not EJB invocations.

Multiple choice technology programming languages
  1. ejbCreate()

  2. ejbActivate()

  3. create()

  4. setSessionContext()

  5. getRollbackOnly()

  6. getEJBHome()

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

The SessionContext interface defines methods for transaction control and EJB home access, including getRollbackOnly() and getEJBHome(). Lifecycle methods such as ejbCreate, ejbActivate, and setSessionContext belong to SessionBean or its ancestors, not SessionContext, so they are incorrect.

Multiple choice technology programming languages
  1. findAllCustomers(…)

  2. removeTheCustomer(…)

  3. createCustomer(…)

  4. create()

  5. retrieveCustData(…)

Reveal answer Fill a bubble to check yourself
A,B,C,D Correct answer
Explanation

EJB home interfaces for entity beans have strict naming conventions. Methods starting with 'create' (like createCustomer) are reserved for create methods. Methods starting with 'find' (like findAllCustomers) are reserved for finder methods. Method names like removeTheCustomer conflict with EQL reserved keywords. The method name 'create' alone is a reserved word in EJB context. Only retrieveCustData() doesn't violate these conventions.

Multiple choice technology programming languages
  1. One or more

  2. Zero or more

  3. Exactly one

  4. Zero

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

Entity bean home interfaces can have zero or more create methods. Unlike session beans which must have at least one create method, entity beans are not required to have any create methods - they can rely exclusively on finder methods to locate existing entities. When create methods are defined, there's no upper limit on how many can exist.

Multiple choice technology programming languages
  1. ObjectNotFoundException.

  2. An empty Collection will be returned.

  3. An entity would be created and a reference to that entity would be returned.

  4. EntityNotFoundException.

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

According to the EJB specification, finder methods returning a Collection must return an empty collection if no matching entities are found. ObjectNotFoundException is only thrown for single-object finder methods (like findByPrimaryKey) when a match is missing, while automatic entity creation never occurs on a failed lookup.

Multiple choice technology programming languages
  1. The entity bean instance is deleted.

  2. The entity in the database is deleted.

  3. Both the entity and the entity bean instance survive, but that entity bean instance does not represent that entity anymore.

  4. Nothing happens; the container simply ignores the call.

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

Calling remove() on an entity bean's component interface deletes the underlying entity from the database. The bean instance itself is not deleted - it's returned to the pool for reuse. Option C is incorrect because the entity is actually removed, not dissociated. Option D is incorrect because the remove operation is significant and not ignored.

Multiple choice technology programming languages
  1. You cannot write JDBC code in the bean class to make a connection and send queries to any database.

  2. You cannot write JDBC code in the bean class to change the values of virtual persistent fields of your bean.

  3. You can write JDBC code and get connected to any database you want.

  4. You can write JDBC code to read the virtual persistent fields, but you cannot change their values.

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

In Container-Managed Persistence (CMP), persistent fields are virtual and accessed via abstract getter and setter methods. The container manages their database synchronization, so you cannot write direct JDBC code to modify these virtual fields. While JDBC can be used for other database connections, direct manipulation of CMP-managed fields is strictly prohibited.

Multiple choice technology programming languages
  1. getEJBObject()

  2. getPrimaryKey()

  3. getEJBHome()

  4. getRollbackOnly()

  5. getUserTransaction()

Reveal answer Fill a bubble to check yourself
A,B,C,D Correct answer
Explanation

During ejbPostCreate, the entity bean's identity is fully established, meaning getEJBObject() and getPrimaryKey() can be safely called. getEJBHome() and transaction methods like getRollbackOnly() are also accessible. However, getUserTransaction() is invalid because entity beans must use container-managed transactions (CMT) and cannot use bean-managed transactions.