Posts

Showing posts from July, 2025

✅ Spring Boot Annotations

🏁 1. Main Application Setup πŸ”° @SpringBootApplication – This is a convenience annotation that combines: @Configuration , @EnableAutoConfiguration , and @ComponentScan . It is used on the main class to bootstrap and launch a Spring Boot application. @Configuration – Indicates that the class contains Spring bean definitions. Beans defined here will be registered in the application context. @EnableAutoConfiguration – Tells Spring Boot to automatically configure beans based on the classpath, properties, and existing beans. Helps reduce manual configuration. @ComponentScan – Enables automatic scanning of packages for components like @Component , @Service , @Repository , and @Controller . 🧩 2. Component & Bean Annotations 🧩 @Component - Spring-managed component (auto-detected). πŸ”§ @Service - For business logic layer. πŸ—ƒ️ @Repository - For data access layer with exception translation. ...

⚙️ApplicationContext in Spring Boot – The Core of IoC

Spring ApplicationContext Explained 🧠 What is ApplicationContext? ApplicationContext is Spring's brain. It is the container that: ✅ Creates all your beans (objects) ✅ Wires them together (dependency injection) ✅ Manages their life cycle ✅ Provides access to them anywhere in the app 🎯 One-Line Definition: ApplicationContext is the place where Spring keeps and manages all your @Component , @Service , and @Controller beans. πŸ“† Example: How It Works 1. Bean class: @Component public class MyBean { public void sayHi() { System.out.println("Hi from MyBean!"); } } 2. Spring Boot App: @SpringBootApplication public class MyApp implements CommandLineRunner { @Autowired MyBean myBean; public static void main(String[] args) { SpringApplication.run(MyApp.class, args); // Creates ApplicationContext } @Override publi...

πŸ“¦ Spring Boot IoC Container

Spring IoC Container Explained 🧠 What is IoC Container? The IoC (Inversion of Control) Container is the core part of Spring that: ✅ Creates your objects (beans) ✅ Manages them ✅ Injects their dependencies ✅ Controls their lifecycle You don’t manually create or connect objects — Spring does it for you. πŸ” Inversion of Control? Normal (manual) object creation: MyService service = new MyService(); Spring Boot style (IoC-managed): @Component public class MyService { } @Autowired MyService service; // Spring injects this This is Inversion of Control — you give up control to the container. πŸ“¦ In Spring Boot Spring Boot automatically starts the IoC container when your application runs: @SpringBootApplication public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); // starts IoC container } } Under the hood, this creates an ApplicationCont...

🌱 Spring Bean

Spring Boot Bean Lifecycle 🧠 What is a Bean in Spring Boot? A bean is a Java object managed by the Spring framework. In Spring Boot, you often create beans using: @Component @Service @Repository @Configuration @Bean Spring Boot automatically detects and manages these beans through component scanning . πŸ”„ How Does the Bean Lifecycle Work in Spring Boot? Spring Boot uses the standard Spring bean lifecycle, but simplifies it with annotations and auto-configuration. ✅ Common Lifecycle Hooks You Might Use: @PostConstruct - Run code after dependencies are injected: @Component public class MyService { @PostConstruct public void init() { System.out.println("Bean is initialized"); } } @PreDestroy - Run code before bean is destroyed (e.g., app shutdown): @PreDestroy public void cleanup() { System.out.println("Bean is being destroyed"); } InitializingBean and DisposableBean interfaces: ...

🌿⚙️ Spring Boot Simplified

🌱 Spring Boot Basics Spring Boot makes it easy to create stand-alone, production-grade Spring-based applications. In this post, you'll learn its core concepts, including auto-configuration, starter dependencies, and embedded servers. πŸ“˜ 1. What is Spring Boot? Spring Boot is a framework built on top of the Spring Framework. Its goal is to simplify the development of production-ready Spring applications by reducing the amount of boilerplate code and configuration. ✅ Key Benefits: Auto-configuration: Smart defaults based on your dependencies Embedded servers: Like Tomcat or Jetty — no need to deploy WARs Opinionated setup: Makes decisions for you, but still customizable Single entry point: Uses @SpringBootApplication to bootstrap the app πŸ†š Spring Boot vs Spring Framework Feature Spring Framework Spring Boot Configuration Manual (XML or Java) Auto-confi...

Internal Working of Hashmap

Internal Working of HashMap in Java πŸ” Internal Working of HashMap in Java ✅ Step-by-Step Explanation 1. Adding a Key-Value Pair map.put("name", "John"); We start by adding a key-value pair to the HashMap. 2. Hash Code Generation Java computes a hash code for the key using: int hash = key.hashCode(); // "name".hashCode() 3. Converting Hash to Array Index To reduce collision risk, it computes the index in the underlying array: index = (hash & (array.length - 1)); 4. Bucket Check If the bucket at the index is empty, the entry is stored directly. If not, a collision has occurred. 5. Collision Handling On collision, Java uses: LinkedList chaining for simple conflicts Red-Black Tree (since Java 8) if bucket size > 8 and capacity > 64 Bucket[5] → ("id", 101) → ("name", "John") 6. Retrieving a...