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 architecture
  1. HttpServletRequest getParameter(...) retrieves the parameter value from the request

  2. HttpServletResponse getAttribute(...) retrieves the attribute value from the response

  3. HttpServletResponse getParameter(...) retrieves the parameter value from the response

  4. HttpServletRequest setParameter(...) sets the parameter value to the request

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

HttpServletRequest.getParameter() retrieves request parameter values sent by the client (from query string or POST body). Option B is wrong because HttpServletResponse has no getAttribute() method - attributes are on requests, not responses. Option C is wrong because HttpServletResponse has no getParameter() - parameters belong to requests only. Option D is wrong because HttpServletRequest has no setParameter() method - request parameters are read-only once set by the client.

Multiple choice technology architecture
  1. sendURL()

  2. redirectURL()

  3. sendRedirect()

  4. getRequestDispatcher()

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

HttpServletResponse.sendRedirect(String URL) is the standard method to redirect the client to a different URL. This sends a 302 temporary redirect response to the browser, which then makes a new request to the target URL. Options A and B are non-existent methods. Option D (getRequestDispatcher) is for server-side forwarding/dispatching, not client-side redirection - it forwards the request without the client knowing.

Multiple choice technology architecture
  1. Write servlet code to extend ThreadSafeServlet.

  2. Have the servlet implement SingleThreadModel

  3. Synchronize the service method of the servlet

  4. Use local variables exclusively, and if you have to use instance variables, synchronize access to them.

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

Servlets are inherently multi-threaded - one instance serves multiple requests concurrently. The recommended approach is to use local variables (thread-safe by design since each thread has its own stack) and avoid instance variables. If instance variables are necessary, synchronize access to them. Option A is wrong - no such class exists. Option B (SingleThreadModel) is deprecated and inefficient - it creates problems without solving thread safety. Option C (synchronizing service()) serializes ALL requests, causing severe performance bottlenecks.

Multiple choice technology architecture
  1. A session whose timeout period has been set to -1 will never expire.

  2. A session will become invalid as soon as the user closes all the browser windows.

  3. A session will become invalid after a timeout period defined by the servlet container.

  4. A session may be explicitly invalidated by calling HttpSession.invalidateSession().

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

HttpSession invalidation is managed by the servlet container based on a configurable timeout period (default typically 30 minutes). The container checks session inactivity and invalidates sessions that exceed the timeout. Option A is wrong - timeout of -1 means no timeout limit, but session can still be invalidated when server restarts or explicitly. Option B is wrong - closing browser doesn't immediately invalidate session; the session cookie persists until it expires or is cleared. Option D has the wrong method name - the correct method is HttpSession.invalidate() not invalidateSession().

Multiple choice technology architecture
  1. URL rewriting may be used by a server as the basis for session tracking.

  2. SSL has a built-in mechanism that a servlet container could use to obtain data used to define a session.

  3. When using cookies for session tracking, the name of the session tacking cookie must be JSESSIONID.

  4. IF a user has cookies disabled in the browser, the container may choose to use a javax.servlet.httpCookielessHttpSession object to track the user's session.

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

Option D is FALSE (making it the correct answer to 'which is NOT true') because there is no such class as javax.servlet.http.CookielessHttpSession in the Servlet API. When cookies are disabled, containers use URL rewriting (appending the session ID to URLs) - they don't switch to a different HttpSession implementation class. Options A, B, and C are all TRUE statements: URL rewriting is a valid session tracking mechanism; SSL sessions can be used; and JSESSIONID is the standard cookie name (though containers can configure a different name).

Multiple choice technology architecture
  1. True

  2. False

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

Session attributes are shared across all servlets within the same ServletContext (web application). When you store an attribute in an HttpSession using setAttribute(), any other servlet in the same application can retrieve it using getAttribute() on the same session (identified by the same session ID). This sharing is a key purpose of session attributes - to maintain user-specific state across multiple servlets/JSPs in the application. Different ServletContexts have separate session scopes.

Multiple choice technology architecture
  1. req.getSession(false);

  2. req.getSession(true);

  3. both the above

  4. none of the above

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

HttpServletRequest.getSession(true) returns the current session or creates a new one if none exists. The boolean parameter 'create' controls this behavior: true means create if needed, false means return null if no session exists. Option A (getSession(false)) would return null instead of creating a session. The method getSession() with no arguments is equivalent to getSession(true) - it also creates sessions.

Multiple choice technology architecture
  1. They should be used for data that changes rarely.

  2. They can be accessed using ServletContext.getInitParameter()

  3. They can be accessed using ServletContext.getParameter()

  4. They should be used for data that is applicable to an entire web application.

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

Option C is FALSE (making it the correct answer to 'which is NOT true') because ServletContext has no getParameter() method - the correct method is getInitParameter(). Options A, B, and D are all TRUE: ServletContext init parameters are configured in web.xml, meant for data that rarely changes (like database connection strings), are application-wide (shared by all servlets), and are accessed using getInitParameter(String name).getParameter() methods exist on HttpServletRequest, not ServletContext.

Multiple choice technology architecture
  1. getMethod()

  2. getHeader()

  3. getCookies()

  4. getInputStream()

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

ServletRequest.getInputStream() is declared in the ServletRequest interface and returns a ServletInputStream for reading the request body as binary data. Options A, B, and C are wrong because getMethod(), getHeader(), and getCookies() are declared in HttpServletRequest (which extends ServletRequest), not in ServletRequest itself. ServletRequest contains fundamental methods like getParameter(), getAttribute(), getInputStream(), and getReader(), while HttpServletRequest adds HTTP-specific methods.

Multiple choice technology architecture
  1. getServletInfo()

  2. getInitParameters()

  3. getServletConfig()

  4. None

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

In the init(ServletConfig) method, the ServletConfig object is passed as a parameter and can be accessed directly. The getServletConfig() method returns this stored config object, which is useful in other methods throughout the servlet lifecycle. getServletInfo() returns servlet information (not config), and getInitParameters() is not a standard method.

Multiple choice technology architecture
  1. singleton

  2. Prototype

  3. request

  4. response

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

Spring defines five bean scopes: singleton (default), prototype, request, session, and global session. 'response' is NOT a valid scope in Spring - the option list includes singleton, prototype, and request, which ARE all valid Spring scopes, making 'response' the correct answer for what is NOT defined.

Multiple choice technology architecture
  1. Application scope

  2. Application Integration

  3. Application Context

  4. None

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

The ApplicationContext is Spring's bootstrap mechanism that loads all high-level entry-point objects required by your application. It provides configuration for the application, reads bean definitions, and assembles them at runtime. Application scope is a bean scope, and Application Integration is not a standard Spring term.

Multiple choice technology architecture
  1. Constructor Injection

  2. Setter Injection

  3. interface Injection

  4. None

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

Spring supports constructor injection (via dependencies in constructor), setter injection (via setter methods), and field injection (via annotations). Interface injection is NOT supported by Spring - it was part of early DI frameworks but Spring chose not to implement it, preferring the other three approaches.