Posts

Java OOPs Concepts Made Simple: A Complete Beginner-Friendly Guide (Part-4)

Java Constructors, this & super Keywords, Singleton Class Master Constructors, this , super , Default Constructors, Constructor Chaining, Singleton Pattern and more. Introduction In the previous OOPS blog, we explored concepts like inheritance, polymorphism, composition, aggregation, interfaces and abstract classes. Now it's time to understand another important part of Java OOPS—how objects are initialized and how child classes communicate with parent classes. In this guide you'll learn: Constructors in Java Default Constructors Constructor Chaining this keyword super keyword this vs super Singleton Class Constructors in Java A constructor is a special method that is called automatically whenever an object is created. Its main purpose is to initialize object data. Definition A constructor is a special method called automatically during object creation to initialize objects. Why Do We Need Constructors? Let's understand this with...

Java OOPs Concepts Made Simple: A Complete Beginner-Friendly Guide (Part-3)

OOPS in Java – Coupling, Cohesion & Interface (Complete Guide with Examples & Interview Questions) Master Coupling, Cohesion, Interfaces, Marker Interfaces, Adapter Classes, and Interview Questions in Java. What You'll Learn Coupling vs Cohesion Loose Coupling & High Cohesion Interface in Java extends vs implements Interface Methods & Variables Marker Interface Adapter Classes Interface vs Abstract Class Constructor Interview Questions Coupling vs Cohesion Explained Writing software isn't just about making code work today. The real goal is to build code that is easy to modify, debug, and expand tomorrow. Two of the most important design principles every Java developer should understand are: Coupling Cohesion 1. Coupling – How Connected is Your Code? Coupling refers to the degree of dependency between different classes or components. Type Meaning Tight Coupling Classes he...

Java OOPs Concepts Made Simple: A Complete Beginner-Friendly Guide (Part-2)

🔗 HAS-A Relationship in Java — Composition & Aggregation In Java, objects can be related to each other in different ways. One important relationship between objects is the HAS-A Relationship . In this section, we will understand what a HAS-A relationship is and then explore its two important forms: Composition and Aggregation . 🔗 What is a HAS-A Relationship? A HAS-A Relationship represents a relationship where one class contains a reference to an object of another class. In simple words, when one object has another object as one of its components, we can say that the objects have a HAS-A relationship . 💡 Main Advantage of HAS-A Relationship: Reusability There is no specific keyword in Java to implement a HAS-A relationship. Most of the time, we create an object of another class using the new keyword. Simple Example class Engine { // Engine functionality } class Car { Engine e = new Engine(); } Here, the Car class c...