Professional Documents
Culture Documents
Question Text: Started On State Completed On Time Taken Marks Grade 70.00 Out of 100.00
Question Text: Started On State Completed On Time Taken Marks Grade 70.00 Out of 100.00
State
Completed on
Time taken
Marks 14.00/20.00
Grade 70.00 out of 100.00
Question 1
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a spring boot application to manage the different Products in an ecommerce
application. Choose the correct code snippet to create a Rest Api that returns a List of Products.
Select one:
None of the listed options
@RestController
@RequestMapping("/products")
public class ProductController {
@PutMapping
public List<Product> getProducts(){
...
}
@RestController
@RequestMapping("/products")
public class ProductController {
@GetMapping
public Product getProducts(){
..._
}
"@RestController
@RequestMapping("/products")
public class ProductController {
@GetMapping
public List<Product> getProducts(){
...
}"
Feedback
The correct answer is: "@RestController
@RequestMapping("/products")
public class ProductController {
@GetMapping
public List<Product> getProducts(){
...
}"
Comments
Make comment or override mark
Response history
Question 2
Correct
Mark 1.00 out of 1.00
Question text
State True or False:
a) The POST verb is used to create new resources.
b) The DELETE verb is used to delete a resource identified by a URI.
c) The DELETE and POST operations are both non idempotent.
d) Making two identical POST requests will create two resources with the same information.
Select one:
Statement a,b,d are TRUE
None of them are TRUE
Statement a,b,c are TRUE
All of them are TRUE
Feedback
The correct answer is: Statement a,b,d are TRUE
Comments
Make comment or override mark
Response history
Question 3
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a RESTful API to manage the employees of an organization. You are working
with Spring Boot framework in order to implement the employee API.
Your API resource does not allow deletion, and a client application attempted to delete the resource. What
HTTP respose code should you return?
Select one:
406 Not Acceptable
405 Method Not Allowed
400 Bad Request
409 Conflict
Feedback
The correct answer is: 405 Method Not Allowed
Comments
Make comment or override mark
Response history
Question 4
Correct
Mark 1.00 out of 1.00
Question text
The url typed on the address bar is as follows:
http://localhost:9000/home?company=Cognizant%20Technology%20Solutions
The output on the web browser is as follows:
Welcome to Cognizant Technology Solutions
Identify the code snippet which is to be written to achieve the above.
Select one:
@GetMapping("/home")
public String sayHello(@PathVariable("company")String companyName) {
return "Welcome to "+companyName;
}
@GetMapping("/home")
public String sayHello(@PathParam("company")String companyName) {
return "Welcome to "+companyName;
}
None of the listed options
@GetMapping("/home")
public String sayHello(@RequestParam("company")String companyName) {
return "Welcome to "+companyName;
}
Feedback
The correct answer is: @GetMapping("/home")
public String sayHello(@RequestParam("company")String companyName) {
return "Welcome to "+companyName;
}
Comments
Make comment or override mark
Response history
Question 5
Correct
Mark 1.00 out of 1.00
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Question 6
Correct
Mark 1.00 out of 1.00
Question text
State True or False:
a) The @RequestBody annotation allows us to retrieve the request body
and convert it to Java Object
b) The @ResponseBody annotation tells Spring framework to serialize the java object into JSON or XML
format and send it back as part of the HTTPResponse.
Select one:
Only Statement b is TRUE
None of them are TRUE
Only Statement a is TRUE
Both of them are TRUE
Feedback
The correct answer is: Both of them are TRUE
Comments
Make comment or override mark
Response history
Question 7
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Comments
Make comment or override mark
Response history
Question 8
Correct
Mark 1.00 out of 1.00
Question text
Martin has created a class where he has defined different exception handler using @ExceptionHandler
annotation.
Which annotation he must need to write to allow the proper exception to be caught and handled if the
application throws a user defined exception
Select one:
@RestControllerAdvice
None of the listed options
@RestController
@HandleException
Feedback
The correct answer is: @RestControllerAdvice
Comments
Make comment or override mark
Response history
Question 9
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Help him to identify the correct code snippet to be included in EmployeeController class.
Select one:
@RestController
@RequestMapping("/employees")
@CrossOrigins(origin = "http://localhost:4200")
public class EmployeeController {//...}
@RestController
@RequestMapping("/employees")
@CrossOrigins(origins = "http://localhost:4200")
public class EmployeeController {//...}
@RestController
@RequestMapping("/employees")
@CrossOrigin(origin = "http://localhost:4200")
public class EmployeeController {//...}
@RestController
@RequestMapping("/employees")
@CrossOrigin(origins = "http://localhost:4200")
public class EmployeeController {//...}
Feedback
The correct answer is: @RestController
@RequestMapping("/employees")
@CrossOrigin(origins = "http://localhost:4200")
public class EmployeeController {//...}
Comments
Make comment or override mark
Response history
Question 10
Correct
Mark 1.00 out of 1.00
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Comments
Make comment or override mark
Response history
Question 11
Correct
Mark 1.00 out of 1.00
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. He wants to return custom response
to the client when the EmployeNotFoundException raised.
Comments
Make comment or override mark
Response history
Question 12
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Choose the correct code snippet to be included in the controller class.
Select one:
Option 3:
John needs to include the below statements in his controller
@PostMapping("/employees")
public ResponseEntity<Employee> createEmployee(Employee employee) {
return ResponseEntity.status(HttpStatus.CREATED).body(employeeService.addEmployee(employee));
}
Option 2:
@PostMapping("/employees")
public ResponseEntity<Employee> createEmployee( @RequestBody("employee")) {
return ResponseEntity.status(HttpStatus.CREATED).body(employeeService.addEmployee(employee));
}
None of the listed options
Option 1:
@PostMapping("/employees")
public ResponseEntity<Employee> createEmployee(@RequestBody Employee employee) {
return ResponseEntity.status(HttpStatus.CREATED).body(employeeService.addEmployee(employee));
}
Feedback
The correct answer is: Option 1:
@PostMapping("/employees")
public ResponseEntity<Employee> createEmployee(@RequestBody Employee employee) {
return ResponseEntity.status(HttpStatus.CREATED).body(employeeService.addEmployee(employee));
}
Comments
Make comment or override mark
Response history
Question 13
Correct
Mark 1.00 out of 1.00
Question text
Properties files are used to keep 'N' number of properties in a single file to run the application in a different
environment. In Spring Boot, properties are kept in the application.properties file. Following is the
application.properties and the AppController code that John developed.
@GetMapping(""/value"")
public String getValue() {
return appTitle;
}
}
On Invocation of http://localhost:8080/value what it will produce
Select one:
No Output
Application title from properties file
Runtime Exception
Application title from controller
Feedback
The correct answer is: Application title from properties file
Comments
Make comment or override mark
Response history
Question 14
Correct
Mark 1.00 out of 1.00
Question text
The @RestController combines the behavior of @Controller and @RequestBody annotations together.
State True or False
Select one:
True
False
Feedback
The correct answer is 'False'.
Comments
Make comment or override mark
Response history
Question 15
Not answered
Marked out of 1.00
Question text
You are tasked to develop a RESTful web service application to manage the employees of an organization.
You are working with Spring Boot framework in order to implement the employee service.
Choose the correct code snippet to define the spring boot exception handling in controller class from
below.
Select one:
@Service
class EmployeeService {
private static final List<Employee> EMPLOYEES = Arrays
.asList(new Employee[] {
new Employee(10, "Akask", "Kolkata"),
new Employee(11, "Akask", "Kolkata")
});
}
public EmployeeNotFoundException(String message) {
super(message);
}
}
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) {
try {
return new ResponseEntity<>(employeeService.findById(id).get(), HttpStatus.OK);
} catch (EmployeeNotFoundException e) {
throw e;
}
}
@ExceptionHandler(EmployeeNotFoundException.class)
public ResponseEntity<Object> handleEmployeeNotFounException(EmployeeNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}
@Service
class EmployeeService {
private static final List<Employee> EMPLOYEES = Arrays
.asList(new Employee[] {
new Employee(10, "Akask", "Kolkata"),
new Employee(11, "Akask", "Kolkata")
});
}
public EmployeeNotFoundException(String message) {
super(message);
}
}
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) {
try {
return new ResponseEntity<>(employeeService.findById(id).get(), HttpStatus.OK);
} catch (EmployeeNotFoundException e) {
throw new EmployeeNotFoundException("Employee Not Exists with id : " +id);
}
}
@ExceptionHandler(EmployeeNotFoundException.class)
public ResponseEntity<Object> handleEmployeeNotFounException(EmployeeNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}
@Service
class EmployeeService {
private static final List<Employee> EMPLOYEES = Arrays
.asList(new Employee[] {
new Employee(10, "Akask", "Kolkata"),
new Employee(11, "Akask", "Kolkata")
});
}
public EmployeeNotFoundException(String message) {
super(message);
}
}
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) {
try {
return new ResponseEntity<>(employeeService.findById(id).get(), HttpStatus.OK);
} catch (NoSuchElementException e) {
throw new EmployeeNotFoundException("Employee Not Exists with id : " +id);
}
}
@ExceptionHandler(EmployeeNotFoundException.class)
public ResponseEntity<Object> handleEmployeeNotFounException(EmployeeNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}
None of the listed options
Feedback
The correct answer is: @Service
class EmployeeService {
private static final List<Employee> EMPLOYEES = Arrays
.asList(new Employee[] {
new Employee(10, "Akask", "Kolkata"),
new Employee(11, "Akask", "Kolkata")
});
}
public EmployeeNotFoundException(String message) {
super(message);
}
}
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) {
try {
return new ResponseEntity<>(employeeService.findById(id).get(), HttpStatus.OK);
} catch (NoSuchElementException e) {
throw new EmployeeNotFoundException("Employee Not Exists with id : " +id);
}
}
@ExceptionHandler(EmployeeNotFoundException.class)
public ResponseEntity<Object> handleEmployeeNotFounException(EmployeeNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}
Comments
Make comment or override mark
Response history
Question 16
Not answered
Marked out of 1.00
Question text
You are tasked to develop a RESTful web service application to manage the employees of an organization.
You are working with Spring Boot framework in order to implement the employee service.
Choose the correct code snippet to read the headers in spring boot from below.
Select one:
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeadersV(@RequestHeader List<String> headers ) {
LOGGER.debug("Header :{}" , headers);
//
return "headers";
}
}
None of the listed options
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeadersV(@RequestHeader List<String> headers ) {
LOGGER.debug("Header :{}" , headers);
//
return "headers";
}
}
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeaders(@RequestHeader Map<String, String> headers ) {
LOGGER.info("Header :{}" , headers.keySet());
//
return "headers";
}
}
Feedback
The correct answer is: @RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeaders(@RequestHeader Map<String, String> headers ) {
LOGGER.info("Header :{}" , headers.keySet());
//
return "headers";
}
}
Comments
Make comment or override mark
Response history
Question 17
Not answered
Marked out of 1.00
Question text
The annotation @SpringBootApplication provides combined effect of the annotations
Select one:
@Configuration,@ComponentScan
None of the listed options
@Configuration,@ComponentScan,@EnableAutoConfiguration
@Controller,@ComponentScan,@EnableAutoConfiguration
Feedback
The correct answer is: @Configuration,@ComponentScan,@EnableAutoConfiguration
Comments
Make comment or override mark
Response history
Question 18
Not answered
Marked out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Comments
Make comment or override mark
Response history
Question 19
Not answered
Marked out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. His application now supports both
XML and JSON representations of the employee resource.
Response Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Request Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Response Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Request Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Response Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Feedback
The correct answer is: Request Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Response Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Comments
Make comment or override mark
Response history
Question 20
Not answered
Marked out of 1.00
Question text
"What happens when the following code gets executed
SpringApplication.run(MyApplication.class, args);"
Select one:
It starts up the Spring Boot Application, start the embedded Tomcat server and launch the application.
None of the listed options
It calls the Thread.run() method
It loads all the beans
Feedback
The correct answer is: It starts up the Spring Boot Application, start the embedded Tomcat server and
launch the application.
Comments
Make comment or override mark
Response history
Question 1
Incorrect
Mark 0.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. His application now supports both
XML and JSON representations of the employee resource.
Idetify the correct Response of follwing request
1. URL - http://localhost:8080/employees
2. Request Method - GET
3. Request Headers -
i. Accept - application/xml
ii. Content-Type - application/json
Select one:
<Employee>
<id>1</id>
<name>Akash</name> <address>Kolkata</address>
</Employee>
<List>
<item>
<id>1</id>
<name>Akash</name>
<address>Kolkata</address>
</item>
</List>
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
[
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
]
Feedback
The correct answer is: <List>
<item>
<id>1</id>
<name>Akash</name>
<address>Kolkata</address>
</item>
</List>
Comments
Make comment or override mark
Response history
Question 2
Incorrect
Mark 0.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
@GetMapping("/value")
public String getValue() {
return appTitle;
}
}
@RestController
public class AppController {
@Value("${app.title}")
private String appTitle;
@GetMapping("/value")
public String getValue() {
return appTitle;
}
}
@RestController
public class AppController {
@Value("{app.title}")
private String appTitle;
@GetMapping("/value")
public String getValue() {
return appTitle;
}
}
None of the listed options
Feedback
The correct answer is: @RestController
public class AppController {
@Value("${app.title}")
private String appTitle;
@GetMapping("/value")
public String getValue() {
return appTitle;
}
}
Comments
Make comment or override mark
Response history
Question 3
Correct
Mark 1.00 out of 1.00
Question text
State True or False:
a) The @RequestBody annotation allows us to retrieve the request body
and convert it to Java Object
b) The @ResponseBody annotation tells Spring framework to serialize the java object into JSON or XML
format and send it back as part of the HTTPResponse.
Select one:
Both of them are TRUE
None of them are TRUE
Only Statement b is TRUE
Only Statement a is TRUE
Feedback
The correct answer is: Both of them are TRUE
Comments
Make comment or override mark
Response history
Question 4
Correct
Mark 1.00 out of 1.00
Question text
The url typed on the address bar is as follows:
http://localhost:9000/home?company=Cognizant%20Technology%20Solutions
The output on the web browser is as follows:
Welcome to Cognizant Technology Solutions
Identify the code snippet which is to be written to achieve the above.
Select one:
@GetMapping("/home")
public String sayHello(@PathVariable("company")String companyName) {
return "Welcome to "+companyName;
}
@GetMapping("/home")
public String sayHello(@PathParam("company")String companyName) {
return "Welcome to "+companyName;
}
None of the listed options
@GetMapping("/home")
public String sayHello(@RequestParam("company")String companyName) {
return "Welcome to "+companyName;
}
Feedback
The correct answer is: @GetMapping("/home")
public String sayHello(@RequestParam("company")String companyName) {
return "Welcome to "+companyName;
}
Comments
Make comment or override mark
Response history
Question 5
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a RESTFull application to manage the employees of an organization. You are
working with Spring Boot framework in order to implement the employee Service
Choose the correct code snippet to define the spring boot application yaml such as log level and log file
name from below.
Select one:
None of the listed options
logging:
file:
name= log.txt
level:
com.cognizant= debug
logging.level.com.cognizant=info
logging.file.name=log.txt
logging:
file:
name: log.txt
level:
com.cognizant: debug
Feedback
The correct answer is: logging:
file:
name: log.txt
level:
com.cognizant: debug
Comments
Make comment or override mark
Response history
Question 6
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a RESTful web service application to manage the employees of an organization.
You are working with Spring Boot framework in order to implement the employee service.
Choose the correct code snippet to read the headers in spring boot from below.
Select one:
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeadersV(@RequestHeader List<String> headers ) {
LOGGER.debug("Header :{}" , headers);
//
return "headers";
}
}
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeadersV(@RequestHeader List<String> headers ) {
LOGGER.debug("Header :{}" , headers);
//
return "headers";
}
}
None of the listed options
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeaders(@RequestHeader Map<String, String> headers ) {
LOGGER.info("Header :{}" , headers.keySet());
//
return "headers";
}
}
Feedback
The correct answer is: @RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeaders(@RequestHeader Map<String, String> headers ) {
LOGGER.info("Header :{}" , headers.keySet());
//
return "headers";
}
}
Comments
Make comment or override mark
Response history
Question 7
Correct
Mark 1.00 out of 1.00
Question text
We keep the application.properties file in Spring boot application
within the _____ directory.
Select one:
src/java/resources
None of the listed options
src/test/resources
src/main/resources
Feedback
The correct answer is: src/main/resources
Comments
Make comment or override mark
Response history
Question 8
Incorrect
Mark 0.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. His application now supports both
XML and JSON representations of the employee resource.
Comments
Make comment or override mark
Response history
Question 9
Correct
Mark 1.00 out of 1.00
Question text
State True or False:
a) The POST verb is used to create new resources.
b) The DELETE verb is used to delete a resource identified by a URI.
c) The DELETE and POST operations are both non idempotent.
d) Making two identical POST requests will create two resources with the same information.
Select one:
None of them are TRUE
Statement a,b,d are TRUE
All of them are TRUE
Statement a,b,c are TRUE
Feedback
The correct answer is: Statement a,b,d are TRUE
Comments
Make comment or override mark
Response history
Step Time Action State
1 9/03/22, 14:12 Started Not yet answered
2 9/03/22, 14:35 Saved: Statement a,b,d are TRUE Answer saved
3 9/03/22, 14:51 Attempt finished Correct
Question 10
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a REST End Point to manage the employees login of an organization. You are
working with Spring Boot framework in order to implement the employee service.
Choose the correct code snippet to define the Rest End Point in LoginRestController from below.
Select one:
None of the listed options
"@PostMapping("/login")
public LoginResponse getLogin(LoginCredential loginCredential) {
//code
}"
"@RequestMapping(path="/login", method = RequestMethod.POST)
public LoginResponse getLogin(@RequestBody LoginCredential loginCredential) {
//Code
}"
"@RequestMapping(path="/login", method = RequestMethod.POST)
public LoginResponse getLogin(LoginCredential loginCredential) {
//code
}"
Feedback
The correct answer is: "@RequestMapping(path="/login", method = RequestMethod.POST)
public LoginResponse getLogin(@RequestBody LoginCredential loginCredential) {
//Code
}"
Comments
Make comment or override mark
Response history
Question 11
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a REST End Point to get the Eligible Benefits of an health care organization.
You are working with Spring Boot framework in order to implement the Policy Service.
Choose the correct code snippet to define the Rest End Point in PolicyRestController from below.
Select one:
"@RequestMapping(path="/geteligiblebenefits/policyId/memberId", method = RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@PathVariable int policyId, @PathVariable int memberId) {
//Code
return null;
}"
"@RequestMapping(path="/geteligiblebenefits", method = RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@RequestBody int policyId, @RequestBody int memberId) {
//Code
}"
None of the listed options
"@RequestMapping(path="/geteligiblebenefits/{policyId}/{memberId}", method = RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@PathVariable int policyId, @PathVariable int memberId) {
//Code
return null;
}"
Feedback
The correct answer is: "@RequestMapping(path="/geteligiblebenefits/{policyId}/{memberId}", method =
RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@PathVariable int policyId, @PathVariable int memberId) {
//Code
return null;
}"
Comments
Make comment or override mark
Response history
Step Time Action St
1 9/03/22, Started Not y
14:12 answ
2 9/03/22, Saved: "@RequestMapping(path="/geteligiblebenefits/{policyId}/{memberId}", method Answ
14:32 = RequestMethod.GET) public List<Benefit> getEligibleBenefit(@PathVariable int save
policyId, @PathVariable int memberId) { //Code return null; }"
3 9/03/22, Attempt finished Corr
14:51
Question 12
Correct
Mark 1.00 out of 1.00
Question text
The annotation @SpringBootApplication provides combined effect of the annotations
Select one:
@Configuration,@ComponentScan
@Configuration,@ComponentScan,@EnableAutoConfiguration
@Controller,@ComponentScan,@EnableAutoConfiguration
None of the listed options
Feedback
The correct answer is: @Configuration,@ComponentScan,@EnableAutoConfiguration
Comments
Make comment or override mark
Response history
Question 13
Correct
Mark 1.00 out of 1.00
Question text
Hari has created an exception EmployeeNotFoundException that will be thrown whenever anyone inputs a
wrong employeeId. Identify the correct code snippet to create an Exception Handler to catch and handle
the EmployeeNotFoundException
Select one:
"@ExceptionHandler
public ResponseEntity<Object> handleEmployeeNotFoundError(EmployeeNotFoundException ex){
....
}"
"@Exception(value = EmployeeNotFoundException .class)
public ResponseEntity<Object> handleEmployeeNotFoundError(Exception ex){
....
}"
None of the listed options
"@ExceptionHandler(value = EmployeeNotFoundException .class)
public ResponseEntity<Object> handleEmployeeNotFoundError(EmployeeNotFoundException ex){
....
}"
Feedback
The correct answer is: "@ExceptionHandler(value = EmployeeNotFoundException .class)
public ResponseEntity<Object> handleEmployeeNotFoundError(EmployeeNotFoundException ex){
....
}"
Comments
Make comment or override mark
Response history
Question 14
Correct
Mark 1.00 out of 1.00
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Comments
Make comment or override mark
Response history
Question 15
Correct
Mark 1.00 out of 1.00
Question text
Identify the purpose of @PathVariable annotation
Select one:
None of the listed options
Is used to read URI variable
Is used to read form fields
Is used to read file path
Feedback
The correct answer is: Is used to read URI variable
Comments
Make comment or override mark
Response history
Question 16
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. His application now supports both
XML and JSON representations of the employee resource.
Response Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Request Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Response Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Request Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Response Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Request Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Response Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Feedback
The correct answer is: Request Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Response Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Comments
Make comment or override mark
Response history
Question 17
Incorrect
Mark 0.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. Help him to identify the correct
headers and value in Postman to Post the data as XML format and consume the response data in Json
format .
Select one:
Headers:
- Content-Type -application/json
- Accept - application/xml
None of the listed options
Headers:
- Content-Type -application/xml
- Accept - application/xml
Headers:
- Content-Type -application/xml
- Accept - application/json
Feedback
The correct answer is: Headers:
- Content-Type -application/xml
- Accept - application/json
Comments
Make comment or override mark
Response history
Question 18
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Comments
Make comment or override mark
Response history
Question 19
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a RESTful web service application to manage the employees of an organization.
You are working with Spring Boot framework in order to implement the employee service.
Choose the correct code snippet to define the spring boot exception handling in controller class from
below.
Select one:
@Service
class EmployeeService {
private static final List<Employee> EMPLOYEES = Arrays
.asList(new Employee[] {
new Employee(10, "Akask", "Kolkata"),
new Employee(11, "Akask", "Kolkata")
});
}
public EmployeeNotFoundException(String message) {
super(message);
}
}
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) {
try {
return new ResponseEntity<>(employeeService.findById(id).get(), HttpStatus.OK);
} catch (EmployeeNotFoundException e) {
throw e;
}
}
@ExceptionHandler(EmployeeNotFoundException.class)
public ResponseEntity<Object> handleEmployeeNotFounException(EmployeeNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}
@Service
class EmployeeService {
private static final List<Employee> EMPLOYEES = Arrays
.asList(new Employee[] {
new Employee(10, "Akask", "Kolkata"),
new Employee(11, "Akask", "Kolkata")
});
}
public EmployeeNotFoundException(String message) {
super(message);
}
}
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) {
try {
return new ResponseEntity<>(employeeService.findById(id).get(), HttpStatus.OK);
} catch (EmployeeNotFoundException e) {
throw new EmployeeNotFoundException("Employee Not Exists with id : " +id);
}
}
@ExceptionHandler(EmployeeNotFoundException.class)
public ResponseEntity<Object> handleEmployeeNotFounException(EmployeeNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}
@Service
class EmployeeService {
private static final List<Employee> EMPLOYEES = Arrays
.asList(new Employee[] {
new Employee(10, "Akask", "Kolkata"),
new Employee(11, "Akask", "Kolkata")
});
}
public EmployeeNotFoundException(String message) {
super(message);
}
}
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) {
try {
return new ResponseEntity<>(employeeService.findById(id).get(), HttpStatus.OK);
} catch (NoSuchElementException e) {
throw new EmployeeNotFoundException("Employee Not Exists with id : " +id);
}
}
@ExceptionHandler(EmployeeNotFoundException.class)
public ResponseEntity<Object> handleEmployeeNotFounException(EmployeeNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}
None of the listed options
Feedback
The correct answer is: @Service
class EmployeeService {
private static final List<Employee> EMPLOYEES = Arrays
.asList(new Employee[] {
new Employee(10, "Akask", "Kolkata"),
new Employee(11, "Akask", "Kolkata")
});
}
public EmployeeNotFoundException(String message) {
super(message);
}
}
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) {
try {
return new ResponseEntity<>(employeeService.findById(id).get(), HttpStatus.OK);
} catch (NoSuchElementException e) {
throw new EmployeeNotFoundException("Employee Not Exists with id : " +id);
}
}
@ExceptionHandler(EmployeeNotFoundException.class)
public ResponseEntity<Object> handleEmployeeNotFounException(EmployeeNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}
Comments
Make comment or override mark
Response history
Question 20
Incorrect
Mark 0.00 out of 1.00
Question text
"What happens when the following code gets executed
SpringApplication.run(MyApplication.class, args);"
Select one:
It calls the Thread.run() method
None of the listed options
It loads all the beans
It starts up the Spring Boot Application, start the embedded Tomcat server and launch the application.
Feedback
The correct answer is: It starts up the Spring Boot Application, start the embedded Tomcat server and
launch the application.
Comments
Make comment or override mark
Response history
Question 1
Correct
Mark 1.00 out of 1.00
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Comments
Make comment or override mark
Response history
Step Time Action Sta
1 9/03/22, Started Not yet
14:05 answer
2 9/03/22, Saved: <dependency> <groupId>org.springframework.boot</groupId> Answer
14:08 <artifactId>spring-boot-starter-web</artifactId> </dependency>" saved
3 9/03/22, Attempt finished Correc
14:33
Question 2
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a RESTFull application to manage the employees of an organization. You are
working with Spring Boot framework in order to implement the employee Service
Choose the correct code snippet to define the spring boot application yaml such as log level and log file
name from below.
Select one:
logging.level.com.cognizant=info
logging.file.name=log.txt
logging:
file:
name: log.txt
level:
com.cognizant: debug
None of the listed options
logging:
file:
name= log.txt
level:
com.cognizant= debug
Feedback
The correct answer is: logging:
file:
name: log.txt
level:
com.cognizant: debug
Comments
Make comment or override mark
Response history
Question 3
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a REST End Point to get the Eligible Benefits of an health care organization.
You are working with Spring Boot framework in order to implement the Policy Service.
Choose the correct code snippet to define the Rest End Point in PolicyRestController from below.
Select one:
"@RequestMapping(path="/geteligiblebenefits", method = RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@RequestBody int policyId, @RequestBody int memberId) {
//Code
}"
"@RequestMapping(path="/geteligiblebenefits/{policyId}/{memberId}", method = RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@PathVariable int policyId, @PathVariable int memberId) {
//Code
return null;
}"
"@RequestMapping(path="/geteligiblebenefits/policyId/memberId", method = RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@PathVariable int policyId, @PathVariable int memberId) {
//Code
return null;
}"
None of the listed options
Feedback
The correct answer is: "@RequestMapping(path="/geteligiblebenefits/{policyId}/{memberId}", method =
RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@PathVariable int policyId, @PathVariable int memberId) {
//Code
return null;
}"
Comments
Make comment or override mark
Response history
Step Time Action St
1 9/03/22, Started Not y
14:05 answ
2 9/03/22, Saved: "@RequestMapping(path="/geteligiblebenefits/{policyId}/{memberId}", method Answ
14:08 = RequestMethod.GET) public List<Benefit> getEligibleBenefit(@PathVariable int save
policyId, @PathVariable int memberId) { //Code return null; }"
3 9/03/22, Attempt finished Corr
14:33
Question 4
Correct
Mark 1.00 out of 1.00
Question text
State True or False:
a) The POST verb is used to create new resources.
b) The DELETE verb is used to delete a resource identified by a URI.
c) The DELETE and POST operations are both non idempotent.
d) Making two identical POST requests will create two resources with the same information.
Select one:
Statement a,b,c are TRUE
All of them are TRUE
Statement a,b,d are TRUE
None of them are TRUE
Feedback
The correct answer is: Statement a,b,d are TRUE
Comments
Make comment or override mark
Response history
Question 5
Correct
Mark 1.00 out of 1.00
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. He wants to return custom response
to the client when the EmployeNotFoundException raised.
Comments
Make comment or override mark
Response history
Question 6
Correct
Mark 1.00 out of 1.00
Question text
Which dependency do we need to add to create a Spring REST application using Spring Boot?
Select one:
spring-boot-starter-rest
None of the listed options
spring-boot-starter-test
spring-boot-starter-web
Feedback
The correct answer is: spring-boot-starter-web
Comments
Make comment or override mark
Response history
Question 7
Incorrect
Mark 0.00 out of 1.00
Question text
You are tasked to develop a RESTful web service application to manage the employees of an organization.
You are working with Spring Boot framework in order to implement the employee service.
Choose the correct code snippet to read the header in spring REST Controller from below.
Select one:
Both Option 1 and 2
None of the listed options
Option 2
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeader(@RequestHeader("accept") List<MediaType> value ) {
LOGGER.info("MediaType :{}" , value);
//
return "headers";
}
}
Option 1
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeaders(@RequestHeader HttpHeaders headers ) {
LOGGER.info("Header :{}" , headers);
List<MediaType> value=headers.getAccept();
LOGGER.info("MediaType :{}" , value);
//
return "headers";
}
}
Feedback
The correct answer is: Both Option 1 and 2
Comments
Make comment or override mark
Response history
Question 8
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a spring boot application to manage the different Products in an ecommerce
application. Choose the correct code snippet to create a Rest Api that returns a List of Products.
Select one:
@RestController
@RequestMapping("/products")
public class ProductController {
@GetMapping
public Product getProducts(){
..._
}
"@RestController
@RequestMapping("/products")
public class ProductController {
@GetMapping
public List<Product> getProducts(){
...
}"
@RestController
@RequestMapping("/products")
public class ProductController {
@PutMapping
public List<Product> getProducts(){
...
}
None of the listed options
Feedback
The correct answer is: "@RestController
@RequestMapping("/products")
public class ProductController {
@GetMapping
public List<Product> getProducts(){
...
}"
Comments
Make comment or override mark
Response history
Question 9
Correct
Mark 1.00 out of 1.00
Question text
Hari has created an exception EmployeeNotFoundException that will be thrown whenever anyone inputs a
wrong employeeId. Identify the correct code snippet to create an Exception Handler to catch and handle
the EmployeeNotFoundException
Select one:
"@ExceptionHandler(value = EmployeeNotFoundException .class)
public ResponseEntity<Object> handleEmployeeNotFoundError(EmployeeNotFoundException ex){
....
}"
None of the listed options
"@Exception(value = EmployeeNotFoundException .class)
public ResponseEntity<Object> handleEmployeeNotFoundError(Exception ex){
....
}"
"@ExceptionHandler
public ResponseEntity<Object> handleEmployeeNotFoundError(EmployeeNotFoundException ex){
....
}"
Feedback
The correct answer is: "@ExceptionHandler(value = EmployeeNotFoundException .class)
public ResponseEntity<Object> handleEmployeeNotFoundError(EmployeeNotFoundException ex){
....
}"
Comments
Make comment or override mark
Response history
Question 10
Correct
Mark 1.00 out of 1.00
Question text
@PutMapping("/users/edit/{name}/{age}")
public ResponseEntity<String> modifyAgeOfUser(//Line1) {
boolean changed=false;
...
...
if(changed)
return ResponseEntity.ok("Record modified");
else
return new ResponseEntity<String>("No such record",HttpStatus.BAD_REQUEST);
}
The following Put request is being made with the url set to http://localhost:9000/users/edit/rahul/22 in
REST client,Postman. Fill Line1 to make the code work.
Select one:
Add the below code in Line1
@PathVariable String name,@PathVariable Integer age
or
Add the below code in Line1
@PathVariable("name") String name,@PathVariable("age") Integer age
Add the below code in Line1
@PathValue String name,@PathValue Integer age
or
Add the below code in Line1
@PathValue("name') String name,@PathValue("age") Integer age
Add the below code in Line1
@RequestParam String name,@RequestParam Integer age
or
Add the below code in Line1
@RequestParam("name') String name,@RequestParam("age") Integer age
None of the listed options
Feedback
The correct answer is: Add the below code in Line1
@PathVariable String name,@PathVariable Integer age
or
Add the below code in Line1
@PathVariable("name") String name,@PathVariable("age") Integer age
Comments
Make comment or override mark
Response history
Question 11
Correct
Mark 1.00 out of 1.00
Question text
The annotation @SpringBootApplication provides combined effect of the annotations
Select one:
@Controller,@ComponentScan,@EnableAutoConfiguration
@Configuration,@ComponentScan,@EnableAutoConfiguration
None of the listed options
@Configuration,@ComponentScan
Feedback
The correct answer is: @Configuration,@ComponentScan,@EnableAutoConfiguration
Comments
Make comment or override mark
Response history
Question 12
Correct
Mark 1.00 out of 1.00
Question text
"What happens when the following code gets executed
SpringApplication.run(MyApplication.class, args);"
Select one:
It starts up the Spring Boot Application, start the embedded Tomcat server and launch the application.
None of the listed options
It calls the Thread.run() method
It loads all the beans
Feedback
The correct answer is: It starts up the Spring Boot Application, start the embedded Tomcat server and
launch the application.
Comments
Make comment or override mark
Response history
Question 13
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Help him to identify the correct code snippet to be included in EmployeeController class.
Select one:
Option 1
@GetMapping("/employees")
public ResponseEntity<List<Employee>> findAll() {
return new ResponseEntity<>(employeeService.findAll(), HttpStatus.OK);
}
Option 3
@GetMapping("/employees")
public ResponseEntity<List<Employee>> findAll() {
return ResponseEntity<List<Employee>>.ok(employeeService.findAll());
}
Option 2
@GetMapping("/employees")
public ResponseEntity<List<Employee>> findAll() {
return ResponseEntity.ok(employeeService.findAll());
}
Option 1 Or Option 2
Feedback
The correct answer is: Option 1 Or Option 2
Comments
Make comment or override mark
Response history
Question 14
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. His application now supports both
XML and JSON representations of the employee resource.
Idetify the correct Response of follwing request
1. URL - http://localhost:8080/employees
2. Request Method - GET
3. Request Headers -
i. Accept - application/xml
ii. Content-Type - application/json
Select one:
<Employee>
<id>1</id>
<name>Akash</name> <address>Kolkata</address>
</Employee>
<List>
<item>
<id>1</id>
<name>Akash</name>
<address>Kolkata</address>
</item>
</List>
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
[
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
]
Feedback
The correct answer is: <List>
<item>
<id>1</id>
<name>Akash</name>
<address>Kolkata</address>
</item>
</List>
Comments
Make comment or override mark
Response history
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Help him to identify the correct code snippet to be included in EmployeeController class.
Select one:
@RestController
@RequestMapping("/employees")
@CrossOrigins(origins = "http://localhost:4200")
public class EmployeeController {//...}
@RestController
@RequestMapping("/employees")
@CrossOrigin(origin = "http://localhost:4200")
public class EmployeeController {//...}
@RestController
@RequestMapping("/employees")
@CrossOrigin(origins = "http://localhost:4200")
public class EmployeeController {//...}
@RestController
@RequestMapping("/employees")
@CrossOrigins(origin = "http://localhost:4200")
public class EmployeeController {//...}
Feedback
The correct answer is: @RestController
@RequestMapping("/employees")
@CrossOrigin(origins = "http://localhost:4200")
public class EmployeeController {//...}
Comments
Make comment or override mark
Response history
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Help him to identify the recommended method and the URL pattern for retrieving a specific employee.
Select one:
@GetMapping("/employees/{id}")
@PostMapping("/employees/{id}")
@GetMapping("/employee?id={id}")
@GetMapping("/employee/{id}")
Feedback
The correct answer is: @GetMapping("/employees/{id}")
Comments
Make comment or override mark
Response history
Question 17
Correct
Mark 1.00 out of 1.00
Question text
State True or False:
The below two annotations are equivalent
@DeleteMapping(value = "/users/remove/{name}")
@RequestMapping(method=RequestMethod.DELETE,value="/users/remove/{name}")
Select one:
True
False
Feedback
The correct answer is 'True'.
Comments
Make comment or override mark
Response history
Question 18
Correct
Mark 1.00 out of 1.00
Question text
Identify the purpose of @PathVariable annotation
Select one:
None of the listed options
Is used to read file path
Is used to read form fields
Is used to read URI variable
Feedback
The correct answer is: Is used to read URI variable
Comments
Make comment or override mark
Response history
Question 19
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. His application now supports both
XML and JSON representations of the employee resource.
Idetify the correct Response of follwing request
1. URL - http://localhost:8080/employees
2. Request Method - GET
3. Request Headers -
i. Accept - application/json
ii. Content-Type - application/xml
Select one:
<Employee>
<id>1</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
[
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
]
<List>
<item>
<id>1</id>
<name>Akash</name>
<address>Kolkata</address>
</item>
</List>
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
Feedback
The correct answer is: [
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
]
Comments
Make comment or override mark
Response history
Question 20
Incorrect
Mark 0.00 out of 1.00
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Comments
Make comment or override mark
Response history
Question 1
Correct
Mark 1.00 out of 1.00
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Comments
Make comment or override mark
Response history
Step Time Action Sta
1 9/03/22, Started Not yet
14:03 answer
2 9/03/22, Saved: <dependency> <groupId>org.springframework.boot</groupId> Answer
14:35 <artifactId>spring-boot-starter</artifactId> </dependency> saved
3 9/03/22, Saved: <dependency> <groupId>org.springframework.boot</groupId> Answer
14:39 <artifactId>spring-boot-starter-web</artifactId> </dependency>" saved
4 9/03/22, Attempt finished Correc
14:43
Question 2
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a REST End Point to get the Eligible Benefits of an health care organization.
You are working with Spring Boot framework in order to implement the Policy Service.
Choose the correct code snippet to define the Rest End Point in PolicyRestController from below.
Select one:
None of the listed options
"@RequestMapping(path="/geteligiblebenefits", method = RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@RequestBody int policyId, @RequestBody int memberId) {
//Code
}"
"@RequestMapping(path="/geteligiblebenefits/policyId/memberId", method = RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@PathVariable int policyId, @PathVariable int memberId) {
//Code
return null;
}"
"@RequestMapping(path="/geteligiblebenefits/{policyId}/{memberId}", method = RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@PathVariable int policyId, @PathVariable int memberId) {
//Code
return null;
}"
Feedback
The correct answer is: "@RequestMapping(path="/geteligiblebenefits/{policyId}/{memberId}", method =
RequestMethod.GET)
public List<Benefit> getEligibleBenefit(@PathVariable int policyId, @PathVariable int memberId) {
//Code
return null;
}"
Comments
Make comment or override mark
Response history
Question 3
Correct
Mark 1.00 out of 1.00
Question text
State True or False:
a) The POST verb is used to create new resources.
b) The DELETE verb is used to delete a resource identified by a URI.
c) The DELETE and POST operations are both non idempotent.
d) Making two identical POST requests will create two resources with the same information.
Select one:
Statement a,b,c are TRUE
Statement a,b,d are TRUE
None of them are TRUE
All of them are TRUE
Feedback
The correct answer is: Statement a,b,d are TRUE
Comments
Make comment or override mark
Response history
Question 4
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. His application now supports both
XML and JSON representations of the employee resource.
Idetify the correct Response of follwing request
1. URL - http://localhost:8080/employees
2. Request Method - GET
3. Request Headers -
i. Accept - application/xml
ii. Content-Type - application/json
Select one:
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
<Employee>
<id>1</id>
<name>Akash</name> <address>Kolkata</address>
</Employee>
<List>
<item>
<id>1</id>
<name>Akash</name>
<address>Kolkata</address>
</item>
</List>
[
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
]
Feedback
The correct answer is: <List>
<item>
<id>1</id>
<name>Akash</name>
<address>Kolkata</address>
</item>
</List>
Comments
Make comment or override mark
Response history
Step Time Action State
1 9/03/22, Started Not yet
14:03 answered
2 9/03/22, Saved: <List> <item> <id>1</id> <name>Akash</name> Answer s
14:41 <address>Kolkata</address> </item> </List>
3 9/03/22, Attempt finished Correct
14:43
Question 5
Incorrect
Mark 0.00 out of 1.00
Question text
You are tasked to develop a RESTful web service application to manage the employees of an organization.
You are working with Spring Boot framework in order to implement the employee service.
Choose the correct code snippet to read the header in spring REST Controller from below.
Select one:
Option 1
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeaders(@RequestHeader HttpHeaders headers ) {
LOGGER.info("Header :{}" , headers);
List<MediaType> value=headers.getAccept();
LOGGER.info("MediaType :{}" , value);
//
return "headers";
}
}
Both Option 1 and 2
None of the listed options
Option 2
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeader(@RequestHeader("accept") List<MediaType> value ) {
LOGGER.info("MediaType :{}" , value);
//
return "headers";
}
}
Feedback
The correct answer is: Both Option 1 and 2
Comments
Make comment or override mark
Response history
Question 6
Correct
Mark 1.00 out of 1.00
Question text
The code in the controller method is as follows:
@GetMapping(value="/users", produces= MediaType.APPLICATION_XML_VALUE)
public User findUser(@RequestParam String name) {
if(name.equalsIgnoreCase("rohit"))
return new User("Rohit",21);
return null;
}
On making the Get request with the url set to http://localhost:9000/users?name=rohit and Accept header
set to the value application/json in REST client, Postman, the response status shows 406 Not Acceptable.
Identify and fix the error in code.
Select one:
The code in the controller method should be:
@GetMapping(value="/users",produces= MediaType.APPLICATION_VALUE)
public User findUser(@RequestParam String name) {
if(name.equalsIgnoreCase("rohit"))
return new User("Rohit",21);
return null;
}
The code in the controller method should be:
@GetMapping(value="/users",consumes= MediaType.APPLICATION_XML_VALUE)
public User findUser(@RequestParam String name) {
if(name.equalsIgnoreCase("rohit"))
return new User("Rohit",21);
return null;
}
None of the listed options
The code in the controller method should be:
@GetMapping(value="/users",produces= MediaType.APPLICATION_JSON_VALUE)
public User findUser(@RequestParam String name) {
if(name.equalsIgnoreCase("rohit"))
return new User("Rohit",21);
return null;
}
Feedback
The correct answer is: The code in the controller method should be:
@GetMapping(value="/users",produces= MediaType.APPLICATION_JSON_VALUE)
public User findUser(@RequestParam String name) {
if(name.equalsIgnoreCase("rohit"))
return new User("Rohit",21);
return null;
}
Comments
Make comment or override mark
Response history
Question 7
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework. His application now supports both
XML and JSON representations of the employee resource.
Response Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Request Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Response Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Request Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Response Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Request Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Response Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Feedback
The correct answer is: Request Body:
<Employee>
<id>2</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Response Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
Comments
Make comment or override mark
Response history
Question 8
Correct
Mark 1.00 out of 1.00
Question text
Martin has created a class where he has defined different exception handler using @ExceptionHandler
annotation.
Which annotation he must need to write to allow the proper exception to be caught and handled if the
application throws a user defined exception
Select one:
@RestController
None of the listed options
@RestControllerAdvice
@HandleException
Feedback
The correct answer is: @RestControllerAdvice
Comments
Make comment or override mark
Response history
Question 9
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Help him to identify the correct code snippet to be included in EmployeeController class.
Select one:
@RestController
@RequestMapping("/employees")
@CrossOrigins(origins = "http://localhost:4200")
public class EmployeeController {//...}
@RestController
@RequestMapping("/employees")
@CrossOrigins(origin = "http://localhost:4200")
public class EmployeeController {//...}
@RestController
@RequestMapping("/employees")
@CrossOrigin(origins = "http://localhost:4200")
public class EmployeeController {//...}
@RestController
@RequestMapping("/employees")
@CrossOrigin(origin = "http://localhost:4200")
public class EmployeeController {//...}
Feedback
The correct answer is: @RestController
@RequestMapping("/employees")
@CrossOrigin(origins = "http://localhost:4200")
public class EmployeeController {//...}
Comments
Make comment or override mark
Response history
Step Time Action Sta
1 9/03/22, Started Not yet
14:03 answere
2 9/03/22, Saved: @RestController @RequestMapping("/employees") @CrossOrigin(origins = Answer
14:29 "http://localhost:4200") public class EmployeeController {//...} saved
3 9/03/22, Attempt finished Correc
14:43
Question 10
Correct
Mark 1.00 out of 1.00
Question text
The annotation @SpringBootApplication provides combined effect of the annotations
Select one:
None of the listed options
@Controller,@ComponentScan,@EnableAutoConfiguration
@Configuration,@ComponentScan
@Configuration,@ComponentScan,@EnableAutoConfiguration
Feedback
The correct answer is: @Configuration,@ComponentScan,@EnableAutoConfiguration
Comments
Make comment or override mark
Response history
Question 11
Correct
Mark 1.00 out of 1.00
Question text
State True or False:
a) The @RequestBody annotation allows us to retrieve the request body
and convert it to Java Object
b) The @ResponseBody annotation tells Spring framework to serialize the java object into JSON or XML
format and send it back as part of the HTTPResponse.
Select one:
Both of them are TRUE
Only Statement b is TRUE
Only Statement a is TRUE
None of them are TRUE
Feedback
The correct answer is: Both of them are TRUE
Comments
Make comment or override mark
Response history
Question 12
Correct
Mark 1.00 out of 1.00
Question text
You are tasked to develop a RESTful web service application to manage the employees of an organization.
You are working with Spring Boot framework in order to implement the employee service.
Choose the correct code snippet to read the headers in spring boot from below.
Select one:
None of the listed options
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeadersV(@RequestHeader List<String> headers ) {
LOGGER.debug("Header :{}" , headers);
//
return "headers";
}
}
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeaders(@RequestHeader Map<String, String> headers ) {
LOGGER.info("Header :{}" , headers.keySet());
//
return "headers";
}
}
@RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeadersV(@RequestHeader List<String> headers ) {
LOGGER.debug("Header :{}" , headers);
//
return "headers";
}
}
Feedback
The correct answer is: @RestController
public class AppController {
private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
@GetMapping("/headers")
public String getHeaders(@RequestHeader Map<String, String> headers ) {
LOGGER.info("Header :{}" , headers.keySet());
//
return "headers";
}
}
Comments
Make comment or override mark
Response history
Question 13
Correct
Mark 1.00 out of 1.00
Question text
We can use ResponseEntity to fully configure the HTTP response.
Choose the correct way of sending response with a body and HTTP 200 OK response code using
ResponseEntity:
a) @GetMapping("/hello")
ResponseEntity<String> sayHello() {
return new ResponseEntity<String>("hello", HttpStatus.OK);
}
b) @GetMapping("/hello")
ResponseEntity<String> sayHello() {
return ResponseEntity.ok("hello");
}
Select one:
None of the options are correct
Both the options are correct
Only option a is correct
None of the listed options
Feedback
The correct answer is: Both the options are correct
Comments
Make comment or override mark
Response history
Question 14
Correct
Mark 1.00 out of 1.00
Question text
We keep the application.properties file in Spring boot application
within the _____ directory.
Select one:
src/java/resources
src/test/resources
None of the listed options
src/main/resources
Feedback
The correct answer is: src/main/resources
Comments
Make comment or override mark
Response history
Question 15
Incorrect
Mark 0.00 out of 1.00
Question text
Akash is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Help him to identify the recommended method and the URL pattern for retrieving a specific employee.
Select one:
@PostMapping("/employees/{id}")
@GetMapping("/employees/{id}")
@GetMapping("/employee/{id}")
@GetMapping("/employee?id={id}")
Feedback
The correct answer is: @GetMapping("/employees/{id}")
Comments
Make comment or override mark
Response history
Question 16
Correct
Mark 1.00 out of 1.00
Question text
Which dependency do we need to add to create a Spring REST application using Spring Boot?
Select one:
spring-boot-starter-test
None of the listed options
spring-boot-starter-web
spring-boot-starter-rest
Feedback
The correct answer is: spring-boot-starter-web
Comments
Make comment or override mark
Response history
Question 17
Correct
Mark 1.00 out of 1.00
Question text
John is an application developer and he currently working with a RESTful web service called
EmployeeService which is developed using Spring Boot Framework.
Comments
Make comment or override mark
Response history
Question 18
Correct
Mark 1.00 out of 1.00
Question text
Properties files are used to keep 'N' number of properties in a single file to run the application in a different
environment. In Spring Boot, properties are kept in the application.properties file. Following is the
application.properties and the AppController code that John developed.
@GetMapping(""/value"")
public String getValue() {
return appTitle;
}
}
On Invocation of http://localhost:8080/value what it will produce
Select one:
No Output
Runtime Exception
Application title from properties file
Application title from controller
Feedback
The correct answer is: Application title from properties file
Comments
Make comment or override mark
Response history
Step Time Action State
1 9/03/22, 14:03 Started Not yet answered
2 9/03/22, 14:43 Saved: Application title from properties file Answer saved
3 9/03/22, 14:43 Attempt finished Correct
Question 19
Incorrect
Mark 0.00 out of 1.00
Question text
You are tasked to develop a RESTFull application to manage the employees of an organization. You are
working with Spring Boot framework in order to implement the employee Service
Choose the correct code snippet to define the spring boot application yaml such as log level and log file
name from below.
Select one:
logging:
file:
name: log.txt
level:
com.cognizant: debug
None of the listed options
logging.level.com.cognizant=info
logging.file.name=log.txt
logging:
file:
name= log.txt
level:
com.cognizant= debug
Feedback
The correct answer is: logging:
file:
name: log.txt
level:
com.cognizant: debug
Comments
Make comment or override mark
Response history
Question text
Identify the correct code snippet to create an Api where client can make a POST request to send a valid
employee object.
Select one:
"
@RestController
public class EmployeeController {
@PostMapping(""/employee"")
public Employee addEmployee(Employee employee){
return employee;
}
}
"
None of the listed options
"
@RestController
public class EmployeeController {
@PostMapping(""/employee"")
public Employee addEmployee(@RequestBody Employee employee){
return employee;
}
}
"
"
@RestController
public class EmployeeController {
@PostMapping(""/employee"")
public Employee addEmployee(@Value Employee employee){
return employee;
}
}
"
Feedback
The correct answer is: "
@RestController
public class EmployeeController {
@PostMapping(""/employee"")
public Employee addEmployee(Employee employee){
return employee;
}
}
"
Comments
Make comment or override mark
Response history