Computer Knowledge

Java Enterprise and Web Technologies

2,279 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 java
  1. a web server

  2. an EJB container

  3. an application server

  4. a database server

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

To understand which component executes EJB components, we need to have knowledge about the architecture of Enterprise JavaBeans (EJB) and the roles of different servers in the execution process.

EJB components are server-side components that are used to implement business logic in Java EE applications. They are executed by an EJB container, which is responsible for managing the lifecycle, deployment, and execution of EJB components.

Now let's go through each option and explain why it is right or wrong:

A. a web server: This option is incorrect. A web server is responsible for handling HTTP requests and serving web pages. It does not execute EJB components.

B. an EJB container: This option is correct. An EJB container is specifically designed to execute EJB components. It provides services such as object pooling, concurrency management, security, and transaction management. The EJB container ensures that EJB components are executed in a managed environment.

C. an application server: This option is also correct. An application server is a runtime environment that provides various services to execute enterprise applications. It includes an EJB container as one of its components. The application server manages the execution of EJB components along with other components of the application.

D. a database server: This option is incorrect. A database server is responsible for storing and retrieving data. It does not execute EJB components.

Therefore, the correct answer is:

The Answer is: B. an EJB container

Multiple choice java
  1. javax.ejb.EnterpriseBean

  2. javax.ejb.SessionBean

  3. javax.ejb.MessageBean

  4. javax.ejb.EntityBean

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

Session Beans (stateful or stateless) are designed to encapsulate business logic and process state for a specific client session. Entity Beans (older EJB tech) represented persistent data. EnterpriseBean is a marker interface. MessageBean would handle messaging.

Multiple choice java
  1. An EJB handle is used to handle exceptions when accessing EJB objects.

  2. An EJB handle is used to store a reference to a specific EJB object.

  3. An EJB handle is part of the Home interface.

  4. An EJB handle is used for local references inside the EJB container.

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

To answer this question, the user needs to have knowledge of Enterprise JavaBeans (EJB) and how they are used in Java applications.

Now, let's go through each option and explain why it is right or wrong:

A. An EJB handle is used to handle exceptions when accessing EJB objects. This option is incorrect. An EJB handle is not used to handle exceptions. Exceptions in EJBs are typically handled using try-catch blocks or by declaring them in the method signature.

B. An EJB handle is used to store a reference to a specific EJB object. This option is correct. An EJB handle is used to store a reference to a specific EJB object. It allows the client to maintain a reference to an EJB object and use it to invoke methods on that object.

C. An EJB handle is part of the Home interface. This option is incorrect. An EJB handle is not part of the Home interface. The Home interface is used for creating and finding EJB objects, while the handle is used to store a reference to an existing EJB object.

D. An EJB handle is used for local references inside the EJB container. This option is incorrect. An EJB handle is not specific to local references inside the EJB container. It can be used for both local and remote references to EJB objects.

Therefore, the correct answer is:

The Answer is: B

Multiple choice java
  1. JNDI binding for local home interface

  2. Local home interface

  3. Home interface

  4. ejb-ref-type

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

When declaring an EJB local reference, you specify: the local home interface (B), the reference type (ejb-ref-type), and the JNDI binding name (A). You do NOT specify the (remote) home interface (C) because local references are exclusively for local interfaces - mixing local and remote in the same reference is invalid. Local references use LocalHome and Local (or LocalBusiness) interfaces only, not remote Home interfaces.

Multiple choice java
  1. ejbCreate()

  2. ejbPassivate()

  3. ejbStore()

  4. ejbSave()

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

For stateful session beans, ejbPassivate() serializes the bean to secondary storage (temporarily saving it), and ejbActivate() restores it. However, ejbStore() is the method that explicitly saves the bean's state to persistent storage during passivation or before container shutdown. ejbCreate() (A) is for initialization, not saving state. ejbPassivate() (B) triggers the passivation process but ejbStore() does the actual saving work. ejbSave() (D) doesn't exist in the EJB API.

Multiple choice java
  1. transactional information

  2. security information

  3. data source information

  4. timer service information

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

SessionContext provides transaction management (getUserTransaction, setRollbackOnly), security context (getCallerPrincipal, isCallerInRole), and timer service access. Data source references are obtained through JNDI lookups using resource references in the deployment descriptor, not through SessionContext methods.

Multiple choice java
  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.

Multiple choice java
  1. The ejbRemove() method of Person invokes the remove() method of Address.

  2. The ejbStore() method of Person invokes the ejbStore() method of Address.

  3. The ejbPassivate() method of Person invokes the ejbPassivate() method of Address.

  4. The ejbLoad() method of Person invokes the findByPrimaryKey() method of Address-Home.

  5. The ejbLoad() method of Person invokes the ejbLoad() method of Address.

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

In BMP with 1:1 composition, the Person must cascade delete to Address. This is implemented by having Person.ejbRemove() call Address.remove(). Additionally, Person.ejbLoad() must invoke Address.ejbLoad() to synchronize the dependent Address bean's state when Person is loaded, maintaining referential integrity.

Multiple choice java
  1. Using ejbSelect() methods in session beans for specifying the selection criteria for a list

  2. Using ejbSelect() methods within ejbHome methods to return entities

  3. Using ejbSelect() methods to access fields of a bean instance

  4. Using ejbSelect() methods to perform operations not specific to a entity instance

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

ejbSelect methods are query methods defined in the entity bean class but not exposed in home/remote interfaces. They perform database operations independent of a specific bean instance, often used within home methods (ejbHome) to return entity results or aggregate values.

Multiple choice java
  1. The native library directory in the classpath must be specified

  2. A message listener port must be defined

  3. The message listener service must be enabled

  4. A message passivation directory must be specified

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

A message-driven bean requires a message listener port (also called an activation spec or JMS listener) to be configured on the application server. This defines the JMS destination and connection factory the MDB will listen to. Without this configuration, the MDB cannot receive messages.

Multiple choice java
  1. static fields in the entity bean

  2. an abstract persistence schema

  3. EJB Query Language definitions in the deployment descriptor

  4. the persistence-type attribute in the deployment descriptor

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

In EJB 2.x, Container-Managed Persistence (CMP) fields are not declared as variables in the bean class. Instead, they are defined as virtual properties via abstract getter and setter methods. The actual mapping and field definitions are specified in the deployment descriptor's abstract persistence schema.

Multiple choice java
  1. declare the CMR member fields and add ejb-relationship definitions in the deployment descriptor

  2. implement the get/set methods for the CMR fields and add ejb-relationship definitions in the deployment descriptor

  3. implement the ejbLoad() and ejbStore() methods and add ejb-relationship definitions in the deployment descriptor

  4. declare abstract get/set methods for the CMR field and add ejb-relationship definitions in the deployment descriptor

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

In CMP entity beans, CMR (Container Managed Relationships) fields are declared as abstract accessor methods (get/set) in the bean class, not as concrete fields. The container generates the actual implementation. The relationship role mappings are defined in ejb-relationship-role elements of the deployment descriptor.

Multiple choice java
  1. Supports

  2. Never

  3. Required

  4. RequiresNew

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

When a session bean demarcates the transaction (using UserTransaction) and calls an entity bean, the entity bean should have transaction attribute 'Required' to ensure it joins the existing transaction context. 'Supports' would allow it to run non-transactionally, which could cause data inconsistency.