Spring Boot/Spring MVC MCQ QUESTIONS AND ANSWER Sample Test,Sample questions

Question:
 How can you access request parameters in a Spring MVC controller method?

1.By using the @RequestParam annotation.

2. By accessing them directly from the HttpServletRequest object.

3.By using the @PathVariable annotation.

4. By using the @RequestHeader annotation.


Question:
 How can you define custom database queries in Spring Data JPA?

1.Using XML configuration files.

2.Using SQL scripts executed during application startup.

3.Using the @Query annotation and JPQL or native SQL queries.

4.Using external SQL files loaded at runtime.


Question:
 In JPA, which strategy generates a primary key assigned by the database?

1.GenerationType.AUTO

2.GenerationType.SEQUENCE

3.GenerationType.IDENTITY

4.GenerationType.TABLE


Question:
 In Spring MVC, what is the role of the ViewResolver?

1.Resolving bean dependencies

2.Handling exceptions

3.Resolving views to specific URLs

4.Handling request parameters


Question:
 What does the @ResponseBody annotation do?

1.It sends the return value of a method back to the web response body.

2. It binds the parameters of a method to the request body.

3.It triggers an exception handling method.

4. It binds the result of a method to a view.


Question:
 What does the @Valid annotation in Spring MVC do?

1.It ensures that the method is correctly overridden from a superclass.

2. It triggers validation of a method parameter or field.

3. It ensures that an HTTP request is valid.

4.It validates the return type of a method.


Question:
 Which annotation is used to autowire a repository into a Spring component?

1.InjectRepository

2.AutoInject

3.Autowire

4.Resource


Question:
Choose the correct Query Method:

1.findByFirstNameOrLastName(String firstName, String lastName)

2. findByFirstNameAndLastName(String firstName, String lastName)

3.findByFirstNameOrLastName(Student student)

4.findByFirstNameLastName(String firstName, String lastName)


Question:
How can you control transaction management in Spring Data JPA?

1.By using the @Transactional annotation.

2. By configuring the transaction properties in the application.properties file.

3.By extending the JpaTransactionManager class.

4.By adding the @EnableTransactionManagement annotation to the configuration class


Question:
How can you customize the column name for a field in a JPA entity?

1.Column(name="custom_name")

2.FieldName("custom_name")

3.TableColumn("custom_name")

4.DatabaseColumn("custom_name")


Question:
How can you define a derived query in Spring Data JPA?

1.By annotating a method with @Query

2. By creating a method in the repository with a specific naming convention

3. By using the @DerivedQuery annotation

4.By creating an XML configuration


Question:
How can you handle exceptions in Spring MVC?

1.@ExceptionHandler

2.@CatchException

3.@ErrorResolver

4.@ResolveError


Question:
How can you indicate a Many-To-One relationship in JPA?

1.ManyToOne

2.OneToMany

3.ManyToMany

4.OneToOne


Question:
How can you mark a field as the primary key in a JPA entity?

1.PrimaryKey

2.EntityKey

3.Id

4.Key


Question:
How can you perform pagination in Spring Data JPA?

1.Using the @Pageable annotation

2.Using the Page and Pageable interfaces

3.Using the @Pagination annotation

4.Using the Paginator class


Question:
How do you execute a native query in Spring Data JPA?

1.Native

2.SQL

3.Execute

4.Query(nativeQuery = true)


Question:
How do you redirect to another URL in Spring MVC?

1."redirect:/url_path"

2."forward:/url_path"

3.goto:/url_path"

4.move:/url_path"


Question:
How do you specify that a controller method should produce JSON as a response?

1. @Produces("application/json")

2.@ResponseBody(type="json")

3.@ResponseFormat("JSON")

4.@RequestMapping(produces="application/json")


Question:
In a Spring Data JPA repository, how can you indicate a method should delete by a specific field?

1.deleteByFieldName

2.removeByFieldName

3.eraseByFieldName

4.exterminateByFieldName


Question:
In which layer is Spring MVC used?

1.Data layer

2.Business layer

3.Presentation layer

4.Integration layer


Question:
What does MVC stand for in Spring MVC?

1.Multi-View Controller

2.Module-View-Controller

3.Model-View-Controller

4.Model-Value-Configuration


Question:
What is Spring MVC

1.A programming language for web development.

2. A lightweight Java framework for building web applications.

3.A database management system for web applications.

4.A library for handling server-side rendering.


Question:
What is the aim of Spring Data JPA?

1.Spring Data JPA aims to reduce the amount of boilerplate code required for common database operations.

2.Spring Data JPA aims to provide the implementation for JPA interfaces

3.Spring Data JPA is a JPA provider and implementation for JPA interfaces

4.Spring Data JPA is an ORM framework that provides an implementation for JPA interfaces


Question:
What is the default implementation class of the JpaRepository interface?

1.JpaRepositoryImpl class

2.SimpleJpaRepository class

3.DeafultJpaRepository class

4.SimpleCrudRepository class


Question:
What is the purpose of the @GeneratedValue annotation in Spring Data JPA?

1.To specify the table name for entity mapping.

2.To define the primary key column in an entity.

3.To configure the fetching strategy for related entities.

4.To automatically generate primary key values for entities.


Question:
What is the purpose of the ModelAndView object in Spring MVC?

1.To store and pass data between the controller and the view.

2.To define the layout and styling of the web application.

3.To handle user authentication and authorization.

4.To manage the application's data access layer.


Question:
Which annotation binds a method parameter to a named attribute?

1.@ModelAttribute

2.@ParameterAttribute

3.@BindAttribute

4.@RequestValue


Question:
Which annotation in JPA allows you to embed another object as part of your entity?

1.Embeddable

2.Embedded

3.Include

4.PartOf


Question:
Which annotation in JPA allows you to embed another object as part of your entity?

1.Embeddable

2.Embedded

3.Include

4.PartOf


Question:
Which annotation indicates a method should handle HTTP POST requests?

1.@HttpPost

2.@PostHandler

3.@RequestMapping(method = RequestMethod.POST)

4.@PostMapping


Question:
Which annotation is commonly used to mark a repository interface in Spring Data JPA?

1.Service

2.Component

3.Controller

4.Repository


Question:
Which annotation is used to bind a method parameter to a web request header?

1.@RequestHeader

2.@Header

3.@BindHeader

4.@HTTPHeader


Question:
Which annotation is used to create a Named JPQL query?

1.NamedQuery

2.NamedJPQLQuery

3.NamedNativeQuery

4.SQLQuery


Question:
Which annotation is used to create a Spring MVC controller class?

1.@ControllerBean

2.@SpringController

3.@WebController

4.@Controller


Question:
Which annotation is used to denote a regular expression in URI template in Spring MVC?

1.@Regex

2.@PathVariable

3.@URIExpression

4.@MatchPattern


Question:
Which annotation is used to specify a custom query in Spring Data JPA?

1.CustomQuery

2.JPAQuery

3.Query

4.ExecuteQuery


Question:
Which annotation marks a class as an entity in JPA?

1.EntityClass

2.JPAEntity

3.Entity

4.TableEntity


Question:
Which dependency is required to use Spring Data JPA in a Spring Boot application?

1.spring-boot-starter-data-jpa

2.spring-boot-starter-web

3.spring-boot-starter-test

4.spring-boot-starter-security


Question:
Which interface do we extend to create a repository in Spring Data JPA?

1.Repository

2.JpaRepository

3.JpaRepository

4.SpringRepository


Question:
Which is the default JPA provider the Spring Data JPA internally uses?

1.EclipseLink

2.MyBatis

3.TopLink

4.Hibernate


Question:
Which of the following annotations is used to handle multipart file uploads?

1.@FileUpload

2.@MultipartFile

3.@RequestFile

4.@UploadPart


Question:
Which of the following components decides which controller method is to be called for a request?

1.DispatcherServlet

2.Controller

3.HandlerMapping

4.ViewResolver


Question:
Which of the following denotes a derived delete query in Spring Data JPA?

1.deleteByFieldName

2.findByFieldName

3.queryByFieldName

4.readByFieldName


Question:
Which of the following handles the HTTP request in Spring MVC?

1.DispatcherServlet

2.HandlerInterceptor

3.HttpListener

4.RequestHandler


Question:
Which of the following is NOT a fetch type in JPA?

1.EAGER

2.LAZY

3.IMMEDIATE

4.BOTH


Question:
Which of the following is NOT a valid Cascade type in JPA?C

1.PERSIST

2.REMOVE

3.MERGE

4.UPDATE


Question:
Which of the following represents a form-backing bean in Spring MVC?

1.@FormEntity

2.@ModelEntity

3.@ModelAttribute

4.@BeanForm


Question:
Which Spring annotation is used to handle Cross-Origin Resource Sharing (CORS) in Spring MVC?

1.CrossOrigin

2.CORSHandler

3.EnableCORS

4.CORSConfig


Question:
Which Spring Boot Starter would you use for developing web applications?

1.spring-boot-starter-web

2. spring-boot-starter-jdbc

3.spring-boot-starter-data

4. spring-boot-starter-app


Question:
Which Spring MVC module provides integration with RESTful services?

1.Spring RestController

2. Spring REST

3.Spring Web MVC

4. Spring WebFlux


More MCQS

  1. Spring Boot Common Test
  2. Spring Boot - Bootstrapping
  3. Spring Boot - Logging
  4. Spring Boot - Application Properties
  5. Spring Boot - RESTful Web Services
  6. Spring Boot - Exception Handling
  7. Spring Boot - Interceptor
  8. Spring Boot - File Handling
  9. Spring Boot - CORS
  10. Spring Boot - Internationalization
  11. Spring Boot - Scheduling
  12. Spring MCQs
  13. SPRING BOOT MCQ QUESTIONS
  14. Spring MVC MCQ QUESTIONS AND ANSWER
  15. Spring Cloud MCQ QUESTIONS AND ANSWER
  16. Spring WebFlux MCQ OUESTIONS AND ANSWER
Search
Olete Team
Online Exam TestTop Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on Online Exam Testwebsite is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!