Java Full Stack Topic # SPRING FRAME WORK Dr.V.R.Seshagiri Rao IARE1 0040 Department of Electronics and Communication Engineering Lecture # 23 July , 202 5 1
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 2 SPRING FRAME WORK
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 3 SPRING FRAME WORK A JavaBean is a reusable software component in Java that follows specific conventions for encapsulation, property access, and event handling. It’s commonly used to represent business objects (like Employee , Product , Customer ) in Java applications.
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 4 SPRING FRAME WORK
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 5 SPRING FRAME WORK
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 6
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 7
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 8 The Spring Framework is a powerful, lightweight, and open-source framework for building enterprise-level Java applications. It provides a comprehensive programming and configuration model, making Java development easier, faster, and more maintainable. Spring is often described as an “ecosystem” because it offers a wide range of tools and modules that cover almost every aspect of Java application development — from web applications to cloud-native microservices .
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 9 Inversion of Control ( IoC ) / Dependency Injection (DI): Spring manages object creation and wiring, reducing boilerplate code and improving testability. Instead of creating objects manually, Spring injects dependencies into classes. Aspect-Oriented Programming (AOP): Helps separate cross-cutting concerns like logging, security, and transactions from business logic. Lightweight and Modular: You can use only the modules you need (e.g., Spring Core, Spring MVC, Spring Data). Key Features of Spring Framework
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 10 Spring MVC (Web Framework): Provides a clean separation of concerns (Model-View-Controller) for building web applications. Data Access and Transaction Management: Simplifies JDBC, Hibernate, JPA, and transaction handling with consistent templates and abstraction layers. Security: Spring Security handles authentication, authorization, and common security vulnerabilities.
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 11 Integration with Other Frameworks: Works seamlessly with Hibernate, JPA, JMS, Kafka, RabbitMQ , etc. Spring Boot (part of the ecosystem): Makes it easier to create production-ready applications with minimal configuration.
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 12
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 13
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 14 In software engineering, coupling refers to the degree of interdependence between software modules or components. How tightly or loosely these components are connected has a significant impact on the maintainability, scalability, and flexibility of the entire system Tight Coupling Tight coupling (or strong coupling) occurs when a component is highly dependent on another concrete component. In a tightly coupled system, a change in one module often necessitates changes in the modules that depend on it. Key Characteristics: High Interdependency: Components are directly aware of and rely on the internal details of other components. Direct Instantiation: A common sign of tight coupling is when a class directly creates an instance of another specific class using the new keyword. Coupling
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 15 Example (in Java): Consider a Car class that directly creates a specific PetrolEngine instance. class PetrolEngine { public void start() { System.out.println ("Petrol engine started."); } } class Car { private PetrolEngine engine; public Car() { this.engine = new PetrolEngine (); // Tightly coupled } public void startCar () { engine.start (); } } In this example, the Car class is tightly coupled to the PetrolEngine class. If you wanted to change to a DieselEngine or an ElectricEngine , you would have to modify the Car class directly, which violates the Open/Closed Principle (a part of the SOLID principles).
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 16 Disadvantages of Tight Coupling: Reduced Flexibility: It's difficult to swap components or add new functionalities without altering existing code. Hard to Test: Modules cannot be tested in isolation because they are so dependent on other concrete classes. Mocking or stubbing dependencies is difficult. Fragile System: Changes in one part of the code can cause a ripple effect, introducing unexpected bugs in other, seemingly unrelated parts of the system. Lower Reusability: A tightly coupled class is difficult to reuse in a different context because it's tied to its specific dependencies.
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 17 Loose Coupling Loose coupling (or weak coupling) is the opposite of tight coupling. It is a design goal that seeks to minimize the dependencies between components, allowing them to interact through well-defined, stable interfaces or abstractions Key Characteristics: Low Interdependency: Components know little to nothing about the internal details of the others. Interaction through Abstractions: Components rely on interfaces or abstract classes rather than concrete implementations. Achieved via Design Patterns: Techniques like Dependency Injection (DI) and Inversion of Control ( IoC ) are used to achieve loose coupling.
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 18 interface Engine { void start(); } class PetrolEngine implements Engine { @Override public void start() { System.out.println ("Petrol engine started."); } } class ElectricEngine implements Engine { @Override public void start() { System.out.println ("Electric engine started."); } } class Car { private Engine engine ; // Dependency is injected through the constructor public Car(Engine engine) { this.engine = engine; // Loosely coupled } public void startCar () { engine.start (); } } // In the main application: // Car petrolCar = new Car(new PetrolEngine ()); // Car electricCar = new Car(new ElectricEngine ());
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 19 In this revised example, the Car class no longer knows the specific type of engine it uses. It only knows about the Engine interface. The specific PetrolEngine or ElectricEngine is "injected" from outside. This makes the Car class reusable, and you can easily switch engine types without changing the Car class itself. Advantages of Loose Coupling: Increased Flexibility: Components can be easily swapped or replaced with different implementations. Improved Testability: You can easily test a component in isolation by "injecting" mock or fake implementations of its dependencies.
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 20 Enhanced Maintainability: Changes in one component are less likely to affect others, reducing the risk of introducing new bugs. Greater Reusability: Modules are independent and can be used in different parts of the application or even in different applications. Better Scalability: It's easier to scale or distribute a loosely coupled system because its components are independent. In summary, loose coupling is generally considered a best practice in software design as it leads to more maintainable, flexible, and robust systems.
ACSD 30 JFSD Institute of Aeronautical Engineering, Hyderabad Dr.V.R.Seshagiri Rao 21 SPRING FRAMEWORK Thank You