Skip to main content

Posts

Showing posts from April, 2026

Open-Closed Principle – Simple Explanation with Example

When building applications, we often need to add new features or change behavior. A common mistake is modifying existing code every time we need something new. This can easily introduce bugs and break parts of the system that were already working. The Open-Closed Principle (OCP) helps solve this problem. What is Open-Closed Principle? The idea is simple: Software entities should be open for extension, but closed for modification. That means: You should be able to add new behavior Without changing existing code Why This Matters When we modify existing code: We risk breaking existing functionality Testing becomes harder The code becomes less stable over time Instead, we should extend the code in a safe way. Bad Example (Modifying Existing Code) Let’s say we have a class that calculates discounts: class DiscountService { calculate(price, type) { if (type === "regular") { return price * 0.1; } els...

Single Responsibility Principle – Simple Explanation with Example

When writing code, it’s common to put multiple responsibilities inside a single file or class. It might work at first, but over time it becomes difficult to manage and update. The Single Responsibility Principle (SRP) helps solve this. It is one of the core ideas from SOLID and focuses on keeping code simple and maintainable. What is Single Responsibility Principle? The idea is simple: A class should have only one responsibility. That means: It should do one job It should have only one reason to change Why This Matters When a class does too many things: Changes become risky Bugs become harder to track Code becomes difficult to understand Keeping responsibilities separate makes your code: Cleaner Easier to maintain Easier to scale Bad Example (Multiple Responsibilities in One Class) Let’s look at a class that handles everything: class UserService { validateUser(user) { if (!user.email) { console.log...

SOLID Principles – Simple Explanation for Beginners

 When I started learning object-oriented programming, I often wrote code that worked—but was hard to maintain or extend later. That’s when I came across the SOLID principles. These are five simple guidelines that help us write code that is: Easy to understand Easy to maintain Easy to scale In this blog, I’ll explain each principle in a simple way so you can understand the idea clearly. What are SOLID Principles? SOLID is a set of five design principles introduced by Robert C. Martin. Each letter represents one principle: S → Single Responsibility O → Open-Closed L → Liskov Substitution I → Interface Segregation D → Dependency Inversion S — Single Responsibility Principle (SRP) A class should have only one responsibility. Simple idea A class should do only one job. If a class has multiple responsibilities: It becomes harder to manage Changes in one part can affect other parts Example thinking Instead of: One class handling user data + logging + validation Split it into: One class fo...

Encapsulation in Java – Simple Explanation for Beginners

When writing programs, one common issue is that data can be modified from different parts of the code without proper control. This often leads to unexpected bugs and makes applications harder to manage. Encapsulation helps solve this problem. It allows us to protect data and control how it is accessed, making our code more secure and easier to maintain. In this blog, I will explain encapsulation in a simple way so that you can understand it clearly and start using it in your Java programs. What is Encapsulation in Java? In simple terms, encapsulation means wrapping data and methods together inside a single class. Instead of allowing direct access to variables, we control how the data is accessed and modified through methods. You can think of it as providing controlled access to the internal state of an object. Why Encapsulation is Important Data Hiding Encapsulation hides the internal data from outside access. This prevents unwanted or incorrect changes. Modularity...

Abstraction in Java

When I started learning Java, abstraction felt confusing at first. But once I connected it with real-life examples, it started to make sense. In this blog, I’ll explain abstraction in the simplest way possible—just like how I understood it. What is Abstraction? Abstraction means hiding the internal implementation details and showing only the essential functionality. In my own words: I focus on what something does, not how it does it. This idea is actually everywhere in real life. Real-Life Example (How I Understood It) Think about a car: I use the steering, brake, and accelerator But I don’t know how the engine works internally Still, I can drive the car perfectly. That’s abstraction. Why Abstraction is Important When I started building projects, I realized abstraction helps me: Reduce complexity Write cleaner code Hide sensitive logic Make code reusable Easily maintain large applications How Abstraction is Achieved in Java In Java...

Understanding Polymorphism in Java (Simple & Beginner-Friendly Guide)

 When I first started learning Java, one concept that really stood out to me was polymorphism . At first, it sounded complex, but once I broke it down, it actually became one of the most powerful and easy-to-understand ideas in Object-Oriented Programming (OOP). What is Polymorphism? Polymorphism simply means “many forms.” In Java, I think of it like this: The same method name can behave differently depending on how I use it. This helps me write cleaner, more flexible, and reusable code. There are two main types of polymorphism in Java: Compile-time Polymorphism (Method Overloading) Run-time Polymorphism (Method Overriding) 1. Compile-time Polymorphism (Method Overloading) What it means When I create multiple methods with the same name but different parameters, it's called method overloading . The difference can be: Number of parameters Type of parameters Syntax Example Here’s a simple example I use to understand it better: My Understanding Even though the method name is the same (...

Oops Concepts : Inheritance In Java

When I first started learning Java, inheritance felt a bit confusing. But once I understood the basic idea, it became one of the easiest and most powerful concepts in Object-Oriented Programming (OOP). In this blog, I’ll explain inheritance in very simple English, so even if you're a beginner student or aspiring developer, you can understand it easily.  What is Inheritance in Java? In simple words, inheritance means reusing code from another class. I usually think of it like this: A child inherits features from parents Similarly, a class can inherit properties and methods from another class Definition: Inheritance is a mechanism where a child class gets properties and methods from a parent class. Key Terms (Very Important) Parent Class (Superclass) → The class that provides properties Child Class (Subclass) → The class that inherits those properties How Inheritance Works in Java Java uses the keyword:           extends Basic Syntax: This means the Chil...

Stop Storing JWTs in LocalStorage: A 2026 Guide to MERN Auth

If you’re still putting your JSON Web Tokens (JWTs) into localStorage in your MERN apps, it's time to stop. As someone who’s spent way too many nights debugging broken auth flows and dealing with security audits, I’ve learned the hard way that localStorage is essentially an open invitation for XSS (Cross-Site Scripting) attacks to hijack your user sessions.  In 2026, the standard has shifted. Here is how we’re handling authentication in the MERN stack now. The Problem: LocalStorage is a Vulnerability  When you store a token in localStorage, any JavaScript running on your page—including a compromised third-party package or an injected script—can read that token. If a hacker manages to execute just one line of code in your app, they have your user's identity.    The Modern Shift: Cookies are Your Best Friend The gold standard now is to move tokens out of the reach of your client-side JavaScript by using HttpOnly, Secure, SameSite=Strict cookies. Because these cookies...

Setting Up MinGW on Windows: A Beginner’s Guide

Introduction MinGW (Minimalist GNU for Windows) is a popular compiler for C, C++, and other languages that provides the necessary tools for compiling and running code on Windows. In this guide, I’ll walk you through the steps to install and configure MinGW on your system. Whether you’re just getting started or need to configure your environment, follow these simple steps! Step 1: Download MinGW First, download the MinGW zip file from the following link: 👉  Download MinGW Once downloaded, you’ll see a file like this: Step 2: Extract the ZIP File Now that you’ve downloaded the ZIP file, it’s time to extract it. Right-click  on the zip file. Choose  Extract All . Extract the contents to a folder on your desktop or in any other location. You should see a folder named  mingw-w64-bin_x86_64-mingw_20111101_sezero . Step 3: Move MinGW64 Folder to C: Drive After extracting, move the  mingw64  folder to your  C:  drive. Here’s how: Open  File Explorer...