Posts

Showing posts from August, 2025

SOLID Principles

   SOLID Principles 1. S — Single Responsibility Principle (SRP) 👉 A class should have only one reason to change. Bad Example ❌ class Payment {     void makeUPIPayment () { }     void generateReceipt () { }     void sendNotification () { } } This class does too much → payment + receipt + notification. Good Example  class UPIPayment {     void makePayment() { } } class ReceiptGenerator {     void generateReceipt() { } } class NotificationService {     void sendNotification() { } } Each class has one responsibility . If tomorrow notification changes ( SMS → WhatsApp ), only NotificationService changes. 2. O — Open/Closed Principle (OCP) 👉 Classes should be open for extension but closed for modification . Bad Example ❌ class PaymentProcessor {     void process(String type) {         if(type.equals("UPI")) { /* UPI logic */ }         else if(typ...

HIbernate Inteview Question

Image
🔍 Key Differences Between CrudRepository and JpaRepository              🧠 Summary Use CrudRepository for basic CRUD operations . Use JpaRepository when you need pagination, sorting, batch operations , or JPA-specific features . Since JpaRepository extends CrudRepository , it includes everything CrudRepository offers — and more.                          Feature CrudRepository JpaRepository Inheritance Base interface for CRUD operations Extends CrudRepository Basic Methods save() , findById() , delete() Inherits all from CrudRepository Additional Features ❌ No extra features ✅ Adds JPA-specific methods Batch Operations ❌ Not supported ✅ deleteInBatch() , saveAll() Pagination & Sorting ❌ Not supported ✅ findAll(Pageable) , findAll(Sort) Flush Support ❌ No ✅ flush() , saveAndFlush() Use Case Simple CRUD-only repositories Advanced JPA features and query customization 🔄 Session vs S...