Docsity

WGU D287 — JAVA FRAMEWORKS | COMPREHENSIVE OBJECTIVE ASSESSMENT | STUDY GUIDE | LATEST U, Exams of Computer Science

Toggle sidebar
bg1
W G U D 2 8 7 | 1
WGU D287 — JAVA FRAMEWORKS |
COMPREHENSIVE OBJECTIVE ASSESSMENT |
STUDY GUIDE | LATEST UPDATE 2026/2027 |
PRACTICE QUESTIONS AND ANSWERS | EXAM
REVIEW
Table of Contents
1. Spring Core: IoC Container and Dependency Injection
2. Spring Bean Lifecycle and Scopes
3. Spring Boot Fundamentals and Auto-Configuration
4. Spring MVC: Controllers and Request Mapping
5. Building RESTful Web Services
6. Spring Data JPA and Repository Patterns
7. Spring Security: Authentication and Authorization
8. Testing Spring Applications
9. Application Properties and Profiles
10. Spring AOP and Cross-Cutting Concerns
11. Exception Handling in Spring
12. Spring Boot Actuator and Monitoring
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download WGU D287 — JAVA FRAMEWORKS | COMPREHENSIVE OBJECTIVE ASSESSMENT | STUDY GUIDE | LATEST U and more Exams Computer Science in PDF only on Docsity!

WGU D287 — JAVA FRAMEWORKS |

COMPREHENSIVE OBJECTIVE ASSESSMENT |

STUDY GUIDE | LATEST UPDATE 2026/2027 |

PRACTICE QUESTIONS AND ANSWERS | EXAM

REVIEW

Table of Contents

_1. Spring Core: IoC Container and Dependency Injection

  1. Spring Bean Lifecycle and Scopes
  2. Spring Boot Fundamentals and Auto-Configuration
  3. Spring MVC: Controllers and Request Mapping
  4. Building RESTful Web Services
  5. Spring Data JPA and Repository Patterns
  6. Spring Security: Authentication and Authorization
  7. Testing Spring Applications
  8. Application Properties and Profiles
  9. Spring AOP and Cross-Cutting Concerns
  10. Exception Handling in Spring
  11. Spring Boot Actuator and Monitoring_

Question 1: What is the primary purpose of the Spring Framework? A. To replace the Java programming language B. To simplify enterprise Java development by providing infrastructure support C. To create mobile applications D. To manage database schemas only Correct Answer: B. To simplify enterprise Java development by providing infrastructure support The Spring Framework is an application framework that provides comprehensive infrastructure support for developing Java applications. It handles the plumbing of enterprise applications so developers can focus on business logic. Spring's core features include dependency injection, aspect-oriented programming, and transaction management. Question 2: What is Inversion of Control (IoC) in the context of Spring? A. A design principle where the framework controls the flow of the program and object creation B. A method for reversing strings C. A type of database transaction D. A security mechanism Correct Answer: A. A design principle where the framework controls the flow of the program and object creation Inversion of Control is a design principle in which the control of object creation and lifecycle is transferred from the application code to the framework. Instead of the application creating objects directly, the Spring IoC container creates and manages them. This promotes loose coupling and easier testing. Question 3: What is Dependency Injection in Spring? A. A technique where objects receive their dependencies from an external source rather than creating them B. A method for injecting SQL queries C. A type of database connection D. A security vulnerability Correct Answer: A. A technique where objects receive their dependencies from an external source rather than creating them Dependency Injection is a design pattern that implements IoC. Objects declare their

Correct Answer: A. To automatically inject dependencies into a Spring bean The @Autowired annotation is used for automatic dependency injection. Spring resolves and injects the required dependency based on type (and optionally by name). It can be applied to constructors, setters, fields, or methods. Question 7: Which injection type is recommended for mandatory dependencies in Spring? A. Field injection B. Setter injection C. Constructor injection D. Method injection Correct Answer: C. Constructor injection Constructor injection is recommended for mandatory dependencies because it ensures the object is created with all required dependencies, supports immutability, and makes testing easier. Field injection is discouraged because it hides dependencies and makes testing harder. Setter injection is suitable for optional dependencies. Question 8: What is the difference between @Bean and @Component? A. @Bean is used on methods in configuration classes; @Component is used on classes B. @Bean is used on classes; @Component is used on methods C. They are identical D. @Bean is for databases; @Component is for web Correct Answer: A. @Bean is used on methods in configuration classes; @Component is used on classes @Bean is applied to methods within @Configuration classes to explicitly declare a bean. @Component is applied to classes and is detected through component scanning. @Bean gives you more control over bean creation, while @Component is more declarative. Question 9: What is the default scope of a Spring bean? A. Prototype B. Request C. Singleton D. Session

Correct Answer: C. Singleton By default, Spring beans are singleton-scoped, meaning only one instance of the bean is created and shared throughout the application context. Other scopes include prototype (new instance each time), request, session, and application. Singleton is the most common scope for stateless services. Question 10: What is the difference between singleton and prototype bean scopes? A. Singleton creates one instance; prototype creates a new instance each time it is requested B. Singleton creates multiple instances; prototype creates one instance C. They are the same D. Singleton is for web apps; prototype is for desktop apps Correct Answer: A. Singleton creates one instance; prototype creates a new instance each time it is requested Singleton scope creates a single shared instance per Spring container. Prototype scope creates a new instance every time the bean is requested from the container. Singleton is suitable for stateless beans, while prototype is used for stateful beans. Question 11: What is the purpose of the @Configuration annotation? A. To indicate that a class contains bean definitions B. To configure a database C. To create a REST controller D. To handle exceptions Correct Answer: A. To indicate that a class contains bean definitions The @Configuration annotation marks a class as a source of bean definitions. Methods annotated with @Bean within a @Configuration class are processed by the Spring container to create and manage beans. It is a core annotation for Java-based configuration. Question 12: What is component scanning in Spring? A. The process of automatically detecting and registering beans from the classpath B. The process of scanning a database C. The process of validating user input D. The process of encrypting data Correct Answer: A. The process of automatically detecting and registering beans from the classpath

Correct Answer: A. A set of convenient dependency descriptors that can be included in your application Spring Boot starters are curated sets of dependencies that simplify build configuration. For example, spring-boot-starter-web includes Spring MVC, Jackson, and an embedded Tomcat server. Starters reduce the need to specify individual dependency versions manually. Question 16: What is the purpose of the application.properties file in Spring Boot? A. To configure application properties such as server port, database connections, and logging B. To define Java classes C. To create REST endpoints D. To handle exceptions Correct Answer: A. To configure application properties such as server port, database connections, and logging The application.properties file (or application.yml ) is the central configuration file in Spring Boot. It allows you to externalize configuration, such as server.port=8081 , spring.datasource.url=jdbc:mysql://... , and logging levels. Properties can also be set via environment variables or command-line arguments. Question 17: What is a Spring Boot profile? A. A way to define different configurations for different environments (e.g., dev, test, prod) B. A user profile in the application C. A type of database D. A security role Correct Answer: A. A way to define different configurations for different environments (e.g., dev, test, prod) Spring Boot profiles allow you to define environment-specific configurations. You can create files like application-dev.properties and application-prod.properties_. Activating a profile (e.g.,_ spring.profiles.active=dev ) loads the corresponding properties. This is essential for managing different deployment environments. Question 18: What is the purpose of the @RestController annotation? A. It combines @Controller and @ResponseBody, simplifying REST API development B. It creates a new Spring Boot application C. It configures a database D. It handles security

Correct Answer: A. It combines @Controller and @ResponseBody , simplifying REST API development @RestController is a convenience annotation that combines @Controller and @ResponseBody_. It indicates that the class handles REST requests, and the return values of its methods are automatically serialized to the response body (typically as JSON or XML)._ Question 19: What is the purpose of the @RequestMapping annotation? A. To map HTTP requests to handler methods or classes B. To create a database table C. To define a bean D. To configure security Correct Answer: A. To map HTTP requests to handler methods or classes The @RequestMapping annotation is used to map web requests to specific handler classes or methods. It can specify the URL path, HTTP method, request parameters, headers, and media types. It is the foundation for request mapping in Spring MVC. Question 20: What is the difference between @GetMapping and @PostMapping? A. @GetMapping handles HTTP GET requests; @PostMapping handles HTTP POST requests B. @GetMapping handles POST; @PostMapping handles GET C. They are the same D. @GetMapping is for databases; @PostMapping is for web Correct Answer: A. @GetMapping handles HTTP GET requests; @PostMapping handles HTTP POST requests @GetMapping is a specialized form of @RequestMapping for HTTP GET requests, typically used for retrieving data. @PostMapping is for HTTP POST requests, typically used for creating resources. Similar annotations exist for PUT, DELETE, and PATCH. Question 21: What is the purpose of the @PathVariable annotation? A. To extract values from the URI path B. To extract values from query parameters C. To extract values from the request body D. To extract values from headers

XML) and write it directly to the HTTP response body. It is automatically applied when using @RestController_._ Question 25: What is the purpose of the ResponseEntity class in Spring? A. To represent the entire HTTP response, including status code, headers, and body B. To represent only the response body C. To represent the request D. To handle exceptions Correct Answer: A. To represent the entire HTTP response, including status code, headers, and body ResponseEntity gives you full control over the HTTP response, including the status code, headers, and body. It is useful for returning different status codes based on the outcome of an operation, such as 200 OK, 201 Created, or 404 Not Found. Question 26: What is the correct way to return a 201 Created status with a body in a REST controller? A. return ResponseEntity.status(HttpStatus.CREATED).body(createdResource); B. return new ResponseEntity(createdResource); C. return createdResource; D. return HttpStatus.CREATED; Correct Answer: A. return ResponseEntity.status(HttpStatus.CREATED).body(createdResource); ResponseEntity.status(HttpStatus.CREATED) sets the status code to 201, and .body(createdResource) sets the response body. This is the standard way to return a specific status code with a body in Spring REST controllers. Question 27: What is the purpose of the @Service annotation? A. To mark a class as a service layer component B. To create a REST endpoint C. To configure a database D. To handle security Correct Answer: A. To mark a class as a service layer component @Service is a specialization of @Component that indicates the class holds business logic. It

is a semantic annotation that improves readability and is typically used in the service layer of an application. It is detected by component scanning. Question 28: What is the purpose of the @Repository annotation? A. To mark a class as a data access component and enable exception translation B. To create a REST endpoint C. To configure a database connection D. To handle security Correct Answer: A. To mark a class as a data access component and enable exception translation @Repository is a specialization of @Component for data access classes. It enables automatic exception translation, converting database-specific exceptions into Spring's DataAccessException hierarchy. This provides a consistent exception model across different persistence technologies. Question 29: What is Spring Data JPA? A. A Spring module that simplifies data access using the Java Persistence API B. A database management system C. A web framework D. A security framework Correct Answer: A. A Spring module that simplifies data access using the Java Persistence API Spring Data JPA is a module that provides repository abstractions for JPA-based data access. It reduces boilerplate code by automatically implementing repository interfaces. Developers can define query methods by following naming conventions or using @Query annotations. Question 30: What is the purpose of the JpaRepository interface? A. To provide CRUD operations and additional JPA-specific methods B. To create REST endpoints C. To configure security D. To handle exceptions Correct Answer: A. To provide CRUD operations and additional JPA-specific methods JpaRepository extends PagingAndSortingRepository and provides standard CRUD

Language) or native SQL. It is used when query derivation is not sufficient or when you need more control over the query. The annotation is placed on repository methods. Question 34: What is the purpose of the @Entity annotation? A. To mark a class as a JPA entity mapped to a database table B. To create a REST endpoint C. To configure a service D. To handle security Correct Answer: A. To mark a class as a JPA entity mapped to a database table @Entity is a JPA annotation that marks a class as an entity, meaning it will be mapped to a database table. Each instance of the entity represents a row in the table. The class must have a no-argument constructor and a primary key annotated with @Id_._ Question 35: What is the purpose of the @Id annotation in JPA? A. To specify the primary key of an entity B. To specify a foreign key C. To specify a column name D. To specify a table name Correct Answer: A. To specify the primary key of an entity @Id marks a field as the primary key of the entity. It is required for every JPA entity. The primary key uniquely identifies each row in the database table. Common generation strategies include @GeneratedValue(strategy = GenerationType.IDENTITY). Question 36: What is the purpose of the @GeneratedValue annotation? A. To specify how the primary key value is generated B. To generate a new entity C. To generate a query D. To generate a table Correct Answer: A. To specify how the primary key value is generated @GeneratedValue specifies the generation strategy for the primary key. Common strategies include IDENTITY (auto-increment), SEQUENCE (database sequence), TABLE (separate table), and AUTO (provider chooses). It is used in conjunction with @Id_._ Question 37: What is the purpose of the @Transactional annotation? A. To define the scope of a single database transaction

B. To create a database table C. To configure a data source D. To handle exceptions Correct Answer: A. To define the scope of a single database transaction @Transactional is used to demarcate transaction boundaries. Methods annotated with it run within a transaction, and the transaction is committed or rolled back based on whether an exception occurs. It can be applied at the class or method level. Question 38: What is the purpose of Spring Security? A. To provide authentication, authorization, and protection against common security vulnerabilities B. To manage database connections C. To create REST endpoints D. To handle exceptions Correct Answer: A. To provide authentication, authorization, and protection against common security vulnerabilities Spring Security is a powerful and customizable authentication and access-control framework. It provides features for authentication (verifying identity), authorization (controlling access), and protection against attacks like CSRF, session fixation, and clickjacking. Question 39: What is the purpose of the @EnableWebSecurity annotation? A. To enable Spring Security's web security support B. To create a REST endpoint C. To configure a database D. To handle exceptions Correct Answer: A. To enable Spring Security's web security support @EnableWebSecurity is used on a @Configuration class to enable Spring Security's web security support. It typically accompanies a SecurityFilterChain bean definition that configures security rules such as which endpoints require authentication. Question 40: What is a SecurityFilterChain in Spring Security? A. A bean that defines the security filter chain and configures security rules B. A database connection pool

C. To configure security filters D. To handle exceptions Correct Answer: A. To load user-specific data during authentication UserDetailsService is a core interface in Spring Security that loads user-specific data. It has a single method, loadUserByUsername(String username) , which returns a UserDetails object containing the user's credentials, authorities, and account status. It is used by the authentication provider. Question 44: What is the purpose of the PasswordEncoder interface in Spring Security? A. To encode and verify passwords securely B. To encrypt database connections C. To encode URLs D. To encode JSON Correct Answer: A. To encode and verify passwords securely PasswordEncoder is used to encode passwords before storing them and to verify a raw password against an encoded one. Common implementations include BCryptPasswordEncoder (recommended), Pbkdf2PasswordEncoder , and Argon2PasswordEncoder_. Passwords should never be stored in plain text._ Question 45: What is CSRF and how does Spring Security protect against it? A. Cross-Site Request Forgery; Spring Security uses CSRF tokens to validate requests B. Cross-Site Request Forgery; Spring Security encrypts all requests C. Cross-Site Scripting; Spring Security sanitizes input D. SQL Injection; Spring Security uses parameterized queries Correct Answer: A. Cross-Site Request Forgery; Spring Security uses CSRF tokens to validate requests CSRF is an attack that tricks a user's browser into making unwanted requests to a site where they are authenticated. Spring Security protects against CSRF by default by requiring a CSRF token for state-changing requests (POST, PUT, DELETE). The token is included in forms and validated on the server. Question 46: What is the purpose of the @SpringBootTest annotation? A. To create an application context for integration testing B. To test only a single controller

C. To mock dependencies D. To configure a database Correct Answer: A. To create an application context for integration testing @SpringBootTest is used for integration testing. It loads the full application context, including all beans and configuration. It can be configured with web environment modes (MOCK, RANDOM_PORT, DEFINED_PORT, NONE). It is heavier than slice tests but provides more realistic testing. Question 47: What is the purpose of the @WebMvcTest annotation? A. To test only the web layer (controllers) without loading the full application context B. To test the entire application C. To test database repositories D. To test security configuration Correct Answer: A. To test only the web layer (controllers) without loading the full application context @WebMvcTest is a slice test annotation that focuses only on the web layer. It loads only the specified controllers and related MVC infrastructure, not the full application context. Dependencies like services are typically mocked using @MockBean_. It is faster than_ @SpringBootTest_._ Question 48: What is the purpose of MockMvc in Spring testing? A. To simulate HTTP requests and test controllers without starting a server B. To mock database connections C. To mock security D. To create a test database Correct Answer: A. To simulate HTTP requests and test controllers without starting a server MockMvc is a testing utility that allows you to test Spring MVC controllers by simulating HTTP requests. It provides a fluent API for performing requests, setting parameters, and asserting responses. It does not require an actual server, making tests faster. Question 49: What is the purpose of the @MockBean annotation in Spring Boot testing? A. To add a Mockito mock to the Spring application context B. To create a real bean

C. A type of aspect D. A type of bean Correct Answer: A. An expression that selects join points where advice should be applied A pointcut is a predicate that matches join points (e.g., method executions). It defines where advice should be applied. Spring AOP uses AspectJ pointcut expressions, such as execution(* com.example.service..(..)). Question 53: What is the purpose of the @Aspect annotation? A. To mark a class as an aspect containing advice and pointcuts B. To create a REST endpoint C. To configure a database D. To handle exceptions Correct Answer: A. To mark a class as an aspect containing advice and pointcuts @Aspect marks a class as an aspect. The class contains advice (behavior to apply) and pointcuts (where to apply it). Spring AOP supports various advice types: @Before , @After , @AfterReturning , @AfterThrowing , and @Around_._ Question 54: What is the difference between @Before and @After advice in Spring AOP? A. @Before runs before the join point; @After runs after the join point B. @Before runs after; @After runs before C. They are the same D. @Before is for security; @After is for logging Correct Answer: A. @Before runs before the join point; @After runs after the join point @Before advice executes before the matched method. @After advice executes after the method, regardless of its outcome. Other advice types include @AfterReturning (only on successful return) and @AfterThrowing (only on exception). Question 55: What is the purpose of the @ControllerAdvice annotation? A. To handle exceptions globally across controllers B. To create a new controller C. To configure a database D. To handle security

Correct Answer: A. To handle exceptions globally across controllers @ControllerAdvice is used to define global exception handlers, data binders, and model attributes for all controllers. Methods annotated with @ExceptionHandler within a @ControllerAdvice class handle exceptions thrown by any controller. @RestControllerAdvice combines it with @ResponseBody_._ Question 56: What is the purpose of the @ExceptionHandler annotation? A. To handle specific exceptions thrown by controller methods B. To create a new exception C. To configure a database D. To handle security Correct Answer: A. To handle specific exceptions thrown by controller methods @ExceptionHandler marks a method to handle specific exception types. It can be used within a controller or a @ControllerAdvice class for global handling. The method can return a ResponseEntity with an appropriate status code and error details. Question 57: What is the correct way to handle a custom exception and return a 404 status? A. @ExceptionHandler(ResourceNotFoundException.class) public ResponseEntity handleNotFound() { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Not found"); } B. @ExceptionHandler public void handleNotFound() {} C. @ExceptionHandler(ResourceNotFoundException.class) public String handleNotFound() { return "Not found"; } D. @ExceptionHandler(ResourceNotFoundException.class) public void handleNotFound() {} Correct Answer: A. @ExceptionHandler(ResourceNotFoundException.class) public ResponseEntity handleNotFound() { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Not found"); } The correct handler method should be annotated with @ExceptionHandler , specify the exception type, and return a ResponseEntity with the appropriate status code and body. This allows the API to return a structured error response. Question 58: What is the purpose of Spring Boot Actuator? A. To provide production-ready features such as health checks, metrics, and monitoring B. To create REST endpoints