Java Interview Preparation
Important Annotations Interview Questions
Core Spring and Spring Boot annotations for configuration, components, and properties.
Important Annotations Interview Focus
Core Spring and Spring Boot annotations for configuration, components, and properties.
Interview questions
1. What does @SpringBootApplication contain internally? Intermediate
@SpringBootApplication combines @SpringBootConfiguration, @EnableAutoConfiguration, and @ComponentScan. Together they mark the main configuration class, enable conditional setup, and scan the application package.
2. What is the difference between @Configuration, @ComponentScan, and @EnableAutoConfiguration? Intermediate
@EnableAutoConfiguration tells Spring Boot to consider its auto-configuration classes. @SpringBootApplication already includes this annotation, so it is rarely written separately.
3. What is the difference between @Component, @Service, @Repository, and @Controller? Beginner
All four are component stereotypes detected during scanning. @Component is general, @Service represents business logic, @Repository represents persistence and translates database exceptions, and @Controller handles web requests.
4. What is the difference between @Controller and @RestController? Beginner
@RestController combines @Controller and @ResponseBody, so handler results are written directly as JSON or another response body. A normal @Controller usually returns a view name unless a method uses @ResponseBody.
5. What is the difference between @Bean and @Component? Intermediate
@Component is placed on a class discovered by component scanning. @Bean is placed on a method inside configuration and is useful when creating a third-party class or when construction needs custom code.
6. What is the purpose of @Configuration? Beginner
@Configuration marks a class as a source of bean definitions. Methods annotated with @Bean are registered in the ApplicationContext and can receive injected dependencies.
7. What is the purpose of @Value? Beginner
@Value injects one property or expression into a field, constructor parameter, or method parameter. It is convenient for a small number of values, but grouped settings are usually clearer with @ConfigurationProperties.
8. What is the purpose of @ConfigurationProperties? Intermediate
@Configuration marks a class as a source of bean definitions. Methods annotated with @Bean are registered in the ApplicationContext and can receive injected dependencies.
9. What is the difference between @Value and @ConfigurationProperties? Intermediate
@Value is concise for individual values. @ConfigurationProperties is better for a related group of settings because it provides a typed object, clear prefixes, and validation.
10. What is the purpose of @Profile? Beginner
@Profile limits a bean or configuration class to selected environments such as dev, test, or prod. The active profile decides which definitions are loaded.
How to Prepare for Java Technical Interviews
Use this Java technical interview question bank to revise core concepts and practise explaining your decisions clearly. The questions cover Java fundamentals, object-oriented programming, collections, exceptions, multithreading, Spring Boot, Hibernate, databases, and other topics used in real software development interviews.
Start with the fundamentals, then move to scenario-based questions and advanced topics. Filter questions by difficulty to build confidence gradually. A strong answer should define the concept, explain why it matters, and include a practical example when appropriate.
Continue your preparation with the Java tutorials, or explore all interview preparation tracks for managerial and company-focused questions.
