0

programming languages Online Quiz - 1

Description: programming languages Online Quiz - 1
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/18 Correct 0 Score 0

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

The variables local to the methods like service(), doPost() and doGet() are thread safe. True/False?

  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.

Which one of the following ServletRequest interface method returns more than one value associated with parameter?

  1. getParameterValue()

  2. getParameters()

  3. getParamValues()

  4. getParameterValues()


Correct Option: D

AI Explanation

To answer this question, we need to understand the difference between the methods getParameterValue() and getParameterValues() in the ServletRequest interface.

Option A) getParameterValue() - This option is incorrect because the getParameterValue() method returns a single value associated with a parameter. It does not return multiple values.

Option B) getParameters() - This option is incorrect because the getParameters() method returns a Map object containing all parameter names and their corresponding values. It does not specifically return multiple values associated with a single parameter.

Option C) getParamValues() - This option is incorrect because the getParamValues() method does not exist in the ServletRequest interface.

Option D) getParameterValues() - This option is correct because the getParameterValues() method returns an array of String objects containing all values associated with a parameter. If multiple values are associated with a parameter, this method allows you to retrieve all of them.

Therefore, the correct answer is option D. The getParameterValues() method returns more than one value associated with a parameter.

  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".


Correct Option: B

Your application supports multiple client types including HTTP clients. Your business layer is implemented using Enterprise Java Beans. Which of the following is best suited for maintaining client state?

  1. Cookies

  2. Entity Beans

  3. HttpSession attributes

  4. Stateful session beans

  5. URL Rewriting


Correct Option: D
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

Which enterprise bean type is defined without any client view interfaces?

  1. BMP Entity bean

  2. CMP Entity bean

  3. Stateful Session bean

  4. Stateless Session bean

  5. Message Driven Bean


Correct Option: E

AI Explanation

To answer this question, we need to understand the different types of enterprise beans in Java EE.

Option A) BMP Entity bean - This option is incorrect because BMP (Bean-Managed Persistence) Entity beans do have a client view interface.

Option B) CMP Entity bean - This option is incorrect because CMP (Container-Managed Persistence) Entity beans also have a client view interface.

Option C) Stateful Session bean - This option is incorrect because Stateful Session beans have a client view interface.

Option D) Stateless Session bean - This option is incorrect because Stateless Session beans also have a client view interface.

Option E) Message Driven Bean - This option is correct because Message Driven Beans are the only type of enterprise beans that can be defined without any client view interfaces. Message Driven Beans are used for asynchronous processing of messages received from a messaging system.

Therefore, the correct answer is option E) Message Driven Bean.

Which of the following is NOT an advantage of using the SessionFacade pattern?

  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


Correct Option: D

AI Explanation

To answer this question, you need to understand the SessionFacade pattern and its advantages. Let's go through each option to understand why it is correct or incorrect:

Option A) Hides model complexity from the client - This option is correct. One of the advantages of using the SessionFacade pattern is that it hides the complexity of the underlying model from the client. The client only needs to interact with the simplified interface provided by the SessionFacade.

Option B) Reduces network traffic - This option is correct. Another advantage of using the SessionFacade pattern is that it can help reduce network traffic. By encapsulating multiple operations into a single method call, the SessionFacade can minimize the number of network requests required.

Option C) Provides a simple interface to the client - This option is correct. The SessionFacade pattern provides a simple interface to the client. Instead of having to interact with multiple components or services directly, the client can use the SessionFacade as a single entry point for its operations.

Option D) Enables the client to control transactions - This option is incorrect. The SessionFacade pattern does not enable the client to control transactions directly. Instead, it encapsulates the transaction management logic within the SessionFacade itself. The client interacts with the SessionFacade, but it does not have control over the transaction boundaries.

The correct answer is D) Enables the client to control transactions. This option is incorrect because the SessionFacade pattern does not provide this advantage.

You want to locate an existing bean object but do not want to create a new instance, if an existing instance is not available. Which of the following bean attributes will you use in the jsp:useBean action?

  1. class

  2. type

  3. beanName

  4. class and type

  5. beanName and type


Correct Option: B

A container-managed persistence (CMP) entity bean A has a one-to-many unidirectional relationship (CMR) to another container-managed persistence (CMP) entity bean B. Which interface can expose the methods related to this relationship?

  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


Correct Option: A

Which method cannot be called by a stateful session bean using bean-managed transactions?

  1. getUserTransaction()

  2. getRollbackOnly()

  3. getStatus()

  4. None of these


Correct Option: B

AI Explanation

To answer this question, we need to understand the concept of bean-managed transactions in stateful session beans.

A stateful session bean is a type of Enterprise JavaBean (EJB) that maintains state or conversational context with the client. Bean-managed transactions (BMT) are a transaction management mechanism in EJB where the bean itself is responsible for managing the transaction boundaries.

In bean-managed transactions, the stateful session bean has control over the transaction flow and can start, commit, or rollback transactions explicitly.

Now let's go through each option to understand which method cannot be called by a stateful session bean using bean-managed transactions:

Option A) getUserTransaction() - This method returns the UserTransaction object, which allows the bean to control the transaction flow. Therefore, a stateful session bean can call this method.

Option B) getRollbackOnly() - This method is used to check if the current transaction has been marked for rollback. However, in bean-managed transactions, the stateful session bean is responsible for managing the transaction boundaries. Therefore, it cannot call this method to check the rollback status. Hence, this option is correct.

Option C) getStatus() - This method returns the current status of the transaction. In bean-managed transactions, the stateful session bean can call this method to check the status of the transaction.

Option D) None of these - This option is incorrect because option B (getRollbackOnly()) cannot be called by a stateful session bean using bean-managed transactions.

Therefore, the correct answer is B) getRollbackOnly(). This method cannot be called by a stateful session bean using bean-managed transactions.

Which of the following statements are true about the given method declaration? MyEJBObject createWithName(String name) throws CreateException, RemoteException

  1. It is declared in the local home interface of a stateful session bean.

  2. It is declared in the local home interface of a stateless session bean.

  3. It is declared in the remote home interface of a stateful session bean.

  4. It is declared in the remote home interface of a stateless session bean.


Correct Option: C

Which of the following combinations (Design Pattern - Functionality) regarding Design Patterns is correct?

  1. Business Delegate - Reduces the coupling between presentation-tier clients and business services.

  2. Data Access Object - Multiple View using the same model.

  3. MVC - Enables easier migration to different persistence storage implementation.

  4. Value Object - Reduces Network Traffic


Correct Option: D

Classes in Java cannot be made static.

  1. True

  2. False


Correct Option: B

In Static inner classes, the data members and the member functions are by default static.

  1. True

  2. False


Correct Option: B

Annonymous Inner classes are not possible within an Interface.

  1. True

  2. False


Correct Option: B

Classes can be created at the runtime. ie; A class during its execution can create another class at the runtime, give it methods,decide what parameters should go into those methods, which all interfaces it should implement etc...

  1. True

  2. False


Correct Option: A

We all know about the Dynamic dispatch in java. But if there is dynamic dispatch , then is there a Static dispatch also? (Easy One...)

  1. True

  2. False


Correct Option: A

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) True - This option is correct. In Java, static dispatch refers to the binding of a method call to its declaration at compile-time, based on the static type of the reference variable. This means that the method to be called is determined at compile-time and does not change at runtime.

Option B) False - This option is incorrect. Static dispatch does exist in Java.

The correct answer is A) True. This option is correct because static dispatch is a concept in Java where the method to be called is determined at compile-time based on the static type of the reference variable.

- Hide questions