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 architecture
  1. True

  2. False

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

A single servlet instance typically handles multiple concurrent requests using a thread-per-request model. The container creates a thread for each request, all executing the same servlet instance's service() method. This makes servlets inherently multi-threaded.

Multiple choice technology architecture
  1. init()

  2. service()

  3. destroy()

  4. Above All

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

The servlet lifecycle consists of three main phases: initialization (init() called once), service (service()/doGet()/doPost() called per request), and destruction (destroy() called once before removal). All three are lifecycle methods, making 'Above All' the correct answer.

Multiple choice technology architecture
  1. True

  2. False

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

Servlets are inherently multi-threaded - a single servlet instance handles multiple concurrent requests, with each request processed in a separate thread. The servlet container manages this threading model automatically.

Multiple choice technology architecture
  1. getServletInfo()

  2. getInitParameters()

  3. getServletConfig()

  4. None

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

The init(ServletConfig) method receives the ServletConfig object as a parameter. The getServletConfig() method returns this ServletConfig object, which contains initialization parameters and servlet configuration. getServletInfo() returns servlet information (author, version etc.), not the config object. getInitParameters() is not a standard method - parameters are accessed via getInitParameter() on the config object.

Multiple choice technology architecture
  1. Java Server Pages

  2. Java Server Programming

  3. Java Service Pages

  4. Java Service Programming

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

JSP stands for Java Server Pages, a server-side technology that enables dynamic web content generation. It simplifies web development by allowing developers to embed Java code directly into HTML pages. The technology is specifically designed for creating platform-independent, dynamically generated web content.

Multiple choice technology architecture
  1. Apache Tomact

  2. Bea WebLogic

  3. Servlets

  4. JSP Engine

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

JSP requires a servlet container with a JSP engine to process and execute pages. Apache Tomcat and BEA WebLogic are application servers that include JSP engines. JSP Engine is a generic term for any container component that can process JSP files. Servlets are a technology, not an execution environment.

Multiple choice technology architecture
  1. useBean

  2. setProperty

  3. getProperty

  4. All

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

JavaBean standard actions in JSP include useBean (instantiate or locate a bean), setProperty (assign values to bean properties), and getProperty (retrieve property values). These three actions provide complete bean manipulation capability in JSP pages without requiring scriptlet code. They simplify working with JavaBeans through declarative syntax.

Multiple choice technology architecture
  1. jar

  2. war

  3. jar, war

  4. jar, war, ear

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

Web servers can deploy JAR files (as libraries or standalone apps) and WAR files (web applications). WAR files are specifically designed for web application deployment with web components. EAR files are for application servers, not basic web servers - they contain multiple modules (WARs, JARs) with deployment descriptors.

Multiple choice technology architecture
  1. Model – Java Class, JSP, View – HTML, Controller – Servlet

  2. Model – Java Class, View – JSP, Controller – Servlet

  3. Model – Java Class, View – JSP, Container – Servlet

  4. Model – Java Beans, View – JSP, HTML, Controller – Servlet, EJB

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

In the MVC (Model-View-Controller) pattern for Java web applications: Model represents the business logic and data (typically Java classes); View handles presentation (JSP pages for rendering HTML); Controller manages user interaction and coordinates Model and View (Servlets receive requests and delegate to appropriate components). Option A incorrectly places HTML as a separate component rather than what JSP generates. Option C is wrong because 'Container' is not an MVC role. Option D adds unnecessary complexity with EJB.

Multiple choice technology architecture
  1. GET

  2. POST

  3. PUT

  4. HEAD

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

To answer this question, the user needs to have a basic understanding of HTTP methods.

An HTTP method is a type of request that a client sends to a server to perform a specific action. HTTP defines several standard methods, each of which is designed to be used for different purposes.

A non-idempotent request is a request that changes the state of the server. This means that if the same request is made multiple times, the result may be different each time.

OPTIONS:

A) GET: This option is not correct. The GET method is used to retrieve data from the server and is considered idempotent. This means that multiple identical requests will return the same response every time.

B) POST: This option is correct. The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server. POST requests are non-idempotent, meaning that multiple identical requests will not produce the same response.

C) PUT: This option is not correct. The PUT method is used to replace all current representations of a target resource with the request payload. Like the POST method, PUT requests are non-idempotent.

D) HEAD: This option is not correct. The HEAD method is used to retrieve the headers that would be returned if the HEAD request's URL was instead requested with the GET method. The HEAD request is considered idempotent because it does not change the state of the server.

Therefore, the correct answer is:

The Answer is: B. POST

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().