Skip to main content

Spring Framework interview questions

Commands 

.\gradlew bootrun   --args='--server.port=8888'    to change the port number in the bootrun




Spring 

1. What is dependency injection

2. What is inversion of control

3. What is the role of IOC Container

4. Spring bean life cycle

5. What is ApplicationContext - IOC Conatiner, in addition it provide like AOP, internationalization, web application features

6. What is Beanfactory  - IOC conatiner, but only basic features (Memory constraint) 

7. How to define application context? using java @Configuration  or XML . AnnotationConfigApplicationContext  

8. for junit how to create the context configuration ? 

using @Runwith() and @ContextConfiguration 

9. What is the ComponentScan ?  @Component, find where the components are, @Componentscan using the basePackages to search in the package.

10. @SpringBootApplication ?  this will initaite the conponentscan within package or subpackages, if we need to explicitly provide we need to provide that 

11. @SpringBootTest 

12. @Component - something is an bean, managed by spring framework. @Autowired - find an matching dependency. @Component vs @Repository vs @Service, there are multiple layers, @Component is generic @Controller means MVC at web layer, @Repository something on the data layer, getting data from database. @Service used in the business layer, all the facade . @Repository - Spring translates the JDBC exception

13. What is the scope of bean, Singleton , Prototype , Session , Request

14 Singleton vs Prototype bean scope? Singleton is the default scope in bean.

15 Request vs Session Bean scope - only for web application context ? 

16. Are Spring bean threadsafe ? NO 

17. How is Spring singleton pattern vs gang of four singleton ? 

18. One instance per class loader vs one instance per application context ?  

19. different types of dependency injection - setter vs constructor injection ? what is the preference ? @Autowired on top of the properties or @Autowired on top of the constructor, Mandatory vs optional dependency ? 

20. NoUniqueBeanDefinitionException vs NoSuchBeanDefinitionException , NoSuchBeanDefinitionException    if the spring is not able to search any implementation then it will throw the error NoSuchBeanDefinitionException , that can also be the issue if that is on an different package (component scan definition) . TWO Components for the same bean -        NoUniqueBeanDefinitionException , Solution auto wiring by name      

21. what is @Primary - default 

22. @Qualifier ? 

23. What is CDI - Context and dependency injection ? Standard for javaEE similar to JPA (JSR-330)  @Inject vs @Autowired , @Named vs @Component, @Singleton per application context and supports the CDI Context. 

24. Spring 2.5 version support for annotation,Spring 3.0 - Java 5 languages,                        Spring 4.0  Java 8 support - Functional programming Spring 4.1 @RESTCONTROLLER for rest services and support for @JCache  , Spring 5.0  Functional web framework , and Support for Jigsaw and support for reactive programming using webflux, Support for kotlin.


25. What is Jigsaw and Java modulator ?

26. What are the different Spring modules ? 

27. Spring framework BOM in maven ?

28. MVC in Spring ?

29. Template Method Pattern ?

30.



 

 

Comments

Popular posts from this blog

Hexagonal Architecture (Ports & Adapters Pattern)

Hexagonal Architecture , also known as the Ports and Adapters pattern, is a software design pattern that aims to create a decoupled and maintainable application by separating the core business logic from external concerns (like databases, APIs, and UIs). Structure of Hexagonal Architecture A typical Hexagonal Architecture has three main layers: 1️⃣ Core Domain (Application Logic) This contains the business rules and domain models. It is completely independent of external technologies . Example: If you’re building a banking system , this part would include logic for transactions, withdrawals, and deposits . 2️⃣ Ports (Interfaces) These are interfaces that define how the core interacts with external components. Two types of ports: Inbound Ports (driven by external inputs like APIs, UI, or events) Outbound Ports (used to interact with external services like databases, messaging systems, etc.) 3️⃣ Adapters (Implementation of Ports) These are concrete implementations of the ports, re...

Recursion & Choice

Understanding Recursion and Choice Diagrams with Examples Understanding Recursion and Choice Diagrams with Examples Recursion is a powerful concept in programming where a function calls itself to solve smaller instances of the same problem. It's often used in solving complex problems that can be broken down into simpler subproblems. In this blog post, we'll explore the basics of recursion, understand choice diagrams, and see examples to illustrate these concepts. What is Recursion? Recursion occurs when a function calls itself directly or indirectly to solve a problem. A recursive function must have a base case to terminate the recursive calls and prevent infinite recursion. Here's a simple example of a recursive function to calculate the factorial of a number: public class RecursionExample { public static void main(String[] args) { int number = 5; int result = factorial(...

Frameworks

  Communication Frameworks: BLUF:  Google's culture strongly emphasizes efficiency and directness, so getting to the "bottom line up front" is very common. SCQA:  Used in presenting proposals, making recommendations, and structuring project plans. PAS : Used in selling ideas and influencing others. BAB : Used in selling ideas and influencing others. Sparklines : Used in presentation to influence others. STAR:  Widely used in Google's interview process and performance evaluations. Problem-Solving/Decision-Making Frameworks: 5 Whys:  A fundamental technique for root cause analysis, and Google is known for its emphasis on data-driven decision-making, which often involves digging into the root causes of problems. Systems Thinking:  Given the complexity of Google's systems, a systems thinking approach is essential. The Four Questions : Used in post-mortem to review an incident. Human factors : Used in post-mortem to avoid the blame culture. Time Management/Prior...