









































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A practice exam for the vmware tanzu developer java certification. It includes multiple-choice questions covering topics such as dependency injection, ioc containers, bean scopes, component scanning, aop, and spring boot. Each question is followed by the correct answer and a brief explanation. This practice exam is designed to help developers prepare for the certification exam and test their knowledge of spring framework concepts. It provides a valuable resource for understanding key concepts and identifying areas for further study. The questions cover a wide range of topics relevant to java development with spring, making it a comprehensive study aid. Use this practice exam to assess your readiness and improve your understanding of spring development.
Typology: Exams
1 / 81
This page cannot be seen from the preview
Don't miss anything!










































































Question 1. What is the primary advantage of using Dependency Injection in the Spring Framework? A) Reduces boilerplate code B) Provides more control over object creation C) Promotes loose coupling and easier testing D) Increases runtime performance Answer: C Explanation: Dependency Injection encourages loose coupling between components, making the application easier to maintain and test. Question 2. Which interface is considered the foundational IoC container in Spring? A) BeanFactory B) ApplicationContext C) ConfigurableListableBeanFactory D) Environment Answer: A Explanation: BeanFactory is the basic IoC container in Spring, handling bean instantiation and wiring. Question 3. What is the recommended IoC container implementation for modern Spring applications? A) BeanFactory B) ApplicationContext C) ResourceLoader D) WebApplicationContext Answer: B Explanation: ApplicationContext extends BeanFactory and adds many features, making it the preferred container.
Question 4. Which ApplicationContext implementation is used for Java-based configuration? A) ClassPathXmlApplicationContext B) FileSystemXmlApplicationContext C) AnnotationConfigApplicationContext D) GenericWebApplicationContext Answer: C Explanation: AnnotationConfigApplicationContext is used for registering beans using Java configuration classes. Question 5. What annotation is used to define a configuration class in Spring? A) @Bean B) @Component C) @Configuration D) @Service Answer: C Explanation: @Configuration designates a class as a source of bean definitions. Question 6. Which annotation is used to declare a bean inside a @Configuration class? A) @Component B) @Bean C) @Autowired D) @Service Answer: B Explanation: @Bean tells Spring to instantiate, configure, and manage the object returned by the method.
A) Constructor, setter, and field injection B) Only field injection C) Only constructor injection D) Only setter injection Answer: A Explanation: @Autowired can be used for constructor, setter, and field injection. Question 11. What happens if you use @Autowired on a dependency that cannot be found? A) Spring throws an exception by default B) Spring ignores the missing dependency C) Spring uses a default value D) Spring logs a warning only Answer: A Explanation: By default, @Autowired requires the dependency and throws an exception if not found. Question 12. How can you make an @Autowired dependency optional? A) @Autowired(required=false) B) @Autowired(optional=true) C) @Optional D) @Autowired(ignore=true) Answer: A Explanation: Setting required=false makes the dependency optional. Question 13. Which annotation helps resolve multiple bean injection conflicts? A) @Primary
B) @Qualifier C) @Autowired D) @Bean Answer: B Explanation: @Qualifier specifies which bean to inject when multiple candidates are present. Question 14. Which annotation can be used on a bean to mark it as the default choice? A) @Default B) @Primary C) @Qualifier D) @Autowired Answer: B Explanation: @Primary marks a bean as the default for autowiring when multiple beans are available. Question 15. What does component scanning achieve in Spring? A) Registers beans defined in XML only B) Automatically detects and registers beans with stereotype annotations C) Scans for bean definitions in Java configuration only D) Loads properties files for beans Answer: B Explanation: Component scanning finds classes annotated with stereotypes and registers them as beans. Question 16. Which stereotype annotation is suitable for a Service layer bean? A) @Component B) @Service
D) @Component(basePackages = {"com.example"}) Answer: A Explanation: @ComponentScan allows you to specify which packages to scan. Question 20. What is the first phase in the Spring bean lifecycle? A) Initialization B) Instantiation C) Destruction D) Population of properties Answer: B Explanation: Bean lifecycle starts with instantiation. Question 21. Which annotation is used to define a method to run after bean initialization? A) @PostConstruct B) @PreDestroy C) @Init D) @Setup Answer: A Explanation: @PostConstruct marks a method to run after the bean has been initialized. Question 22. How can you specify a custom destroy method for a bean? A) @Bean(destroyMethod = "cleanup") B) @DestroyMethod("cleanup") C) @PreDestroy("cleanup") D) @Bean(cleanupMethod = "cleanup")
Answer: A Explanation: destroyMethod attribute in @Bean specifies the custom destroy method. Question 23. Which interface allows you to modify bean instances after their creation but before initialization? A) BeanFactoryPostProcessor B) BeanPostProcessor C) ApplicationListener D) DisposableBean Answer: B Explanation: BeanPostProcessor lets you customize beans before and after initialization. Question 24. What is the order of invocation between BeanFactoryPostProcessor and BeanPostProcessor? A) BeanPostProcessor first B) BeanFactoryPostProcessor first C) Simultaneous invocation D) No defined order Answer: B Explanation: BeanFactoryPostProcessor is invoked before BeanPostProcessor. Question 25. What is the main purpose of Spring proxies? A) To provide thread safety B) To add runtime behavior like AOP and transactions C) To enable bean destruction D) To optimize bean instantiation
Explanation: It matches all methods in any class with 'Service' suffix in com.example. Question 29. Which proxy type does Spring use for beans with interfaces? A) CGLIB proxy B) JDK dynamic proxy C) Static proxy D) Manual proxy Answer: B Explanation: Spring uses JDK dynamic proxies for beans that implement interfaces. Question 30. Which proxy type is used for beans without interfaces? A) JDK dynamic proxy B) CGLIB proxy C) Java reflection proxy D) Manual proxy Answer: B Explanation: CGLIB proxies subclass the target class if no interface is present. Question 31. What is the primary goal of Spring Boot? A) To simplify XML configuration B) To enable rapid cloud-native application development C) To support legacy applications D) To improve bean performance Answer: B Explanation: Spring Boot focuses on convention over configuration for rapid development.
Question 32. Which feature allows Spring Boot to manage dependency versions automatically? A) Dependency Injection B) Starter dependencies C) BOM (Bill of Materials) D) ApplicationContext Answer: C Explanation: BOM allows Spring Boot to control dependency versions centrally. Question 33. What annotation is used to bootstrap a Spring Boot application? A) @SpringBootApplication B) @EnableAutoConfiguration C) @ComponentScan D) @Configuration Answer: A Explanation: @SpringBootApplication combines several annotations to start a Spring Boot app. Question 34. What mechanism does Spring Boot use to configure beans automatically? A) External configuration B) Autoconfiguration C) Manual configuration D) XML configuration Answer: B Explanation: Autoconfiguration automatically sets up beans based on classpath and settings.
A) @InjectProperty B) @Property C) @Value D) @Autowired Answer: C Explanation: @Value injects property values directly into fields, methods, or constructor parameters. Question 39. What annotation is used to activate a Spring profile? A) @ActivateProfile B) @Profile C) @SpringProfile D) @EnableProfile Answer: B Explanation: @Profile marks beans for activation in specific environments. Question 40. How can you activate a Spring profile from the command line? A) --spring.profiles.active=prod B) --profile=prod C) --activate=prod D) --spring.profile=prod Answer: A Explanation: spring.profiles.active sets the active profile via command line. Question 41. What is the purpose of Spring Expression Language (SpEL)? A) To write SQL queries
B) To inject property values and manipulate objects dynamically C) To define bean scopes D) To configure external properties Answer: B Explanation: SpEL allows dynamic value injection and manipulation within bean definitions. Question 42. Which file format can be used for external configuration in Spring Boot? A) .xml only B) .properties only C) .yml and .properties D) .json only Answer: C Explanation: Spring Boot supports both .yml and .properties for configuration. Question 43. Which endpoint does Spring Boot Actuator expose for health checks? A) /metrics B) /health C) /info D) /env Answer: B Explanation: /health endpoint provides application health status. Question 44. How do you customize exposed Actuator endpoints in Spring Boot? A) management.endpoints.web.expose B) management.endpoints.web.exposure.include/exclude
D) @Dispose Answer: B Explanation: @PreDestroy marks a method to run before the bean is destroyed. Question 48. What does @ComponentScan do? A) Scans for beans annotated with @Bean B) Scans for classes annotated with stereotypes and registers them as beans C) Scans for XML configuration files D) Loads external properties Answer: B Explanation: @ComponentScan detects stereotype-annotated classes for bean registration. Question 49. How does Spring Boot determine which configuration classes to load? A) By scanning all classes B) By looking for @SpringBootApplication C) By searching for @Component D) By XML configuration Answer: B Explanation: @SpringBootApplication identifies the primary configuration class. Question 50. How do you define a prototype scoped bean? A) @Scope("prototype") B) @PrototypeBean C) @Bean(prototype=true) D) @Scope("singleton")
Answer: A Explanation: @Scope("prototype") creates a new bean instance for every request. Question 51. What is the main benefit of using @Qualifier? A) Prevents bean initialization errors B) Resolves ambiguity when multiple beans of the same type exist C) Sets bean scope D) Configures bean destruction Answer: B Explanation: @Qualifier specifies which bean to inject among multiple candidates. Question 52. Which method runs after all properties are set in a bean? A) afterPropertiesSet() B) postInitialization() C) initialize() D) onSetup() Answer: A Explanation: afterPropertiesSet() from InitializingBean interface runs after properties are set. Question 53. What does @RestController combine? A) @Controller and @RequestMapping B) @Controller and @ResponseBody C) @Service and @Controller D) @Component and @Controller Answer: B
Question 57. What does the @Autowired annotation do if multiple beans of the same type exist and no @Qualifier is specified? A) Throws an exception B) Uses @Primary bean C) Uses the first bean found D) Ignores injection Answer: B Explanation: If a @Primary bean exists, it is injected by default. Question 58. Which annotation is used to inject environment variables into beans? A) @Environment B) @Value C) @Autowired D) @EnvInject Answer: B Explanation: @Value can inject environment variables using their keys. Question 59. What is the role of Spring Boot starter dependencies? A) To provide default configurations B) To simplify dependency management by grouping related libraries C) To enable XML configuration D) To define bean scopes Answer: B Explanation: Starters group related dependencies to simplify setup.
Question 60. How can you override default auto-configurations in Spring Boot? A) By providing your own bean definitions B) By disabling auto-config C) By using custom properties files D) By modifying the BOM Answer: A Explanation: Defining your own beans overrides defaults. Question 61. What is the purpose of @ConditionalOnMissingBean? A) To configure a bean only if a class is present B) To configure a bean only if no bean of that type exists C) To inject missing beans D) To mark beans for autowiring Answer: B Explanation: @ConditionalOnMissingBean configures beans only if not already present. Question 62. Which annotation defines a method to run before bean destruction? A) @PreDestroy B) @PostConstruct C) @BeforeDestroy D) @Destroy Answer: A Explanation: @PreDestroy marks destruction callback methods. Question 63. What is the primary function of BeanFactoryPostProcessor?