MCQ 3
MCQ 3
ANS: B
2.
ANS:B
Consider the code
Package com.accenture.lkm; Employee Address:Bangalore-Maharasthra
@Component(“address”)
Public class Address{
//common word (“Hyderabad- Telangana”)//
//common word (“Bangalore-Maharasthra”)//
3. ANS:A
Package com.accenture.lkm;
@Component(“employee”) /// common @Autowired,@Qualifier(“room1”),com
word(@Autowired,Gettors and Setters,UITester
_____Line1_____ _____Line2_____
_____Line3_____ House,room1,room2
ApplicationContext applicationContext=new
ClassPathXmlApplicationContext("classpath:com/accenture/lkm/reso
urce/my_springbean.xml");
Refer the Spring configuration code gievn
below:
1 @Configuration ApplicatonContext ctx=new
2 public class AppConfig { AnnotationConfigApplicationContext(AppConfig.class); Address
3 @Bean("address") address=(Address) ctx.getBean("address");
4 public address createAddress( ) {
5 Address address = new Address( ) :
6 return address ;
7}
8}
Identify the correct code to create spring
container object and get the address object
injected Choose the most appropriate option
7.
1 @Entity ANS:A
2 public class CustomerEntity{
3 @Id @Modifying
4 private int cid; @Query("delete from CustomerEntity & where k where
5 private String cname; k.credit*cname)
6 private double credit; int delete @Param(credit) double credit
7 // getter and setter methods
8.
Which of the following is/are CORRECT with ANS:B
respect to Spring transaction methods?
(i) If a method throws Only(i)
runtime/unchecked exception, then
rollback will be triggered implicity
(ii) (ii) If a method throws checked
exception, then rollback will be
triggered implicitly Choose the
most appropriate option
9.
1 ANS:A
2
3 @Transaction(value = "txManager", propogation =
4 Propogation.REQUIRES_NEW)
//Line-X
5 public Integer addEmployee AndDepartment(EmployeeBean
employeeBean, DepartmentBean departmentBean) throws
Exception {
6 int result = 0;
7 int deptId =
employeeDepartmentDAO.addDepartment(departmentBean);
8 employeeBean.setDepartmentCode(deptId);
9 result = deptId +
employeeDepartmentDAO.addEmployee(employeeBean);
10 return result;
11 }
10.
Which of the following statements is/are CORRECT with respect
to JSP? both (i) and (ii)
(i) Default scope of a variable is page
(ii) Session scope variable will be available in all JSP files if it is
accessed in a single session
(iii) JSTL codes are placed inside service() method of
translated servlet Choose the most appropriate option
11. ANS:A
From the Following identify two INCORRECT statements about I and ii only
ServletConfig Object
(i)it is not created for each servlet during servlet initialization (ii)it
will be available to all servlets of an application
(iii)Its lifetime ….object is destroyed
(iv)one object per servlet class
12.
Which object is created by web container for each Servlet during ANS:B
servlet initialization? ServletConfig
13.
Mr.john has been assigned the task of creating a servlet filter to ANS: A
log IP address of the computers ……servlet filters in web.xml file
14.
Blessie is a web developer wants to create a wep pageis a web
developer wants to create a web page which always lands in
portal.accenture.com, whenever user hits on welcome button response.sendRedirect("https:/portal.accenture.co
in index.html given below: index.html ----------------------- m");
MyServlet.java ---------------------------
@WebServlet(urlPatterns="/MyServlet) public class MyServlet
extends HttpServlet{ public static final long serialVersionUID = 1L;
public myServlet(){ super(); }
<meta charset="ISO-8859-1">
<title>Sample</title>
</head>
<body>
</body>
</html>
18.
1
Refer the folowing JSP pages
Header.jsp:
<%@ page language = "java" contentType="text/html; charset =
ISO-8859-1" pageEncoding = "ISO-8859-1" %> <!DOCTYPE html
PUBLIC "//W3C//DTD HTML 4.01 Transitional//EN"
"HTTP://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset =
ISO-8859-1">
<title> insert title here </title>
</head>
<body>
<h2> <font color="blue"> This is content of Header </font> </h2>
</body>
</html>
Footer.jsp
<%@ page languages = "java" contentType = "text html; charset =
ISO-8859-1" %>
19.
Refer the incomplete code given below:
package com.model; @ContextCOnfiguration(locations="/com/resource
public class Author{ s/my_springbean.xml")@Test
public Authore(){
System.out.println("author");
}
} Below configuration is available in the file located at
/com/resources/my_springbean.xml package come.test;
@Runwith(SpringJUnit4ClassRunner.class)
____Line1____
public class TestAuthorClass{
@Autowired private Author author;
____Line2___
public void testAuthor()
{ Assert.assertTrue(author!=null);
20.
Which of the following is/are correct statement(s) with respect
to spring test? only (i)
(i) @DirtiesContest is used to mark the context dirty so
that it can be closed
(ii) (ii) @ContextConfiguration can only point to Spring
XML..... Choose the most appropriate option.
21. System.setProperty(“spring.profiles.active”,”mypro
refer the code given below file”);
@Component
@Profile(“myprofile”) Class product{ }
Choose from the below a valid option to activate the profile
“myprofile”
22. ANS:A
John has created a properties file below: @Component Public…
config.properties @Value… Private int customer;
customerName: James @Value(…”) Private String Coustomer Name}
CustomerId: 1009090
Choose from below a valid option to inject values in Customer @Componet public class Customer{
bean from confiig.properties file @Value("${customerID}") private int customerID;
@Value("${customerName}") private int
customerName;
23. ANS:
Which of the following is correct with respect to spring? Only (ii)
(i)@Configuration is used to declare a XML files Spring
configuration
(ii)@componentScan is used to scan stereotype annotation
24.
Which of the following statement(s) is/are CORRECT?
(i) JVM Supports IOC option (ii) is correct
(ii) Spring container manages the instance of the beans
mentioned in configuration and provides them back to code
when needed
25.
Refer the code given below. List<EmployeeEntity>findBySalaryBetweenOrderBy
@Entity Public class EmployeeEntity{ SalaryDesc(Double param1, Double param2)
@Id;
private int employeeId;
private String employeeName; private Double salary;
//Getters and Setters are coded }
26.
Refer the code given below
@Entity public class EmployeeEntity{
@Id
private int empId;
private String name;
private double salary;
//getter and setter methods }
Choose the valid implementation of the Update query to update
employee salary, using Spring JPA Data.
27.
Which of the following are with respect to Spring transaction Both (i) &(ii)
propagation types:
(i) propagation type Propagation.REQUIRED starts a new
transaction, if a method is provided from another
method and a transaction does not exist.
(ii) (ii) propagation type Propagation.REQUIRED_NEW
starts a new transaction, if a method is invoked from
another method and a transaction already exists.
Choose the most appropriate
28.
CORRECT with respect to JSP? ANS: A
(i) Default scope of a variable is request Both (i) and (ii)
(ii) Application Scope variable will be available in all JSP
files irrespective of session …
(iii) (iii)JSTL codes are not placed inside
services()method
29.
Choose from below the CORRECT statement about Autowiring. Autowiring requires setters or constructors in bean
classes
(Or)
32.
From the following tables match the JSP implicit objects given in 1 - ii 2 - i 3 - iv 4 – iii
table A with APIs in sevlets package given in table B.
Table A Table B 1. OUT - JSPWRITER 2. APPLICATION-
1) out i) ServletContext SERVLETCONFIG 3. EXCEPTION -
2) application ii) JSPWriter THROWABLE 4. PAGE - OBJECT
3) exception iii) Object
4) page iv) Threwable
33. ANS: C
Incorrect statement about JSR-330 annotation JSR-330 annotations can not beuesd along with
Spring framework annotations
34.
Assume that class “Employee” is created with property “empid”
and its setter method. Refer the spring configuration given below
1
bean id =”emp” class=”com.Employee”> Employee object
///applicationContext///
35. classes, @ActiveProfile
(Option was not visible properly spelling may be
Refer the below incomplete code for a test class different)
1 @RunWith(SpringJUnit4ClassRunner.class)
2 @ContextConfiguration(__________ = MyConfig.class)
3 __________________(profiles = "myProfile") 4
public class TestSpringCustomClass (
5 @Autowired
6 private Employee employee:
7 // test cases goes here
8}
Choose from below a valid combination to complete the above
code in the order as it appears
36.
Refer the code given below:
@Entity findByPublisherType(String pType)
class BookEntity{
@ld private int bookld;
private String title;
private String authorName;
private String publisher Type;
// getters and setters
}
Choose from below the valid option to retrieve the books based
on given publisher type by using Query Method Approach
37.
Refer the JSP code below and predict the output
<body> Book Id: 2 publish Year: 2001
<h3>
<%!
int bookld = 1;
int publish Year = 2000;
public int incrementBookId(int bookId) {
return bookld++;
%>
<%
publish Year++;
bookid++;
%>
</h3>
<h3> Book Id: <%= bookld %> </h3>
<h3> Publish Year: <%= publish Year %></h3>
</body>
40.
Refer the code given below
package com.model;
@component("prodObject") @ActiveProfiles(profiles="myorderProfile")
@Profile("myProdProfile")
public classs Product {
private int productid;
private String productName;
}
package com.model;
@component("orderObject")
@Profile("myOrderProfile")
public classs Order {
private int orderId;
private String orderDetail;
} choose from the below the valid option to activate ....
41.
Refer the incomplete code given below:
@Component
class Customer( _____ @Value("#(cartObj")
private Cart cart;
}
Assume instance of the Cart is managed by
Spring Container ________
Choose from below a valid SpEL to inject the cart object in
Customer bean;
42.
_____Line 1_____
class Customer{ private int customerId; @Component,@Autowied,@Coponent,@Configur
_____Line 2_____ ation,AnnottionConfigApplicationContext
private Address address; }
______Line 3_____
class Address{ public Address(){
------ ------ -------
43.
Which of the following are stereotype annotations? [Choose 2] @Component ,@Sevice
44. ANS: A
/springormdemos”/> DriverManagerDataSource,
Id-“cst_entityManagerFactory” LocalContainerEntityManagerFactoryBean,@repos
class=*org.springframework.com… / itory,@Auto f
// dataSource , JpaVendorAdapter”
Class=”org.springframework.orm.jpa.vendor.hibernate.jpavendor
adapter
45.
Refer the incomplete code given below:
ANS: C
<beans> @Repository,@PersistenceContext,@Transactional
(value="txConfiguration public class")
<!--Assume rest of the configuration is written-->
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager"class="org.springframework.orm.jpa.jpa">
<property
name="entityManagerFactory"ref="cst_entityManagerFactory">
</bean>
</beans>
Line 1
Line2
private EntityManager entityManager;
Line3
Integer employeeID = 0;
return employeelD;
46.
Consider the code given below:
package com.accenture.ikm;
<bean id="employee"class="com.accenture.ikm.Employee">
<property name="hobbies">
<list>
<value>watching Movies</value>
</list>
</property></bean></beans>
48.
1
2 @Transaction(value = "txManager",
3 propogation =
Propogation.REQUIRES_NEW)
@Transactiona(value="txManager",rollbackFor=InvalidDummyException.class)
public Integer addEmployeeAndDepartment
4 //Line-X
5 public Integer addEmployee AndDepartment(EmployeeBean
employeeBean, DepartmentBean departmentBean) throws Exception {
6 int result = 0;
7 int deptId = employeeDepartmentDAO.addDepartment(departmentBean);
8 employeeBean.setDepartmentCode(deptId);
9 result = deptId + employeeDepartmentDAO.addEmployee(employeeBean);
10 return result;
11 }
49. getLastAccessedTime(
Which method is used to retrieve the recent access time of a request by user
by session?
task.
i.
<% java.uti.Date date = new java.util.Date();
out.print(date);
%>
ii.
<%
java.uti.Date date = new java.uti.Date();
%>
Iii.
<%=date;%>
<% java.uti.Date date =new java.uti.Date(): out.print(date);
%>
<%date%>
51.
Book Servlet
Refer the code below:
Web.xml
<web-app>
<servlet>
<servlet-name>Book</servlet-name>
<servlet-class>com.accenture.BookServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>Magazine</servlet-name>
<servlet-class>com.accenture.MagazineServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
54.
Miss Ashrey has been asked to add headers and footers while designing login <jsp include page="Header.jsp">
page and homepage in jsp. from the following options help her to identify the <jsp param value="userName"
right tags in JSP so that headers and footers are consistent in web pages. name="${name}"/>
Moreover she has to display username captured in the login page in headers </jsp include>
across at pagesheaders and footers ate html pages named Header.jsp and <jsp include page="Footer.jsp">
footer.jsp </jsp include>
55. ANS:B
which lifecycle method of jsp is invoked by the container to perform the _jsp service
actual task also the method is invoked by the container each ….
56. Answer :- B
Farhan wants to write a code to add 2 numbers and return the result……….
……………………………………….. JSP scripting element.
60.
Which of the following is CORRECT with respect to propogation type
Propogation.REQUIRES_NEW?
(i) For a method, begin a new transaction always Option-(i)
(ii) If a method is invoked from another method and a transaction
exists, then the same transaction is used. Choose the most
appropriate option
61.
Assume that class "Employee is created with property "empld" and its setter
method.
Refer the spring configuration given below. 1
1 <bean id = "emp" class = "com.Employee">
2 <property name = "empId" value = "John">
3 </bean>
How many Employee objects will be created if the below code executes
successfuly in a main method?
Assume that "context" referes to spring container ApplicationContext
1 public static void main(String[] args) {
2 // code for ApplicationContext creation goes here
3 Employee emp1 = (Employee) context.getBean("emp");
4 Employee emp2 = (Employee) context.getBean("emp");
5 Employee emp3= emp1;
6}
Use the most appropriate option
62.
From the following identify TWO INCORRECT statements about Servlet Coding
i and ii only
objects.
63.
Raghav added following query in orm.xml file @Query(name="getPatientData")
List getPatientsData();
<named-query name="getPatientsData">
</named-query>
{ @Query(name="updateQuery1")
65.
Raghav added the following methods in Service and DAO addPatientInDAO() method always exceutes in a new
implementation classes to add paitent's information in db. transaction rather than the interface started in service layer of
addPatientInService() method.
//service implementation
@transactional(propagation=Propagation.REQUIRED)
Integer addPatientInService (Patients patient)
//DAO implementation
@transactional(propagation=Propagation.REQUIRES_NEW)
Integer addPatientInService(Patients patient)
{ //implementation
}
what is the behaviour of the addPatientInDAO() method?
<web-app>
66. <filter>
Mr. john has been assigned the task of creating a servlet <filter-name>...</filter-name>
filter to log IP addresses of the computers from which the <filter-class>...</filter-class>
request originate. help him from the follwing options to </filter>
identify the correct order of tags meant for servlet filters in <web-mapping>
web.xml file.(Option is not Visible but answer is correct. <filter-name>...</filter-name>
just cross check in exam) <urt-pattern>...</urt-pattern>
</filter-mapping>
</web-app>
67.
which of the following is CORRECT with respect to spring
transection propagation
1) propagation type Propagation REQUIRED starts a both(1) and (2)
new transection ,it a method is involved another
method and a transection does not required.
2) propagation type Propogation.REQUIRED_NEW
start a new transaction. If a method is involved
from another method and a transection already
exists choose most appropriate option
68.
Peter wants a method to add 2 numbers and return the <%!
result. He also wanted to place it inside the service public int add(int num1, int num2) { return num1 + num2;
method. Help him to select the appropriate JSP scripting. }
%>
69.
Sadana wants to share the common database data <%
throughout the application. Help her to identify the String userName = (String)application.getAttribute("dbname")
appropriate code to achieve the task.
%>
70.
Miss Monica has given login request to Translation, Compilation, Instantiation, Service and Destroy
EventmanagementApp. The app displays a JSP page to
prompt her to enter the username and password. Identify
the phases of JSP page it goes through until the response is
generated in right order
71.
76.
Rohit wants to validate the quantity entered by the Add @Range(min=1, max=10)anotation in the Bean class The
customer as mentioned in requirement 2. Choose from the request handler method should include @Valid to
below valid option.[Choose 2] @ModelAnnotation parameter