SpringBoot Mock Assessment 27FebPune Batch With Answers
SpringBoot Mock Assessment 27FebPune Batch With Answers
boot
Which annotation is used to define the primary key of an entity in a Spring Boot application?
@PrimaryKey
@Primary
@Id
@GeneratedValue
boot
@SpringConfig
@Configuration
@AppConfig
@SpringBootConfig
boot
What is Spring Boot's embedded database for development and testing by default?
PostgreSQL
Oracle
mySql
H2
1/24
Question - 4 SCORE: 1 points
Spring
boot
@RestController
@RequestMapping
@ResponseBody
@Service
boot
Which of the following Spring Boot starter dependencies is used for building RESTful web services?
spring-boot-starter-data-jpa
spring-boot-starter-web
spring-boot-starter-actuator
spring-boot-starter-test
boot
@SpringBootApp
@EnableSpring
@SpringBootApplication
@SpringConfig
Bean
2/24
What is the purpose of the Spring framework's ApplicationContext?
Annotation
spring boot
Which file is typically used to configure properties for a Spring Boot application?
application.properties
spring-config.xml
web.xml
pom.xml
build.gradle
Spring boot
Consider you are making a REST controller, which of the following annotation you will use to specific your
spring boot application that this is a Rest controller?
3/24
@Controller
@RestController
@GenerateController
@GenerateRESTController
Spring boot
Repository
JpaRepository
SpringRepository
DataJpaRepository
Spring boot
How can you customize the column name for a field in a JPA entity ?
@Column(name="custom_name")
@FieldName("custom_name")
@TableColumn("custom_name")
@DatabaseColumn("custom_name")
Spring boot
@Service
@Component
@ServiceRequest
@Repository
4/24
Question - 14 SCORE: 1 points
Spring boot
Spring boot
Spring boot
If you want to send the string back as it is from the controller which of the following annotation you will use?
Note: This is a controller class with the annotation of @Controller
@ResponseBody
@RequestBody
You dont have to do anything Spring boot will take care for it
It cant be done
Spring boot
_____________ is the annotation you use when we want to specify the Repository. And it is usually extended by __________________ and _____________ class.
You can use either of the two option both are correct
Spring boot
5/24
If you want to keep the URL same in the H2 console for the application which of the following property you will need to change in application.properties?
spring.url=jdbc:h2:mem:testdb
spring.datasource.url=jdbc:h2:mem:testdb
url=jdbc:h2:mem:testdb
springboot
Dependency Injection
Boilerplate Code
Auto-Configuration
None of above
All of Above
Which of the following annotation can we use when we want to make a GET request for spring boot application?
@GetMapping
@RequestMapping
Both of them
kickoff springboot
Hibernate
6/24
iBatis
JPA
All
kickoff springboot
This can be used to inject a collection of name-value pairs where name and value can be of any type.
kickoff springboot
The concept of an endpoint in web services is much like that of a controller in web applications
TRUE
FALSE
Which of the following are most common object notation to interact with backend?
XML
Json
Both of them
None of them
7/24
If you dont write @Service annoation, what will happen to your application. NOTE: You have used class in other @Controller file
@RestController
@Controller
Both of them
None of them
With the help of which annotation will I be able to use to map the request to a specific end point in RESTful application?
@Request()
@Mapping()
@RequestMapping()
All of these
Which of the annotation will we use when we want to annotate the class with the business logic for the application?
@RestContoller
@Controller
8/24
@Repository
@Service
@Repository
@Controller
@RestController
@Rest
Model
View
Controller
None of them
springboot
@SpringBootApplication
@RestController
@Controller
9/24
springboot
@Configuration
@Autowired
@ComponentScan
springboot
@PostMapping
@GetMapping
@Service
@Metadata
springboot
Java 10
Java 8
Java 7
Java 11
springboot
Spring-boot-starter-data-hibernate
10/24
Spring-boot-starter-data-jpa
Spring-boot-starter-data-web
springboot
FALSE
TRUE
springboot
Spring-boot-starter-web
Spring-boot-starter-test
Spring-boot-html
springboot
8081
8080
5555
8000
springboot
11/24
SpringBoot has embedded tomcat, jetty which makes it just code and run the application.
TRUE
FALSE
springboot
Is it possible to change the port of the embedded Tomcat server in Spring Boot?
YES
NO
springboot
This method serves as an entry point, which invokes the SpringApplication#run method to bootstrap the application.
SpringApplication.run(MyApplication.class);
SpringApplication.start(MyApplication.class);
SpringApplication.begin(MyApplication.class);
springboot
scans all the beans and package declarations when the application initializes.
12/24
MCQ12
springboot
@PostMapping
@GetMapping
@PutMapping
springboot
Pom.xml
Config.xml
META-INF
springboot
@Table
@Entity
@Column
@Repository
springboot
JPA is a Data Access Abstraction used to reduce the amount of boilerplate code
13/24
TRUE
FALSE
springboot
@PathVariable annotation can be used to handle template variables in the request URI mapping,
FALSE
TRUE
springboot
BAD REQUEST
UNAUTHORIZED
SERVER ERROR
springboot
BAD REQUEST
UNAUTHORIZED
SERVER ERROR
springboot
14/24
response status 500 used for
BAD REQUEST
UNAUTHORIZED
SERVER ERROR
springboot
@Id
@Column
@JoinedColumn
easy
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
For @SpringBootApplication, what is equivalent of below annotations ?
Configuration Annotation
EnableAutoConfiguration Annotation
ComponentScan Annotation
JPA
15/24
Consider the following snippets and Fill in the blanks for the application
Course.java
package com.springboot.learnjpaandhibernate.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@Entity
public class Course {
@Id
private int id;
private String name;
private String author;
package com.springboot.learnjpaandhibernate.springdatajpa.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.springboot.learnjpaandhibernate.model.Course;
you need to write a function name so that you can search based on the author i.e. author as a parameter
findByAuthor
findBasedOnAuthor
getByAuthor
author
Annotation
Consider the following snippet and fill in the blanks for the same.
package com.springboot.restapi.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
16/24
import com.springboot.restapi.model.HelloWorldBean;
________________
public interface HelloWorldRepository extends JpaRepository<HelloWorldBean, String> {
}
@Controller
@Service
@Repository
@Autowired
Web
com.example.sampleapplication
@SpringBootApplication
com.example.sampleapplication.controller
@RestController
@GetMapping("/response_entity")
int randomInt = 8;
if (randomInt < 9) {
} else {
ResponseEntity<Integer>
ResponseEntity<Float>
17/24
ResponseEntity<String>
Web
Consider the following code. Assuming all the dependency and imports are done correctly.
com.example.sampleapplication
@SpringBootApplication
com.example.sampleapplication.controller
@RestController
@GetMapping("/index/{id}")
Consider the above example and fill in the blanks if you have a request that look like below
http://localhost:8080/index/12
RequestParam
PathVariable
ModelAttribute
RequestBody
Web
18/24
Consider the following code. Assuming all the dependency and imports are done correctly.
com.example.sampleapplication
@SpringBootApplication
com.example.sampleapplication.controller
@RestController
@GetMapping("/index")
Consider the above example and fill in the blanks if you have a request that look like below
http://localhost:8080/index?id=12
RequestParam
PathVariable
ModelAttribute
RequestBody
Annotation
// Controller
_____________________ // this is the service file for the spring boot application
19/24
public class SampleService {
@Service
@Autowired
@Component
@Repository
Web
Consider the following code and predict the behaviour for the program. You can assume all the things imports and
dependency are done correctly.
com.example.sampleapplication
@SpringBootApplication
com.example.sampleapplication.controller
@RestController
@GetMapping("/index")
return "index";
index.jsp
This will throw you an error because it is not able to find the JSP file.
{"key": "index"}
index
Web
Consider the following code and predict the behaviour for the program. You can assume all the things imports and
dependency are done correctly.
com.example.sampleapplication
@SpringBootApplication
com.example.sampleapplication.controller
@Controller
@GetMapping("/index")
return "index";
index.jsp
Consider the above code and predict the behaviour for the application on the browser.
This will throw you an error because it is not able to find the JSP file.
{"key": "index"}
21/24
index
Web
Consider the following code. Assuming all the dependency and imports are done correctly.
com.example.sampleapplication
@SpringBootApplication
com.example.sampleapplication.controller
@RestController
@GetMapping("/index")
com.example.sampleapplication.model
super();
this.number1 = number1;
this.number2 = number2;
return number1;
this.number1 = number1;
22/24
}
return number2;
this.number2 = number2;
{"number1":24,"number2":12}
number1: 24
Number2: 12
{"number1":12,"number2":24}
Annotation
Consider the following coding structure and Fill in the details for the application
com.example.sampleapplication
@SpringBootApplication
com.example.sampleapplication.controller
@RestController
@___________________
23/24
private SampleModelService sampleModelService;
@GetMapping("/index")
return output;
com.example.sampleapplication.model
com.example.sampleapplication.dao
com.example.sampleapplication.service
Assuming import and dependency are done properly, Please fill in the blanks for the same.
Autowired
Service
Repository
Entity
24/24