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 technology programming languages
  1. Yes

  2. No

  3. May Be

  4. Can't Say

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

Technically yes, you can use a constructor for servlet initialization. However, the servlet specification recommends using init() because: (1) ServletConfig is not available in the constructor, (2) init() is called after the container completes initialization. Using constructor is possible but not standard practice.

Multiple choice technology programming languages
  1. Attributes of ServletContext

  2. Enterprise Java Beans

  3. Attributes of HttpSession

  4. Database

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

ServletContext attributes are stored in the JVM memory of a single container instance. In a distributed (clustered) web application, different JVMs run independently, so ServletContext attributes cannot be shared across them. Database, EJBs, and clustered HttpSessions can span JVMs.

Multiple choice technology programming languages
  1. session

  2. page

  3. application

  4. None of the above

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

The page implicit object is synchronized because it is a reference to the current servlet instance (this). In JSP, the page object represents the servlet itself, and the servlet instance is typically synchronized by the container to handle concurrent requests safely.

Multiple choice technology programming languages
  1. encodeURL

  2. encodeRedirectURL

  3. encodeSessionURL

  4. encodeSessionRedirectURL

  5. None of these

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

For sendRedirect(), you must use encodeRedirectURL(). The encodeURL() method is for regular URLs (links in HTML, form actions). encodeRedirectURL() specifically handles the session encoding rules required for redirect responses.

Multiple choice technology programming languages
  1. The bean method is throwing a checked exception and is configured with a transaction attribute of "Required".

  2. The bean method is throwing an unchecked exception and is configured with a transaction attribute of "Required".

  3. The bean does not throw an exception but is configured with a transaction attribute of "Mandatory".

  4. The bean method is throwing an unchecked exception and is configured with a transaction attribute of "Requires New".

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

If a transaction is initiated by a client (Required attribute) and the bean method throws a system (unchecked) exception, the EJB container intercepts it, rolls back the transaction, and throws a TransactionRolledBackException to the client. Checked exceptions do not cause auto-rollback by default.

Multiple choice technology programming languages
  1. Cookies

  2. Entity Beans

  3. HttpSession attributes

  4. Stateful session beans

  5. URL Rewriting

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

To maintain client state, the user needs to know the different options available and which option is best suited to the given scenario.

A. Cookies: Cookies are small text files that are stored on the client's computer. They can be used to store client state information, such as user preferences or session IDs. While cookies can be effective for maintaining state, they have some limitations, such as a limited storage capacity and the potential for security vulnerabilities.

B. Entity Beans: Entity beans are used to represent persistent data in a Java Enterprise Edition (JEE) application. They are not designed to maintain client state.

C. HttpSession attributes: HttpSession attributes are used to store client-specific information on the server side. They are associated with a particular user session and can be used to maintain client state across multiple requests. This makes HttpSession attributes a good option for maintaining client state in a JEE application.

D. Stateful session beans: Stateful session beans are designed to maintain state across multiple requests. They are associated with a particular client and can be used to store client-specific information. This makes stateful session beans a good option for maintaining client state in a JEE application.

E. URL Rewriting: URL rewriting is a technique for adding session IDs to URLs. This allows the server to identify the client and maintain state across multiple requests. While URL rewriting can be effective for maintaining state, it has some limitations, such as the potential for security vulnerabilities and the impact on URL readability.

Based on the given scenario, the best option for maintaining client state is D. Stateful session beans, as they are designed to maintain state across multiple requests and are associated with a particular client. Option C. HttpSession attributes is also a good option since it can be used to maintain client state across multiple requests. Option A. Cookies and option E. URL Rewriting can also be used to maintain state but are less suited to the given scenario.

The Answer is: D. Stateful session beans

Multiple choice technology programming languages
  1. BMP Entity bean

  2. CMP Entity bean

  3. Stateful Session bean

  4. Stateless Session bean

  5. Message Driven Bean

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

Message Driven Beans (MDBs) do not have client view interfaces (local or remote) because they do not receive direct synchronous calls from clients; instead, they act as asynchronous message consumers listening to JMS queues or topics.

Multiple choice technology programming languages
  1. Hides model complexity from the client

  2. Reduces network traffic

  3. Provides a simple interface to the client

  4. Enables the client to control transactions

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

The SessionFacade pattern hides complexity, provides a simple interface, and reduces network traffic by consolidating remote calls. However, it manages transactions on the server side; allowing the client to control fine-grained transactions contradicts the pattern's goal of abstraction.

Multiple choice technology programming languages
  1. class

  2. type

  3. beanName

  4. class and type

  5. beanName and type

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

When you use only the type attribute in jsp:useBean (without class or beanName), the container will look for an existing bean with the specified scope and type. If no existing bean is found, no new instance is created. This prevents instantiation when you only want to reference existing beans.

Multiple choice technology programming languages
  1. Only local interface of bean A

  2. Local interfaces of both beans A and B

  3. Only local home interface of bean A

  4. Local home interfaces of both beans A and B

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

In a unidirectional one-to-many CMR relationship where A owns the relationship to B, only bean A's local interface exposes the relationship methods (abstract getter/setter for the collection of B). Bean B has no knowledge of the relationship in unidirectional CMR.

Multiple choice technology programming languages
  1. getUserTransaction()

  2. getRollbackOnly()

  3. getStatus()

  4. None of these

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

In bean-managed transactions (BMT), stateful session beans manage their own transactions using UserTransaction methods. The getRollbackOnly() method is specific to container-managed transactions (CMT) and is not available in BMT context. getUserTransaction() and getStatus() are valid methods that can be called in BMT.