⏳ Day 20 – 1 Minute Java Clarity – Method Overloading vs Overriding Same name… totally different behaviour! 🤯 📌 What is Method Overloading? Same method name — different parameters — in the SAME class. 👉 Decided at Compile Time → Static Polymorphism. 📌 Example: class Calculator { int add(int a, int b) { return a + b; } double add(double a, double b) { return a + b; } int add(int a, int b, int c) { return a + b + c; } } 👉 Java picks the right method based on arguments you pass ✅ 📌 What is Method Overriding? Child class provides its OWN implementation of a parent class method. 👉 Decided at Runtime → Dynamic Polymorphism. 📌 Example: class Animal { void sound() { System.out.println("Some sound"); } } class Dog extends Animal { @Override void sound() { System.out.println("Dog barks!"); } } Animal a = new Dog(); a.sound(); // Output: Dog barks! ✅ 💡 Real-time Example: Overloading → Same coffee machine ☕ Small cup button → 100ml Large cup button → 300ml Same button name, different output based on input! Overriding → Company policy 📋 Head office says "work 9 to 5" Branch office overrides → "work 8 to 4" Same rule name, child changes the behaviour! ⚠️ Interview Trap: Can we override a static method? 👉 No! Static methods belong to the class — not the object. 👉 It's called Method Hiding, not Overriding! 💡 Quick Summary: | Feature | Overloading | Overriding | | Class | Same | Parent & Child | | Parameters | Different | Same | | Time | Compile time | Runtime | | Keyword | None | @Override | 🔹 Next Topic → Polymorphism in Java Which one confuses you more — overloading or overriding? Drop 👇 #Java #JavaProgramming #MethodOverloading #MethodOverriding #OOPs #CoreJava #JavaDeveloper #BackendDeveloper #Coding #Programming #SoftwareEngineering #LearningInPublic #100DaysOfCode #ProgrammingTips #1MinuteJavaClarity
Java Method Overloading vs Overriding: Key Differences
More Relevant Posts
-
Every time I opened a new Java project in VS Code, I had to set it up from scratch. I work across multiple Java repositories. IntelliJ is my main IDE, but I use VS Code and Cursor for quick navigation and AI-first coding. Lighter. Always ready. But it doesn't pick up IntelliJ configs automatically. So every new project meant: - Mapping source folders manually - Fixing JAR paths - Setting the JDK again Same steps every time. So I tried something different. Instead of writing a script, I wrote a Markdown file. Step-by-step instructions telling the AI exactly what to do. A small snippet from the file: - Check .idea at root only (ignore subdirs) - Extract source roots from .iml files - Map them to java.project.sourcePaths Now I just type /java-vscode-setup in VS Code or Cursor Agent. The AI scans the project. Generates the correct settings.json. Confirms changes before applying them. No scripts. No extra tools. Just clear instructions. This changed how I think about automation. Instead of writing scripts to do the work, you write instructions that guide the AI to do it. Same result. Less hassle. Works across every repo. Could I have done this with a Python script? Yes. But I'm already in Claude or Cursor anyway. So I built it where I work. Still experimenting with this approach. Curious - what task have you turned into a slash command? #AI #Cursor #Claude #VSCode #DevTools
To view or add a comment, sign in
-
⏳ Day 21 – 1 Minute Java Clarity – Polymorphism Explained Simply 🎭 Same action… different behaviour! 🔥 📌 What is Polymorphism? 👉 “Poly” = Many 👉 “Morphism” = Forms ✔ One method behaves differently based on the object 👉 It is the core of OOP and makes code flexible & reusable 📌 Types of Polymorphism 1️⃣ Compile-Time Polymorphism 👉 Achieved using Method Overloading class Calculator { int add(int a, int b) { return a + b; } double add(double a, double b) { return a + b; } } ✔ Same method → different parameters ✔ Decided at compile time 2️⃣ Runtime Polymorphism 👉 Achieved using Method Overriding class Animal { void sound() { System.out.println("Some sound"); } } class Dog extends Animal { void sound() { System.out.println("Dog barks!"); } } Animal a = new Dog(); a.sound(); // Dog barks! ✔ Parent reference → child object ✔ Decided at runtime 💡 Real-time Example 🎮 Game Character Same action → "attack()" Warrior → uses sword ⚔️ Archer → uses bow 🏹 Mage → casts spell 🔮 👉 Same method → different behaviour ⚠️ Interview Trap 👉 Can we achieve polymorphism without inheritance? ✔ YES (Using Method Overloading) ❌ NO (for Runtime polymorphism – needs inheritance) 💡 Quick Summary TypeMethodTimeExampleCompile-TimeOverloadingCompile Timeadd()RuntimeOverridingRuntimesound() 🔹 Why Polymorphism matters? ✔ Cleaner code ✔ Easy to extend ✔ Reduces duplication ✔ Helps in real-world system design 🔹 Next Topic → Encapsulation in Java 🔐 Which type do you find tricky — Compile-time or Runtime? Drop 👇 #Java #JavaProgramming #Polymorphism #OOPs #CoreJava #JavaDeveloper #BackendDeveloper #Coding #Programming #SoftwareEngineering #LearningInPublic #100DaysOfCode #ProgrammingTips #1MinuteJavaClarity
To view or add a comment, sign in
-
-
Exception handling became much clearer when I actually understood how try-catch works 👇 Earlier, I just used it to “stop crashes” without really knowing what was happening 🔹 Basic idea 👉 "try" → code that might fail 👉 "catch" → handle the error 🔹 Simple example try { int result = 10 / 0; } catch (ArithmeticException e) { System.out.println("Cannot divide by zero"); } ✔ Instead of crashing, the error is handled 🔹 Multiple catch blocks You can handle different exceptions differently: try { int[] arr = new int[5]; arr[5] = 10; } catch (ArithmeticException e) { System.out.println("Math error"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Index out of bounds"); } catch (Exception e) { System.out.println("General error"); } 👉 More specific exceptions should come first 🔹 finally block Runs no matter what (exception or not): try { // risky code } catch (Exception e) { // handle } finally { System.out.println("Always runs"); } ✔ Used for cleanup (closing files, DB connections, etc.) 🔹 Important things I learned ❌ Don’t use empty catch blocks ❌ Don’t catch Exception blindly every time ❌ Don’t hide errors — log or handle properly 🧠 Simple way I remember it 👉 try → risky code 👉 catch → handle problem 👉 finally → cleanup Still learning, but understanding this properly made my code more stable and easier to debug 💡 If you’re learning Java, what confused you most about try-catch? 👇 #Java #ExceptionHandling #Developers #Programming #LearningInPublic
To view or add a comment, sign in
-
-
⏳ Day 16 – 1 Minute Java Clarity – final Keyword in Java What if something should NEVER change? Use final! 🔒 📌 What is final? The final keyword restricts modification. 👉 It can be applied to variables, methods and classes. 📌 1️⃣ Final Variable: final int SPEED_LIMIT = 120; SPEED_LIMIT = 150; // ❌ Compilation Error! 👉 Once assigned, value can NEVER be changed. ✔ By convention, final variables are written in UPPER_CASE. 📌 2️⃣ Final Method: class Vehicle { final void start() { System.out.println("Engine started!"); } } 👉 Child class CANNOT override this method. ✔ Used when core behavior must stay consistent. 📌 3️⃣ Final Class: final class PaymentGateway { // Cannot be extended } 👉 No class can inherit from a final class. ✔ Example from Java itself → String class is final! 💡 Real-time Example: Think of a traffic system 🚦 Speed limit on a highway = 120 km/h No one can change that rule → that's your final variable! PI value in Math = 3.14159… It never changes → Math.PI is declared final in Java ✅ ⚠️ Interview Trap: final vs finally vs finalize — all different! 👉 final → restricts change 👉 finally → block in exception handling 👉 finalize → called by GC before object is destroyed 💡 Quick Summary ✔ final variable → value can't change ✔ final method → can't be overridden ✔ final class → can't be inherited ✔ String is a final class in Java! 🔹 Next Topic → Access Modifiers in Java Did you know String is a final class? Drop 💡 if this was new! hashtag #Java #JavaProgramming #FinalKeyword #CoreJava #JavaDeveloper #BackendDeveloper #Coding #Programming #SoftwareEngineering #LearningInPublic #100DaysOfCode #ProgrammingTips #1MinuteJavaClarity
To view or add a comment, sign in
-
-
🚀 Day 8 – final vs finally vs finalize (Clearing the Confusion) These three look similar but serve completely different purposes in Java. 👉 final (keyword) Used to restrict modification final int x = 10; // cannot be changed ✔ Variables → constant ✔ Methods → cannot be overridden ✔ Classes → cannot be extended --- 👉 finally (block) Used in exception handling try { // code } finally { // always executes } ✔ Runs whether exception occurs or not ✔ Commonly used for cleanup (closing resources) --- 👉 finalize() (method) @Override protected void finalize() throws Throwable { // cleanup code } ✔ Called by Garbage Collector before object destruction ⚠️ Important insight: "finalize()" is deprecated and unreliable — not recommended in modern Java. --- 💡 Quick takeaway: - "final" → restriction - "finally" → execution guarantee - "finalize()" → outdated cleanup mechanism Understanding these avoids confusion in both interviews and real projects. #Java #BackendDevelopment #JavaBasics #ExceptionHandling #LearningInPublic
To view or add a comment, sign in
-
what is serialization and deserialization ? Serialization is the process of converting an in-memory object (like a class instance in your backend code) into a format that can be easily stored or transmitted, such as: JSON XML Protocol Buffers Example: You have a user object in code: { "id": 1, "name": "Aman" } When you send this over an API, it gets serialized into JSON so it can travel over HTTP. What is Deserialization? Deserialization is the reverse process — converting the transmitted data (like JSON from an API request/response) back into an in-memory object your program can use. Example: You receive this JSON from a request: { "id": 1, "name": "Aman" } Your backend converts it into a language-specific object (e.g., a class instance in Java, Python, Node.js, etc.). Serialization = Packing your object into a suitcase (JSON) to travel Deserialization = Unpacking it back into usable form at the destination
To view or add a comment, sign in
-
#OOPSREVISION #SERIES LECTURE:16 + LECTURE 17 BY: Love Babbar Link :https://lnkd.in/g4cnY-PR ✅Classes, Objects, Constructors in Java 🔹 What is a Class? 👉 A Class is a blueprint/template used to create objects. 👉 It defines properties (variables) and behaviors (methods). 🔹 What is an Object? 👉 An Object is a real-world instance of a class. 👉 It represents actual data + behavior. ✅ A Constructor in Java is a special method used to initialize objects. It is automatically called when an object is created. 🔹 What is a Constructor? ✔ A constructor has the same name as the class. ✔ It does not have a return type (not even void). ✔ It is called automatically when using new keyword. 🔹 Why do we use Constructor? 👉 To initialize object values 👉 To reduce code repetition 👉 To make object creation clean and efficient 🚀 this Keyword in Java – The this keyword in Java is a reference variable that refers to the current object. 🔹 Why do we use this? 👉 To avoid confusion between instance variables and parameters. 👉 To access current class properties & methods. 👉 To make code more readable and clean. #Java #OOP #Programming #Coding #JavaDeveloper #InterviewPrep #TechLearning
To view or add a comment, sign in
-
📅 Date: April 27, 2026 Day 6 of my LeetCode Journey 🚀 ✅ Problem Solved: 14. Longest Common Prefix 🧠 Approach & Smart Solution: To solve this problem, I used a highly efficient Horizontal Scanning technique. Instead of comparing characters index by index across all strings, I assumed the very first string was the common prefix. Then, I iteratively compared it with the next strings, shaving off characters from the end until a match was found. By leveraging Java's built-in startsWith() method, the logic is kept clean and readable! • Pseudo-code: Assume the first string in the array is the initial 'prefix'. Loop through the rest of the strings in the array: While the current string does not start with the 'prefix': Shorten the 'prefix' by removing its last character. If the 'prefix' becomes completely empty, return "" (no common prefix exists). Return the final 'prefix' after checking all strings. This step-by-step reduction ensures we only do as much work as absolutely necessary. ⏱️ Time Complexity: O(S) (where S is the sum of all characters in all strings) 📦 Space Complexity: O(1) (Only modifying the prefix string, no extra arrays used) 📊 Progress Update: • Streak: 5 Days 🔥 • Difficulty: Easy • Pattern: String / Horizontal Scanning 🔗 LeetCode Profile: https://lnkd.in/gBcDQwtb (@Hari312004) Smartly utilizing built-in string methods like startsWith and substring can drastically reduce code complexity! 💡 #LeetCode #DSA #Strings #Java #CodingJourney #ProblemSolving #InterviewPrep #Consistency #BackendDevelopment
To view or add a comment, sign in
-
-
📊 Java ArrayList — Everything You Need to Know in One Visual Guide ArrayList is one of the most commonly used data structures in Java, but do you really understand what's happening under the hood? 🤔 I created this visual breakdown to help developers master ArrayList fundamentals 👇 ⏱️ Time Complexity at a Glance: Access: O(1) — Lightning fast Add: O(1) / O(n) Remove: O(n) Search: O(n) 🧠 Internal Magic: ArrayList uses continuous memory locations (backed by an array), giving it: ✅ O(1) direct access ✅ Efficient dynamic resizing ✅ Fast iteration ⚠️ The Tradeoff: Resizing can be expensive for large lists — it creates a new array and copies everything over. 💡 Use ArrayList When: ✅ You need frequent read/write operations ✅ You want indexed access ✅ Order matters ❌ Avoid ArrayList When: ❌ Heavy deletions (use LinkedList) ❌ Memory-critical apps ❌ Large fixed-size collections needed 🎯 Pro Tip: Understanding these internals isn't just for interviews — it's essential for writing performant, production-grade code! What's your go-to Java collection? Drop it in the comments! 👇 Save this for later & follow for more Java deep dives! 🚀 #Java #Programming #DataStructures #ArrayList #JavaDeveloper #SoftwareEngineering #CodingTips #100DaysOfCode #TechEducation #JavaInterview
To view or add a comment, sign in
-
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