Download as pdf or txt
Download as pdf or txt
You are on page 1of 83

Started on

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

Step Time Action Sta


1 6/12/21, Started Not yet
11:34 answere
2 6/12/21, Saved: "@RestController @RequestMapping("/products") public class Answer
12:00 ProductController { @GetMapping public List<Product> getProducts(){ ... }" saved
3 7/12/21, Attempt finished Correc
19:39

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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 6/12/21, 12:00 Saved: Statement a,b,d are TRUE Answer saved
3 7/12/21, 19:39 Attempt finished Correct

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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 6/12/21, 12:00 Saved: 405 Method Not Allowed Answer saved
3 7/12/21, 19:39 Attempt finished Correct

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

Step Time Action Sta


1 6/12/21, Started Not ye
11:34 answer
2 6/12/21, Saved: @GetMapping("/home") public String Answe
12:00 sayHello(@RequestParam("company")String companyName) { return "Welcome to saved
"+companyName; }
3 7/12/21, Attempt finished Correc
19:39

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.

Choose the correct annotation to be included for exception handling.


Select one:
Any one of the listed options
@RestControllerAdvice
@ControllerAdvice
None of the listed options
Feedback
The correct answer is: Any one of the listed options
Comments
Make comment or override mark
Response history

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 6/12/21, 12:00 Saved: Any one of the listed options Answer saved
3 7/12/21, 19:39 Attempt finished Correct

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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 6/12/21, 12:04 Saved: Both of them are TRUE Answer saved
3 7/12/21, 19:39 Attempt finished Correct

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.

Choose the correct code snippet to be included in the controller class.


Select one:
Option 2
@RequestMapping(path = "/employees/{id}", method = RequestMethod.GET)
public ResponseEntity<Employee> findByIdAlt(@PathVariable int id) throws
EmployeeNotFoundException {
return ResponseEntity.ok(employeeService.findById(id));
}
None of the listed options
Option 1
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) throws EmployeeNotFoundException
{
return ResponseEntity.ok(employeeService.findById(id));
}
Either option 1 or 2 can be implemented
Feedback
The correct answer is: Either option 1 or 2 can be implemented

Comments
Make comment or override mark
Response history

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 6/12/21, 12:04 Saved: Either option 1 or 2 can be implemented Answer saved
3 7/12/21, 19:39 Attempt finished Correct

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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 6/12/21, 12:04 Saved: @RestControllerAdvice Answer saved
3 7/12/21, 19:39 Attempt finished Correct

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

Step Time Action Sta


1 6/12/21, Started Not yet
11:34 answere
2 6/12/21, Saved: @RestController @RequestMapping("/employees") @CrossOrigin(origins = Answer
12:07 "http://localhost:4200") public class EmployeeController {//...} saved
3 7/12/21, Attempt finished Correc
19:39

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.

Choose the correct dependancy to be included in pom.xml .


Select one:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
None of the listed options
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>"
Feedback
The correct answer is: <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>"

Comments
Make comment or override mark
Response history

Step Time Action Sta


1 6/12/21, Started Not yet
11:34 answer
2 6/12/21, Saved: <dependency> <groupId>org.springframework.boot</groupId> Answer
12:07 <artifactId>spring-boot-starter-web</artifactId> </dependency>" saved
3 7/12/21, Attempt finished Correc
19:39

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.

Following is the ErrorResponse code


@Data
@NoArgsConstructor
public class ErrorResponse {
private String errorMsg;
private HttpStatus status;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss")
private LocalDateTime timestamp;
}

Help him to identify the correct Global Exception Handler code .


Select one:
@ControllerAdvice(EmployeeNotFoundException.class)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}
@ExceptionHandler(EmployeeNotFoundException.class)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}
@ControllerAdvice(EmployeeNotFoundException)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}
@ExceptionHandler(EmployeeNotFoundException)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}
Feedback
The correct answer is: @ExceptionHandler(EmployeeNotFoundException.class)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}

Comments
Make comment or override mark
Response history

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 7/12/21, 19:39 Attempt finished Correct 1

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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 7/12/21, 19:39 Attempt finished Correct 1

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.

app.title=Application title from properties file


@RestController
public class AppController {
@Value(""${app.title:This is the title of app}"")
private String appTitle;

@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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 7/12/21, 19:39 Attempt finished Correct 1

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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 7/12/21, 19:39 Attempt finished Correct 1

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 Optional<Employee> findById(int id){


return EMPLOYEES.stream().filter(e -> e.getId()==id).findFirst();
}
}
class EmployeeNotFoundException extends RuntimeException{
public EmployeeNotFoundException() {
super();

}
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 Optional<Employee> findById(int id){


return EMPLOYEES.stream().filter(e -> e.getId()==id).findFirst();
}
}
class EmployeeNotFoundException extends RuntimeException{
public EmployeeNotFoundException() {
super();

}
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 Optional<Employee> findById(int id){


return EMPLOYEES.stream().filter(e -> e.getId()==id).findFirst();
}
}
class EmployeeNotFoundException extends RuntimeException{
public EmployeeNotFoundException() {
super();

}
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 Optional<Employee> findById(int id){


return EMPLOYEES.stream().filter(e -> e.getId()==id).findFirst();
}
}
class EmployeeNotFoundException extends RuntimeException{
public EmployeeNotFoundException() {
super();

}
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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 7/12/21, 19:39 Attempt finished Not answered

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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
Step Time Action State
2 7/12/21, 19:39 Attempt finished Not answered

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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 7/12/21, 19:39 Attempt finished Not answered

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.

Choose the correct code snippet to be included in the controller class.


Select one:
@PostMapping("/employees")
public Employee createEmployee(@RequestBody Employee employee) {
return employeeService.addEmployee(employee);
}
@PostMapping("/employees")
public Employee createEmployee(@RequestBody Employee employee) {
return employeeService.addEmployee(employee);
}
@PostMapping("/employees")
@ResponseBody
public Employee createEmployee(@RequestBody Employee employee) {
return employeeService.addEmployee(employee);
}
None of the listed options
Feedback
The correct answer is: @PostMapping("/employees")
@ResponseBody
public Employee createEmployee(@RequestBody Employee employee) {
return employeeService.addEmployee(employee);
}

Comments
Make comment or override mark
Response history

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 7/12/21, 19:39 Attempt finished Not answered

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.

Idetify the correct Request Body and Response of follwing request


1. URL - http://localhost:8080/employees
2. Request Method - POST
3. Request Headers -
i. Accept - application/xml
ii. Content-Type - application/json
Select one:
Request Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}
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:
<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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 7/12/21, 19:39 Attempt finished Not answered

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

Step Time Action State


1 6/12/21, 11:34 Started Not yet answered
2 7/12/21, 19:39 Attempt finished Not answered
Started on
State
Completed on
Time taken
Marks 15.00/20.00
Grade 75.00 out of 100.00

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

Step Time Action State


1 9/03/22, 14:12 Started Not yet answere
2 9/03/22, 14:25 Saved: { "id": 1, "name": "Akash", "address": "Kolkata" } Answer saved
3 9/03/22, 14:51 Attempt finished Incorrect

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.

Choose teh correct code snippet to be added in Controller class.

app.title property is defined application.properties file


Select one:
@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;
}
}
@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

Step Time Action State


1 9/03/22, 14:12 Started Not yet answered
2 9/03/22, 14:46 Saved: None of the listed options Answer saved
3 9/03/22, 14:51 Attempt finished Incorrect

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

Step Time Action State


1 9/03/22, 14:12 Started Not yet answered
2 9/03/22, 14:25 Saved: Both of them are TRUE Answer saved
3 9/03/22, 14:51 Attempt finished Correct

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

Step Time Action Sta


1 9/03/22, Started Not ye
14:12 answer
2 9/03/22, Saved: @GetMapping("/home") public String Answe
14:27 sayHello(@RequestParam("company")String companyName) { return "Welcome to saved
"+companyName; }
3 9/03/22, Attempt finished Correc
14:51

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

Step Time Action State


1 9/03/22, 14:12 Started Not yet answer
2 9/03/22, 14:33 Saved: logging: file: name: log.txt level: com.cognizant: debug Answer saved
3 9/03/22, 14:51 Attempt finished Correct

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

Step Time Action Sta


1 9/03/22, Started Not y
14:12 answ
2 9/03/22, Saved: @RestController public class AppController { private static final Logger Answ
14:35 LOGGER = LoggerFactory.getLogger(AppController.class); @GetMapping("/headers") saved
public String getHeaders(@RequestHeader Map<String, String> headers ) {
LOGGER.info("Header :{}" , headers.keySet()); // return "headers"; } }
3 9/03/22, Attempt finished Corr
14:51

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

Step Time Action State


1 9/03/22, 14:12 Started Not yet answered
2 9/03/22, 14:27 Saved: src/main/resources Answer saved
3 9/03/22, 14:51 Attempt finished Correct

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.

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:
{
"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"
}
]
<Employee>
<id>1</id>
<name>Akash</name>
<address>Kolkata</address>
</Employee>
Feedback
The correct answer is: [
{
"id": 1,
"name": "Akash",
"address": "Kolkata"
}
]

Comments
Make comment or override mark
Response history

Step Time Action State


1 9/03/22, 14:12 Started Not yet answere
2 9/03/22, 14:27 Saved: { "id": 1, "name": "Akash", "address": "Kolkata" } Answer saved
3 9/03/22, 14:51 Attempt finished Incorrect

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.

Following is the REST End Point details:


POST:/login(input : LoginCredential like userName and password | Output : LoginResponse like
userName and isValid)

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

Step Time Action Sta


1 9/03/22, Started Not ye
14:12 answer
Step Time Action Sta
2 9/03/22, Saved: "@RequestMapping(path="/login", method = RequestMethod.POST) public Answe
14:31 LoginResponse getLogin(@RequestBody LoginCredential loginCredential) { //Code saved
}"
3 9/03/22, Attempt finished Correc
14:51

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.

Following is the REST End Point details:


GET:/geteligiblebenefits (input : policyId , memberId | Output : Benefit List)

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

Step Time Action State


1 9/03/22, 14:12 Started Not yet answ
2 9/03/22, 14:29 Saved: @Configuration,@ComponentScan,@EnableAutoConfiguration Answer save
3 9/03/22, 14:51 Attempt finished Correct

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

Step Time Action Sta


1 9/03/22, Started Not y
14:12 answe
2 9/03/22, Saved: "@ExceptionHandler(value = EmployeeNotFoundException .class) public Answ
14:29 ResponseEntity<Object> saved
handleEmployeeNotFoundError(EmployeeNotFoundException ex){ .... }"
3 9/03/22, Attempt finished Corre
14:51

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.

Choose the correct annotation to be included for exception handling.


Select one:
@ControllerAdvice
@RestControllerAdvice
None of the listed options
Any one of the listed options
Feedback
The correct answer is: Any one of the listed options

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:29 Saved: Any one of the listed options Answer saved
3 9/03/22, 14:51 Attempt finished Correct

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

Step Time Action State


1 9/03/22, 14:12 Started Not yet answered
2 9/03/22, 14:29 Saved: Is used to read URI variable Answer saved
3 9/03/22, 14:51 Attempt finished Correct

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.

Idetify the correct Request Body and Response of follwing request


1. URL - http://localhost:8080/employees
2. Request Method - POST
3. Request Headers -
i. Accept - application/xml
ii. Content-Type - application/json
Select one:
Request Body:
{
"id": 2,
"name": "Akash",
"address": "Kolkata"
}

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

Step Time Action Sta


1 9/03/22, Started Not ye
14:12 answer
2 9/03/22, Saved: Request Body: { "id": 2, "name": "Akash", "address": "Kolkata" } Response Answe
14:42 Body: <Employee> <id>2</id> <name>Akash</name> <address>Kolkata</address> saved
</Employee>
3 9/03/22, Attempt finished Correc
14:51

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

Step Time Action State


1 9/03/22, 14:12 Started Not yet answ
2 9/03/22, 14:49 Saved: Headers: - Content-Type -application/json - Accept - application/xml Answer sav
3 9/03/22, 14:51 Attempt finished Incorrect

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.

Choose the correct code snippet to be included in the controller class.


Select one:
None of the listed options
@PostMapping("/employees")
public Employee createEmployee(@RequestBody Employee employee) {
return employeeService.addEmployee(employee);
}
@PostMapping("/employees")
public Employee createEmployee(@RequestBody Employee employee) {
return employeeService.addEmployee(employee);
}
@PostMapping("/employees")
@ResponseBody
public Employee createEmployee(@RequestBody Employee employee) {
return employeeService.addEmployee(employee);
}
Feedback
The correct answer is: @PostMapping("/employees")
@ResponseBody
public Employee createEmployee(@RequestBody Employee employee) {
return employeeService.addEmployee(employee);
}

Comments
Make comment or override mark
Response history

Step Time Action Sta


1 9/03/22, Started Not ye
14:12 answe
2 9/03/22, Saved: @PostMapping("/employees") @ResponseBody public Employee Answe
14:42 createEmployee(@RequestBody Employee employee) { return saved
employeeService.addEmployee(employee); }
3 9/03/22, Attempt finished Corre
14:51

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 Optional<Employee> findById(int id){


return EMPLOYEES.stream().filter(e -> e.getId()==id).findFirst();
}
}
class EmployeeNotFoundException extends RuntimeException{
public EmployeeNotFoundException() {
super();

}
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 Optional<Employee> findById(int id){


return EMPLOYEES.stream().filter(e -> e.getId()==id).findFirst();
}
}
class EmployeeNotFoundException extends RuntimeException{
public EmployeeNotFoundException() {
super();

}
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 Optional<Employee> findById(int id){


return EMPLOYEES.stream().filter(e -> e.getId()==id).findFirst();
}
}
class EmployeeNotFoundException extends RuntimeException{
public EmployeeNotFoundException() {
super();

}
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 Optional<Employee> findById(int id){


return EMPLOYEES.stream().filter(e -> e.getId()==id).findFirst();
}
}
class EmployeeNotFoundException extends RuntimeException{
public EmployeeNotFoundException() {
super();

}
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

Step Time Action St


1 9/03/22, Started Not
14:12 answ
2 9/03/22, Saved: @Service class EmployeeService { private static final List<Employee> Answ
14:42 EMPLOYEES = Arrays .asList(new Employee[] { new Employee(10, "Akask", save
"Kolkata"), new Employee(11, "Akask", "Kolkata") }); public Optional<Employee>
findById(int id){ return EMPLOYEES.stream().filter(e -> e.getId()==id).findFirst(); } }
class EmployeeNotFoundException extends RuntimeException{ public
EmployeeNotFoundException() { super(); } 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); } }
3 9/03/22, Attempt finished Corr
14:51

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

Step Time Action State


1 9/03/22, 14:12 Started Not yet answered
2 9/03/22, 14:28 Saved: It loads all the beans Answer saved
3 9/03/22, 14:51 Attempt finished Incorrect
Started on
State
Completed on
Time taken
Marks 17.00/20.00
Grade 85.00 out of 100.00

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.

Choose the correct dependancy to be included in pom.xml .


Select one:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>"
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
None of the listed options
Feedback
The correct answer is: <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>"

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

Step Time Action State


1 9/03/22, 14:05 Started Not yet answer
Step Time Action State
2 9/03/22, 14:08 Saved: logging: file: name: log.txt level: com.cognizant: debug Answer saved
3 9/03/22, 14:33 Attempt finished Correct

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.

Following is the REST End Point details:


GET:/geteligiblebenefits (input : policyId , memberId | Output : Benefit List)

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

Step Time Action State


1 9/03/22, 14:05 Started Not yet answered
2 9/03/22, 14:08 Saved: Statement a,b,d are TRUE Answer saved
3 9/03/22, 14:33 Attempt finished Correct

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.

Following is the ErrorResponse code


@Data
@NoArgsConstructor
public class ErrorResponse {
private String errorMsg;
private HttpStatus status;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss")
private LocalDateTime timestamp;
}

Help him to identify the correct Global Exception Handler code .


Select one:
@ControllerAdvice(EmployeeNotFoundException)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}
@ExceptionHandler(EmployeeNotFoundException)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}
@ControllerAdvice(EmployeeNotFoundException.class)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}
@ExceptionHandler(EmployeeNotFoundException.class)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}
Feedback
The correct answer is: @ExceptionHandler(EmployeeNotFoundException.class)
public final ResponseEntity<ErrorResponse> handleNotFoundException(EmployeeNotFoundException
ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND)
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}

Comments
Make comment or override mark
Response history

Step Time Action St


1 9/03/22, Started Not
14:05 answ
2 9/03/22, Saved: @ExceptionHandler(EmployeeNotFoundException.class) public final Answ
14:08 ResponseEntity<ErrorResponse> save
handleNotFoundException(EmployeeNotFoundException ex) { ErrorResponse
errorResponse = ErrorResponse.builder() .errorMsg(ex.getMessage())
.status(HttpStatus.NOT_FOUND) .timestamp(LocalDateTime.now()) .build(); return
ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse); }
3 9/03/22, Attempt finished Corr
14:33

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

Step Time Action State


1 9/03/22, 14:05 Started Not yet answered
2 9/03/22, 14:11 Saved: spring-boot-starter-web Answer saved
3 9/03/22, 14:33 Attempt finished Correct

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

Step Time Action Sta


1 9/03/22, Started Not y
14:05 answe
2 9/03/22, Saved: Option 1 @RestController public class AppController { private static final Answ
14:28 Logger LOGGER = LoggerFactory.getLogger(AppController.class); saved
@GetMapping("/headers") public String getHeaders(@RequestHeader HttpHeaders
headers ) { LOGGER.info("Header :{}" , headers); List<MediaType>
value=headers.getAccept(); LOGGER.info("MediaType :{}" , value); // return
"headers"; } }
3 9/03/22, Attempt finished Incor
14:33

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

Step Time Action Sta


1 9/03/22, Started Not yet
14:05 answere
2 9/03/22, Saved: "@RestController @RequestMapping("/products") public class Answer
14:11 ProductController { @GetMapping public List<Product> getProducts(){ ... }" saved
3 9/03/22, Attempt finished Correc
14:33

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

Step Time Action Sta


1 9/03/22, Started Not y
14:05 answe
2 9/03/22, Saved: "@ExceptionHandler public ResponseEntity<Object> Answ
14:11 handleEmployeeNotFoundError(EmployeeNotFoundException ex){ .... }" saved
3 9/03/22, Saved: "@ExceptionHandler(value = EmployeeNotFoundException .class) public Answ
14:28 ResponseEntity<Object> saved
handleEmployeeNotFoundError(EmployeeNotFoundException ex){ .... }"
4 9/03/22, Attempt finished Corre
14:33

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

Step Time Action Sta


1 9/03/22, Started Not ye
14:05 answer
2 9/03/22, Saved: Add the below code in Line1 @PathVariable String name,@PathVariable Answe
14:11 Integer age or Add the below code in Line1 @PathVariable("name") String saved
name,@PathVariable("age") Integer age
3 9/03/22, Attempt finished Correc
14:33

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

Step Time Action State


1 9/03/22, 14:05 Started Not yet answ
2 9/03/22, 14:15 Saved: @Configuration,@ComponentScan,@EnableAutoConfiguration Answer save
3 9/03/22, 14:33 Attempt finished Correct

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

Step Time Action State


1 9/03/22, Started Not yet
14:05 answered
2 9/03/22, Saved: It starts up the Spring Boot Application, start the embedded Tomcat Answer s
14:15 server and launch the application.
3 9/03/22, Attempt finished Correct
14:33

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

Step Time Action State


1 9/03/22, 14:05 Started Not yet answered
2 9/03/22, 14:15 Saved: Option 1 Or Option 2 Answer saved
3 9/03/22, 14:33 Attempt finished Correct

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

Step Time Action State


1 9/03/22, Started Not yet
14:05 answered
2 9/03/22, Saved: <List> <item> <id>1</id> <name>Akash</name> Answer s
14:15 <address>Kolkata</address> </item> </List>
3 9/03/22, Attempt finished Correct
14:33
Question 15
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")
@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

Step Time Action Sta


1 9/03/22, Started Not yet
14:05 answere
2 9/03/22, Saved: @RestController @RequestMapping("/employees") @CrossOrigin(origins = Answer
14:15 "http://localhost:4200") public class EmployeeController {//...} saved
3 9/03/22, Attempt finished Correc
14:33
Question 16
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:
@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

Step Time Action State


1 9/03/22, 14:05 Started Not yet answered
2 9/03/22, 14:18 Saved: @GetMapping("/employee/{id}") Answer saved
3 9/03/22, 14:33 Attempt finished Incorrect

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

Step Time Action State


1 9/03/22, 14:05 Started Not yet answered
2 9/03/22, 14:18 Saved: True Answer saved
3 9/03/22, 14:33 Attempt finished Correct 1

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

Step Time Action State


1 9/03/22, 14:05 Started Not yet answered
2 9/03/22, 14:18 Saved: Is used to read URI variable Answer saved
3 9/03/22, 14:33 Attempt finished Correct

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

Step Time Action State


1 9/03/22, Started Not yet
14:05 answered
Step Time Action State
2 9/03/22, Saved: <List> <item> <id>1</id> <name>Akash</name> Answer s
14:18 <address>Kolkata</address> </item> </List>
3 9/03/22, Saved: [ { "id": 1, "name": "Akash", "address": "Kolkata" } ] Answer s
14:20
4 9/03/22, Attempt finished Correct
14:33

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.

Choose the correct annotation to be included for exception handling.


Select one:
None of the listed options
@RestControllerAdvice
Any one of the listed options
@ControllerAdvice
Feedback
The correct answer is: Any one of the listed options

Comments
Make comment or override mark
Response history

Step Time Action State


1 9/03/22, 14:05 Started Not yet answered
2 9/03/22, 14:18 Saved: @RestControllerAdvice Answer saved
3 9/03/22, 14:33 Attempt finished Incorrect
Started on
State
Completed on
Time taken
Marks 16.00/20.00
Grade 80.00 out of 100.00

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.

Choose the correct dependancy to be included in pom.xml .


Select one:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
None of the listed options
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>"
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
Feedback
The correct answer is: <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>"

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.

Following is the REST End Point details:


GET:/geteligiblebenefits (input : policyId , memberId | Output : Benefit List)

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

Step Time Action St


1 9/03/22, Started Not y
14:03 answ
2 9/03/22, Saved: "@RequestMapping(path="/geteligiblebenefits/{policyId}/{memberId}", method Answ
14:41 = RequestMethod.GET) public List<Benefit> getEligibleBenefit(@PathVariable int save
policyId, @PathVariable int memberId) { //Code return null; }"
3 9/03/22, Attempt finished Corr
14:43

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

Step Time Action State


1 9/03/22, 14:03 Started Not yet answered
2 9/03/22, 14:05 Saved: Statement a,b,d are TRUE Answer saved
3 9/03/22, 14:43 Attempt finished Correct

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

Step Time Action Sta


1 9/03/22, Started Not y
14:03 answe
2 9/03/22, Saved: Option 1 @RestController public class AppController { private static final Answ
14:39 Logger LOGGER = LoggerFactory.getLogger(AppController.class); saved
@GetMapping("/headers") public String getHeaders(@RequestHeader HttpHeaders
headers ) { LOGGER.info("Header :{}" , headers); List<MediaType>
value=headers.getAccept(); LOGGER.info("MediaType :{}" , value); // return
"headers"; } }
3 9/03/22, Attempt finished Incor
14:43

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

Step Time Action Sta


1 9/03/22, Started Not y
14:03 answ
2 9/03/22, Saved: The code in the controller method should be: Answ
14:40 @GetMapping(value="/users",produces= MediaType.APPLICATION_JSON_VALUE) saved
public User findUser(@RequestParam String name) {
if(name.equalsIgnoreCase("rohit")) return new User("Rohit",21); return null; }
3 9/03/22, Attempt finished Corr
14:43

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.

Idetify the correct Request Body and Response of follwing request


1. URL - http://localhost:8080/employees
2. Request Method - POST
3. Request Headers -
i. Accept - application/json
ii. Content-Type - application/xml
Select one:
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:
{
"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

Step Time Action Sta


1 9/03/22, Started Not ye
14:03 answer
2 9/03/22, Saved: Request Body: <Employee> <id>2</id> <name>Akash</name> Answe
14:40 <address>Kolkata</address> </Employee> Response Body: { "id": 2, "name": saved
"Akash", "address": "Kolkata" }
3 9/03/22, Attempt finished Correc
14:43

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

Step Time Action State


1 9/03/22, 14:03 Started Not yet answered
2 9/03/22, 14:16 Saved: @RestControllerAdvice Answer saved
3 9/03/22, 14:43 Attempt finished Correct

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

Step Time Action State


1 9/03/22, 14:03 Started Not yet answ
2 9/03/22, 14:12 Saved: @Configuration,@ComponentScan,@EnableAutoConfiguration Answer save
3 9/03/22, 14:43 Attempt finished Correct

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

Step Time Action State


1 9/03/22, 14:03 Started Not yet answered
2 9/03/22, 14:20 Saved: Both of them are TRUE Answer saved
3 9/03/22, 14:43 Attempt finished Correct

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

Step Time Action Sta


1 9/03/22, Started Not y
14:03 answ
2 9/03/22, Saved: @RestController public class AppController { private static final Logger Answ
14:42 LOGGER = LoggerFactory.getLogger(AppController.class); @GetMapping("/headers") saved
public String getHeaders(@RequestHeader Map<String, String> headers ) {
LOGGER.info("Header :{}" , headers.keySet()); // return "headers"; } }
3 9/03/22, Attempt finished Corr
14:43

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

Step Time Action State


1 9/03/22, 14:03 Started Not yet answered
2 9/03/22, 14:23 Saved: Both the options are correct Answer saved
3 9/03/22, 14:43 Attempt finished Correct

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

Step Time Action State


1 9/03/22, 14:03 Started Not yet answered
2 9/03/22, 14:11 Saved: src/main/resources Answer saved
3 9/03/22, 14:43 Attempt finished Correct

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

Step Time Action State


1 9/03/22, 14:03 Started Not yet answered
2 9/03/22, 14:11 Saved: @GetMapping("/employee/{id}") Answer saved
3 9/03/22, 14:43 Attempt finished Incorrect

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

Step Time Action State


1 9/03/22, 14:03 Started Not yet answered
2 9/03/22, 14:07 Saved: spring-boot-starter-web Answer saved
3 9/03/22, 14:43 Attempt finished Correct

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.

Choose the correct code snippet to be included in the controller class.


Select one:
Option 2
@RequestMapping(path = "/employees/{id}", method = RequestMethod.GET)
public ResponseEntity<Employee> findByIdAlt(@PathVariable int id) throws
EmployeeNotFoundException {
return ResponseEntity.ok(employeeService.findById(id));
}
None of the listed options
Option 1
@GetMapping("/employees/{id}")
public ResponseEntity<Employee> findById(@PathVariable int id) throws EmployeeNotFoundException
{
return ResponseEntity.ok(employeeService.findById(id));
}
Either option 1 or 2 can be implemented
Feedback
The correct answer is: Either option 1 or 2 can be implemented

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: Either option 1 or 2 can be implemented Answer saved
3 9/03/22, 14:43 Attempt finished Correct

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.

app.title=Application title from properties file


@RestController
public class AppController {
@Value(""${app.title:This is the title of app}"")
private String appTitle;

@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

Step Time Action State


1 9/03/22, 14:03 Started Not yet answer
2 9/03/22, 14:43 Saved: logging: file: name= log.txt level: com.cognizant= debug Answer saved
3 9/03/22, 14:43 Attempt finished Incorrect
Question 20
Incorrect
Mark 0.00 out of 1.00

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

Step Time Action Sta


1 9/03/22, Started Not yet
14:03 answer
2 9/03/22, Saved: " @RestController public class EmployeeController { Answe
14:43 @PostMapping(""/employee"") public Employee addEmployee(@RequestBody saved
Employee employee){ return employee; } } "
3 9/03/22, Attempt finished Incorr
14:43

You might also like