Updated Java ASA MCQs with Answer


Java ASA Multiple Choice Questions | Java ASA Objective type questions | Java ASA Quiz with answer

Q1.Rohit wants to create an auto populated drop down box in purchase.jsp page. Help Rohit to implement a proper handler method in controller that can retrieve sports Type defined in DAO layer.Choose from below a valid option.

Ans – Create a method in the controller to invoke DAO layer method which returns the Map of Sports Type with @ModelAttribute annotation.

Q2- Rohit wants to display all the validation error messages in purchase jsp. Help
him to display those messages at the bottom of the page choose from below a valid
option assume the below tag lib directives are added in the JSP.
<%@taglib url=”http://www.springframework.org/tags/form” prefix=”form”%>
<%@taglib url=”http://www.springframework.org/tags/form” prefix=”spring”%>

ans –

<form:form method="POST" modelAttribute="bean" action="store.html">
<table border="3">
<!—Assume form elements are mentioned appropriately^
</table>
<spring:hadBindErrors name="bean">
<h3>AII Errors</h3>
<form:errors path="*" cssClass="error/>
</spring:hasBindErrors>
</form:form>

Q3- Rohit wants to externalize the validation error messages so he defined the messages in com/Accenture/lkm/resources/messages_en properties” file. Rohit to configure the message source bean in the context file by choosing a valid option from below.

ans –

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageS 
ource">
<property name="basename"
value="classpath.com/accenture/lkm/resources/messages_en*
/>
</bean>

Q4- Rohit wants to auto populate the items available for the selected sports type to the respectively drop down box. Assume he defined the respective method in the controller which can return Map. Rohit is supposed to bind the key as label attribute , value as value attribute in the drop down box. choose from below a valid option.

ans –

 <form:select path="items"> 
<form:option value="" label="select"/> 
<form:options items="${itemsList}"/> 
</form:select>

Q5-Rohit wants to navigate to success.jsp page on successful submission. Assume he wrote a handler method to return model and view with logical view name as success he needs to configure a view resolver bean in child configuration file to resolve the logical view name choose from below a valid option .

ans –

 <bean
class="org.springframework.web.servlet.view. Interna IResourceViewResolver"> 
<property name="prefix">
<value/WEB-INF/jspViews</value> 
</property>
<property name="suffix"> 
<value>.jsp</value> 
</property>
</bean>

Q6- Rohit wants to create a request handler method in controller that can handle customer request and send the response back to the customer. Help rohit to achieve this with a valid option given below.

A) create a request handler method in the controller to map the request using @RequestMapping annotation and return to the ModelAndView object.

Q7- Rohit wants to display the success message in success.jsp page as mentioned in requirement 2. Help him to display the purchase date in dd-mmm-yyyy pattern. Choose from below a valid option.

ans –

< %@taglib url="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 
<fmt:formatDate value="${date}" type="date" pattern="dd-MMM-yyyy" />

Q8- Rohit wants to receive the request from customers and forward those requests to othercomponents of the application.

Ans – B) configure the DispatcherServlet provided by Spring Framework which acts as a front controlle

Q9- Rohit wants to validate the quantity entered by the customer as mentioned in requirement 2.choose from the below valid options.

Ans – A) Add @Range (min-1, max=10 C) The request handler method should include @Valid to @ModelAttribute parameter.

Q10- Rohit deployed the application in the Apache tomcat serve. But he got an exception as

ans –


A ) Configure <context:component-scan base-package="com.accenture.lkm.dao"/> 
in the context configuration
C) Configure <mvc:annotation-driven/> in the child context configuration

Q11. Help Raghav to choose from below a valid option to be used in DAO layer so that boilerplate code can be reduced

Ans – (C) Spring JPA data

Q12. Which are the mandatory annotations Raghav should use in Patient class ?

Ans – (A) (©Entity (B) @ld

Q13. Meera is responsible for creating all the view pages. She wants to create a page

Ans – (Answer:- (B) Use Spring from tags

Q14. The Admin can get the details of the patients who have taken appointment a particular doctor

ans –

List<Patients> findByDoctorNameEquals(String name)

Q15. Raghav must pre-populate doctor’s name from Doctor table in a drop-down list when patient is booking appointments online .

Ans – (A) Use @ModelAttribute on the method in controller class which includes the service class method returning the doctors name from DAO layer.

Q16. Raghav has added a method to update the details of the patients as below

Ans:- (C) (©Modifying is not used on the method and no changes required in the method signature

Q17. Meera wants to render the model object on a view without trying to a specific new technology4And

Answer:- (A) configure ViewResolver in servlet/child web application context

Q18. Raghav Added the following method in service and DAO implementation classes to add patient’s info in database

Ans:- (A) addPatientlnDAO() method always executes in a new transaction rather than the transaction started in service layer of addPatientService() method

Q19. Help Raghav to select correct JPQL query to retrieve all the details of patient based on their name for the below

Ans:- (B) @Query(“Select p from Patients p where p.pName = ?100”)

Q20. Harry wants to validate the mandatory fields(email and title) of newPost.jsp as per therequirement

Ans:- (A) Add @NoNull annotation for email and the fields in the bean class (C) The request handler method should include @Valid annotation & @ mode I Attribute paramete

Q21. Harry needs to configure Dispatcher servlet in the deployment
descriptor(web.xml) for his app.

Ans:- (B) <servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springfra mework. web. servlet. DispatcherServlet</servlet- 
class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</s-n> 
<url-pattern>*.htm</u-p> 
</s-m>

Q22.Harry needs to mark postld field as primary key and the value for primary key column should be

Ans:- (C) @id @generatedValue(strategy= GenerationType.AUTO) private in postld;

Q23. Harry needs to define spring beans and dependencies using dependencyinjection annotations and

Ans:- (B) <context:component-scan base-package = "com.accenture" />

Q24. Harry wants to use spring declarative transaction using (©Transactional annotation.

Ans:- (A) <tx:annotation-driven transaction-manager="txManager"/>

Q25. To integrate framework with JPA and get complete support of transaction management

 <bean id - “ entityManagerFactory"
>
Class = "org. springframework. com.jpa.LocalContainerEntityManagerFactoryBean"
<I—Assume properties are assign property --> 
</bean>

Q26. Harry creates a method in controller class to redirect to new Post.jsp page .

<bean class =
"org.springfra mework. web. serve let. view. I nternalResourseViewResolver">
<property name = "prefix" value="/WEB-INF/" /> 
<property name = "suffix" value=".jsp" /> 
</bean>

Q27.Harry wants to create container managed Entity Manager for managing the entities and their

Ans:- (A and C) (A) @PersistenceContext
Private EntityManager entityManager;______
(C) @PersistenceContextType= PersistenceContextType.TRANSACTION 
Private EntityManager entityManager;

Q28. Harry need to write a JPQ.L query to count number of posts entered by user as mentioned

Ans:- (A and C)  (A) Add the below code in the DAO layer;
Query query=entityManager.createQuery("select count(*)") from 
Postentity m where m.email=email"};
(C) Add the below code in the entity Class 
@NamedQuery(
Name="countPostsByName";
Query="select count(*) from Post Entity m where m.email=email")

Q29. Harry added the spring MVC form select tag in newPost.jsp to auto populate the values in drop-

@ModelAttribute("themeMap")
Public Map<String, String> populate Theme    Exception { 
Map<String,String> themeMap = new HashMap<String,String>
themeMap.put("DJ", "Daily Journal");
themeMap.put("DU", "Dress Up");
themeMap.put("JB", "Joy the B...");
themeMap.put("NY", "The New Yorks"); 
return ThemeMap;}


Leave a Reply

Your email address will not be published. Required fields are marked *