Tag: programming languages

Questions Related to programming languages

  1. 1 can only be called with predecleration of complex_num

  2. 1 and 2 are same

  3. 2 can only be called with predecleration of complex_num

  4. 1 is reference to a subroutine


Correct Option: C
  1. Attributes of ServletContext

  2. Enterprise Java Beans

  3. Attributes of HttpSession

  4. Database


Correct Option: A

Can we call destroy() method on servlets from service method ?

  1. Yes

  2. No

  3. May be

  4. Cant Say


Correct Option: A
  1. session

  2. page

  3. application

  4. None of the above


Correct Option: B

Which of the following aren't the methods for state/session management in the context of Servlets?

  1. Http Redirects

  2. Hidden Variables

  3. Cookies

  4. Rewritten URLs

  5. Using HttpSession Interface


Correct Option: A
  1. True

  2. False


Correct Option: A
Explanation:

To solve this question, the user needs to know the basic concept of thread safety in Java and how it applies to local variables in methods like service(), doPost() and doGet().

The answer to this question is:

A. True

Explanation:

Local variables declared within a method are thread-safe because they are confined to the method and are not shared between threads. Each thread, when executing the method, will have its own copy of the local variables declared within the method. As a result, other threads cannot modify the values of these local variables, ensuring thread safety.

Therefore, the correct answer is option A, true.

You want to use URL rewriting to support client browsers, which do not use cookies. Which method will you use to attach the session id to a URL that is to be used for the sendRedirect() method of the HttpServletResponse?

  1. encodeURL

  2. encodeRedirectURL

  3. encodeSessionURL

  4. encodeSessionRedirectURL

  5. None of these


Correct Option: B

AI Explanation

To attach the session ID to a URL that is to be used for the sendRedirect() method of the HttpServletResponse, you can use the encodeRedirectURL method.

The correct answer is B) encodeRedirectURL.

Explanation for each option:

A) encodeURL - This method is used to encode the URL, including the session ID, if necessary. However, when using the sendRedirect() method, encodeRedirectURL should be used instead.

B) encodeRedirectURL - This method is used to encode the URL, including the session ID, if necessary, specifically for the sendRedirect() method.

C) encodeSessionURL - This method does not exist in the HttpServletResponse class.

D) encodeSessionRedirectURL - This method does not exist in the HttpServletResponse class.

E) None of these - The correct answer is B) encodeRedirectURL.

Therefore, the correct answer is B) encodeRedirectURL.