Again, a good article from Sergiy Yevtushenko. Every developer should read this - it's Java, but the lessons are useful in many modern languages. Practical, applied programming tips like many devs appreciate them. These are not just "FP style examples in Java". They are also applied ways of properly decoupling concepts and mechanisms that should remain decoupled, but which traditional OOP languages tend to force us to couple. For example: handling errors with try-catch VS handling errors with Result<>, flatMap() etc. And don't forget to follow Sergiy Yevtushenko, his programming advice is always best of class. #Java #FunctionalProgramming #Programming #Architecture
Yannick L.’s Post
More Relevant Posts
-
--->> Understanding Inheritance in Java & Its Types **Inheritance is a fundamental concept in Object-Oriented Programming (OOP) that allows one class to acquire the properties and behaviors of another class. √ What is Inheritance? It is the process where a child class inherits variables and methods from a parent class using the extends keyword. ~Why is it Important? ✔️ Code reusability ✔️ Reduced development time ✔️ Better maintainability ✔️ Cleaner and scalable design @ Types of Inheritance in Java 1️⃣ Single Inheritance 2️⃣ Multilevel Inheritance 3️⃣ Hierarchical Inheritance 4️⃣ Hybrid (combination of types) # Important Notes 🔸 Java does NOT support multiple inheritance using classes ➡️ Because of the Diamond Problem (ambiguity in method resolution) 🔸 Cyclic inheritance is not allowed ➡️ Prevents infinite loops in class relationships 💻 Code Example (Single Inheritance) Java class Parent { void show() { System.out.println("This is Parent class"); } } class Child extends Parent { void display() { System.out.println("This is Child class"); } } public class Main { public static void main(String[] args) { Child obj = new Child(); obj.show(); // inherited method obj.display(); // child method } } 👉 Here, the Child class inherits the show() method from the Parent class. -->> Real-World Example Think of a Vehicle system 🚗 Parent: Vehicle Child: Car, Bike All vehicles share common features like speed and fuel, but each has its own unique behavior. @ Key Takeaway Inheritance helps you avoid code duplication and build efficient, reusable, and scalable application TAP Academy #Java #OOP #Inheritance #Programming #JavaDeveloper #Coding #SoftwareDevelopment #LearnJava
To view or add a comment, sign in
-
-
🚀 Learning Core Java – Achieving Runtime Polymorphism using Loose Coupling Today I explored an important concept in Java — Runtime Polymorphism through Loose Coupling. Runtime polymorphism is one of the most powerful features of Object-Oriented Programming because it helps us write flexible, scalable, and maintainable code. 🔹 What is Tight Coupling? Tight Coupling means: 👉 A child class reference is used to create and access a child class object Example conceptually: Child child = new Child(); Here, the code is directly dependent on the child class. This creates: ❌ Less flexibility ❌ Harder maintenance ❌ Difficult scalability Because if the implementation changes, the code also needs changes. 🔹 What is Loose Coupling? Loose Coupling means: 👉 A parent class reference is used to refer to a child class object Example conceptually: Parent ref = new Child(); This is also called: ✔ Upcasting ✔ Runtime Polymorphism ✔ Dynamic Method Dispatch Here, the parent reference can call overridden methods of the child class at runtime. This gives: ✔ Better flexibility ✔ Easy maintenance ✔ Scalable design ✔ Cleaner architecture 🔹 Limitation of Loose Coupling Using a parent reference: 👉 We can only access methods available in the parent class Even though the object is a child object, we cannot directly access specialized methods of the child class. 🔹 How to Access Child-Specific Methods? We use Downcasting 👉 Convert parent reference back to child reference Conceptually: Child child = (Child) ref; Now the parent reference behaves like a child reference, and we can access: ✔ Specialized methods ✔ Child-specific properties 💡 Key Insight 👉 Tight Coupling = Less flexibility 👉 Loose Coupling = More flexibility + Runtime Polymorphism 👉 Downcasting helps access specialized child methods This concept is heavily used in Spring Framework, Dependency Injection, Interfaces, and Enterprise Applications. Understanding this helps build professional-level Java applications. Excited to keep strengthening my OOP fundamentals! 🚀 #CoreJava #RuntimePolymorphism #LooseCoupling #TightCoupling #ObjectOrientedProgramming #JavaDeveloper #ProgrammingFundamentals #LearningJourney
To view or add a comment, sign in
-
-
🚀 Understanding Inheritance in Java: Building Scalable Object-Oriented Systems Inheritance is a foundational concept in Java that enables developers to create structured, reusable, and maintainable code by establishing relationships between classes. At its core, inheritance allows a subclass (child class) to acquire the properties and behaviors of a superclass (parent class) — promoting code reusability and logical design. 🔹 Why Inheritance Matters in Modern Development • Encourages code reuse, reducing redundancy • Enhances readability and maintainability • Supports scalable architecture design • Models real-world relationships effectively 🔹 Basic Example class Animal { void eat() { System.out.println("Eating..."); } } class Dog extends Animal { void bark() { System.out.println("Barking..."); } } In this example, the Dog class inherits the eat() method from Animal, while also defining its own behavior. 🔹 Types of Inheritance in Java • Single Inheritance • Multilevel Inheritance • Hierarchical Inheritance (Note: Java does not support multiple inheritance with classes to avoid ambiguity, but it can be achieved using interfaces.) 🔹 Key Concepts to Remember • extends keyword is used to inherit a class • super keyword allows access to parent class members • Inheritance represents an "IS-A" relationship (e.g., Dog is an Animal) 💡 Final Thought Mastering inheritance is essential for anyone aiming to build robust backend systems or work with frameworks like Spring. It forms the backbone of clean architecture and object-oriented design. 📌 I’ll be sharing more insights on Encapsulation, Polymorphism, and real-world Java applications soon. #Java #OOP #SoftwareEngineering #BackendDevelopment #CleanCode #Programming #Developers
To view or add a comment, sign in
-
-
Day 11/100 – Java Practice Challenge 🚀 Continuing my #100DaysOfCode journey with another important Java concept. 🔹 Topic Covered: Compile-time vs Runtime Polymorphism 💻 Practice Code: 🔸 Compile-time Polymorphism (Method Overloading) class Calculator { int add(int a, int b) { return a + b; } int add(int a, int b, int c) { return a + b + c; } } 🔸 Runtime Polymorphism (Method Overriding) class Animal { void sound() { System.out.println("Animal sound"); } } class Cat extends Animal { @Override void sound() { System.out.println("Cat meows"); } } public class Main { public static void main(String[] args) { // Compile-time Calculator c = new Calculator(); System.out.println(c.add(10, 20)); System.out.println(c.add(10, 20, 30)); // Runtime Animal a = new Cat(); a.sound(); } } 📌 Key Learnings: ✔️ Compile-time → method decided at compile time ✔️ Runtime → method decided at runtime ✔️ Overloading vs Overriding difference 🎯 Focus: Understanding how Java resolves method calls 🔥 Interview Insight: Difference between compile-time and runtime polymorphism is one of the most frequently asked Java interview questions. #Java #100DaysOfCode #MethodOverloading #MethodOverriding #Polymorphism #JavaDeveloper #Programming #LearningInPublic
To view or add a comment, sign in
-
🛑Stop treating Abstraction and Encapsulation like they’re the same thing. Demystifying Java OOP: From Basics to the "Diamond Problem" 💎💻 If you're leveling up in Java, understanding the "How" is good—but understanding the "Why" is what makes you a Senior Developer. Let’s break down the core of Object-Oriented Programming. 🚀 1️⃣ What is OOP & The 4 Pillars? 🏗️ OOP is a way of designing software around data (objects) rather than just functions. It rests on four main concepts: ✅ Encapsulation: Protecting data. ✅ Abstraction: Hiding complexity. ✅ Inheritance: Reusing code. ✅ Polymorphism: Adapting forms. 2️⃣ Encapsulation vs. Abstraction: The Confusion 🔐 These two are often mixed up, but here is the simple split in Java: 🔹 Encapsulation is about Security. We keep variables private and use getters and setters to act as a "shield" for our data. 🔹 Abstraction is about Design. We use Interfaces or Abstract Classes to show the user what the code does while hiding the messy details of how it works. 3️⃣ The Rule of Inheritance 🌳 Inheritance allows a child class to take on the traits of a parent class. However, the catch: In Java, a class can only have ONE parent. 🚫 4️⃣ Why no Multiple Inheritance? (The Diamond Problem) 💎 Imagine Class A has a start() method. Both Class B and Class C inherit it, but they modify how it works. If Class D tries to inherit from both B and C, and we call D.start(), Java has no way of knowing which version to run! To avoid this "ambiguity" and keep your code predictable, Java forbids inheriting from multiple classes. 5️⃣ How to solve it? 🛠️ Need multiple behaviors? No problem. 👉 Interfaces: A class can implement as many interfaces as it needs. 👉 Default Methods: Since Java 8, if two interfaces have the same default method, Java forces you to override it and choose a winner. No more guesswork! 👉 Composition: Instead of "being" a class, "have" an instance of it. Mastering these rules is crucial for writing clean, maintainable, and professional Java code. 🌟 #Java #Programming #OOP #SoftwareDevelopment #CodingTips #TechCommunity #SoftwareEngineering #CareerGrowth
To view or add a comment, sign in
-
Ever wondered if Java’s checked exceptions can be… bypassed? I explored an interesting approach using generics to influence how checked exceptions are treated by the compiler. Here’s the interesting part: catch (Exception e) { Task.<RuntimeException>throwAs(e); } At compile time: The compiler believes we are throwing a RuntimeException (unchecked), so it doesn’t force us to handle or declare it. At runtime: Due to type erasure, the JVM simply throws the original exception which can still be a checked exception like InterruptedException. The trick lies in this method: @SuppressWarnings("unchecked") public static <T extends Throwable> void throwAs(Throwable t) throws T { throw (T) t; } This works because: • Generics are erased at runtime • Checked exceptions are enforced only by the compiler So effectively: → We bypass Java’s checked exception mechanism → Without breaking any JVM rules This pattern is often called a “Sneaky Throw” and is even used internally by tools like Lombok (@SneakyThrows). Not something to use casually in production, but a great way to understand how Java’s type system and exception handling really work under the hood. #Java #Programming #Generics #ExceptionHandling
To view or add a comment, sign in
-
-
🚫 Why Java Disallows Multiple Inheritance – The Diamond Problem Explained! Ever wondered why Java doesn’t support multiple inheritance with classes? 🤔 The answer lies in something called the Diamond Problem. 🔷 Imagine this: A class (Child) inherits from two parent classes (Parent A & Parent B), and both of them inherit from a common class (Object). Now, what happens if both parents have the same method? 👉 The child class gets duplicate methods 👉 The compiler gets confused 👉 And you get a compilation error ❌ 💥 This leads to ambiguity: Which method should the child use? Parent A’s or Parent B’s? 🔍 Key Insights: ✔ Every Java class already extends the Object class ✔ Multiple inheritance can lead to duplicate method injection ✔ Identical method signatures create conflicts the compiler can’t resolve ✔ Java follows a “zero tolerance for ambiguity” approach 💡 How Java Solves This? Instead of multiple inheritance with classes, Java uses: 👉 Interfaces (with default methods) 👉 Clear method overriding rules This ensures: ✅ Better code clarity ✅ No ambiguity ✅ Easier maintainability 🔥 Takeaway: Java prioritizes simplicity and reliability over complexity — and avoiding the Diamond Problem is a perfect example of that design philosophy. #TAPAcademy #Java #OOP #Programming #SoftwareDevelopment #Coding #JavaDeveloper #TechConcepts #LearningJourney
To view or add a comment, sign in
-
-
💎 Understanding the Diamond Problem in Java (and how Java solves it!) Ever heard of the Diamond Problem in Object-Oriented Programming? 🤔 It happens in multiple inheritance when a class inherits from two classes that both have the same method. The Problem Structure: Class A → has a method show() Class B extends A Class C extends A Class D extends B and C Now the confusion is: Which show() method should Class D inherit? This creates ambiguity — famously called the Diamond Problem Why Java avoids it? Java does NOT support multiple inheritance with classes. So this problem is avoided at the root itself. But what about Interfaces? Java allows multiple inheritance using interfaces, but resolves ambiguity smartly. If two interfaces have the same default method, the implementing class must override it. Example: interface A { default void show() { System.out.println("A"); } } interface B { default void show() { System.out.println("B"); } } class C implements A, B { public void show() { A.super.show(); // or B.super.show(); } } Key Takeaways: No multiple inheritance with classes in Java Multiple inheritance allowed via interfaces Ambiguity is resolved using method overriding Real Insight: Java doesn’t just avoid problems — it enforces clarity. #Java #OOP #Programming #SoftwareDevelopment #CodingInterview #TechConcepts
To view or add a comment, sign in
-
Most Java developers think switching to Kotlin means learning a whole new language. Here's the truth: 𝘆𝗼𝘂'𝗿𝗲 𝗮𝗹𝗿𝗲𝗮𝗱𝘆 𝟳𝟬% 𝘁𝗵𝗲𝗿𝗲, and the remaining 30% will make you wonder why you didn't switch sooner. First, embrace data classes. That 50-line Java POJO with equals, hashCode, toString, and getters? Gone. ```kotlin data class User(val name: String, val email: String, val age: Int) ``` That's it. One line. The compiler generates everything for you, and it's less error-prone than any IDE-generated boilerplate. Second, stop writing null checks everywhere. 𝗞𝗼𝘁𝗹𝗶𝗻'𝘀 𝘁𝘆𝗽𝗲 𝘀𝘆𝘀𝘁𝗲𝗺 𝗱𝗶𝘀𝘁𝗶𝗻𝗴𝘂𝗶𝘀𝗵𝗲𝘀 𝗻𝘂𝗹𝗹𝗮𝗯𝗹𝗲 𝗳𝗿𝗼𝗺 𝗻𝗼𝗻-𝗻𝘂𝗹𝗹𝗮𝗯𝗹𝗲 𝘁𝘆𝗽𝗲𝘀 𝗮𝘁 𝗰𝗼𝗺𝗽𝗶𝗹𝗲 𝘁𝗶𝗺𝗲. Instead of littering your code with `if (user != null)` chains, you get elegant safe calls like `user?.address?.city` and the Elvis operator `user?.name ?: "Unknown"`. Entire categories of NullPointerExceptions simply vanish. Third, learn extension functions early. They let you add methods to existing classes without inheritance. Need a utility method on String? Just write `fun String.isValidEmail(): Boolean` and call it naturally. No more StringUtils classes with static methods scattered across your codebase. The biggest mindset shift isn't syntax. 𝗜𝘁'𝘀 𝗮𝗰𝗰𝗲𝗽𝘁𝗶𝗻𝗴 𝘁𝗵𝗮𝘁 𝗹𝗲𝘀𝘀 𝗰𝗼𝗱𝗲 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝗺𝗲𝗮𝗻𝘀 𝗺𝗼𝗿𝗲 𝗰𝗹𝗮𝗿𝗶𝘁𝘆. Kotlin rewards you for writing less. What was the single Kotlin feature that made you never want to go back to pure Java? #Kotlin #Java #AndroidDev #SoftwareEngineering #Programming
To view or add a comment, sign in
-
-
💻 Generics in Java — Write Flexible & Type-Safe Code 🚀 If you’ve ever faced ClassCastException or messy type casting… Generics are your solution 🔥 This visual breaks down Java Generics in a simple yet practical way 👇 🧠 What are Generics? Generics allow you to write type-safe and reusable code by using type parameters (<T>). 👉 Instead of hardcoding data types, you write code that works with any type 🔍 Why Generics? ✔ Eliminates explicit type casting ✔ Ensures compile-time type safety ✔ Improves code reusability ✔ Makes code cleaner and readable 🔄 Core Concepts: 🔹 Generic Class class Box<T> { T data; } 👉 Same class → works with String, Integer, etc. 🔹 Generic Method public <T> void printArray(T[] arr) 👉 Works for any data type 🔹 Bounded Types <T extends Number> 👉 Restrict types (only numbers allowed) 🔹 Wildcards (?) <?> → Any type <? extends T> → Upper bound <? super T> → Lower bound 🔹 Type Inference (Diamond Operator) List<String> list = new ArrayList<>(); 👉 Cleaner code, compiler infers type ⚡ Generics with Collections: List<String> names = new ArrayList<>(); 👉 Ensures only String values are stored 💡 Real impact: Without generics → Runtime errors ❌ With generics → Compile-time safety ✅ 🎯 Key takeaway: Generics are not just syntax — they are the foundation of writing robust, scalable, and reusable Java code. #Java #Generics #Programming #BackendDevelopment #SoftwareEngineering #Coding #100DaysOfCode #Learning
To view or add a comment, sign in
-
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Sergiy Yevtushenko It's a good article on an important topic, but it would be nice to have an explanation in this article, or some future article, explaining the key differences between Promise and Future. Future is also essentially an async result. And I'm sure Option is better than Optional, but an explanation of the differences here would also be good. Another question: does Promise integrate with the new Java structured concurrency?