Day 26... 💡Today, I explored a brand new concept — Method Overloading in Java. Here’s a 1-minute recap 🧠👇 🔹 Definition: Method Overloading means defining multiple methods with the same name in a class, but with different parameter lists (number or type). 🔹 How Java Resolves It: At compile time, the Java compiler checks: 1️⃣ Method name 2️⃣ Number of parameters 3️⃣ Type of parameters …and calls the correct version — avoiding any confusion. 🔹 Key Insight: No method is truly “overloaded.” Each method performs its own unique task — we, as programmers, just assume one name does many things. 🔹 Why Called Compile-Time Polymorphism? Because the method to be executed is decided at compile time. 🔹 Polymorphism in Simple Words: “One in many forms.” Example: Water 💧 Ice ❄️ → Solid Water 💦 → Liquid Steam ☁️ → Gas That’s polymorphism — and method overloading is its compile-time version! #Java #Learning #Polymorphism #MethodOverloading #JavaDeveloper #CodingJourney
Java Method Overloading Explained
More Relevant Posts
-
🚀 LeetCode 242: Valid Anagram — Solved! ✅ Today, I solved the Valid Anagram problem on LeetCode using Java. Sharing the step-by-step approach I followed 👇 🔍 Problem Understanding Given two strings s and t, check whether t is an anagram of s. (An anagram has the same characters with the same frequency, just arranged differently.) 🧠 Steps I Followed to Solve It 1️⃣ Length Check If the lengths of both strings are not equal, they can never be anagrams. → Return false immediately. 2️⃣ Convert Strings to Character Arrays Converted both strings into character arrays using toCharArray() so that sorting is possible. 3️⃣ Sort Both Arrays Sorted both character arrays using Arrays.sort(). 4️⃣ Compare Characters One by One After sorting, if all characters at the same index are equal, the strings are anagrams. 5️⃣ Final Result If any mismatch is found → false If all characters match → true 💻 Time Complexity: O(n log n) (due to sorting) 📦 Space Complexity: O(n) ✨ This approach is simple, clean, and easy to understand — great for beginners in DSA! #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Placements #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 78 of- #100DaysOfCode Today’s problem: Check if the Sentence Is Pangram A pangram is a sentence that contains every letter of the English alphabet at least once. 🔹 Approach I Used: Loop from 'a' to 'z' Check if each character exists in the given string If any character is missing → return false If all characters are present → return true 💻 Java Solution: 🧠 Time Complexity: O(26 * n) → Since we check 26 letters and contains() takes O(n) Simplified: O(n) 📌 Space Complexity: O(1) (No extra data structure used) 💡 What I Learned: Sometimes simple brute-force solutions are clean and efficient enough. Always analyze time complexity even for small loops like 26 characters.
To view or add a comment, sign in
-
-
🚀 Dutch National Flag Algorithm in Java (0s, 1s, 2s sorting) Today I implemented an efficient Java solution to sort an array containing only 0s, 1s, and 2s — without using any extra space. 🔹 Approach Used: I used the Dutch National Flag Algorithm, which works in O(n) time and O(1) space. 🔹 Key Idea: We maintain three pointers: low → boundary for 0s mid → current element high → boundary for 2s 🔹 Logic: If element is 0 → swap with low, move both low and mid If element is 1 → just move mid If element is 2 → swap with high, move high This ensures all: 0s come first 1s stay in the middle 2s move to the end 💡 Simple logic, powerful optimization! #Java #DSA #DutchNationalFlag #CodingInterview #TCSNQT #ProblemSolving #Arrays #LearningByDoing MD SADIQUE Sharath R Harshit T
To view or add a comment, sign in
-
-
🚀 “ArrayList is Dynamic” — But Is It Really? When I first learned Java, I was told: “ArrayList is dynamic in size.” I accepted it. But later I asked myself: How? Because arrays in Java are fixed size. 🤔 So how can something built on arrays be dynamic? 🔍 The Truth Most Tutorials Don’t Explain ArrayList is backed by: Object[] elementData; Yes. It is literally an array. And arrays cannot grow. So what’s happening behind the scenes? ⚙️ What Actually Happens When It Becomes Full Let’s say capacity = 10. You insert the 11th element. Java does this: 1️⃣ Creates a new bigger array 2️⃣ New capacity = old + (old / 2) 3️⃣ Copies all old elements 4️⃣ Adds the new element So: 10 → 15 → 22 → 33 → ... It grows by 50%. That’s how it becomes “dynamic.”
To view or add a comment, sign in
-
-
In modern c++, you can do this: class MyClass { int value; public: MyClass(int value) : value{value} {} }; But you have to be careful when using the ”value” in the constructor body. The plain ”value” refers to the constructor parameter and if you want to access the member variable, you need to qualify it with ”this”, i.e. ”this->value”. This pattern is familiar for Java coders. It is becomes very important if you move, e.g. class MyClass { MyValue value; public: MyClass(MyValue value) : value{std::move(value)} {} }; Now you can use only ”this->value” in the constructor body because ”value” was moved. Always use a linter like clang-tidy to catch issues where you attempt to use a moved value
To view or add a comment, sign in
-
🚀 Java Revision Journey – Day 05 Continuing my Java revision, today I focused on number-based logic and pattern problems, which help strengthen problem-solving skills and improve understanding of how numbers are handled in Java. These concepts are very useful for building logical thinking and are commonly used in coding practice, competitive programming, and technical interviews. 📌 Topics Covered: Number Logic & Mathematical Concepts ✔ Sum of first N numbers → n*(n+1)/2 or iterative addition ✔ Finding the last digit → n % 10 (positive numbers) or Math.abs(n % 10) for both positive & negative ✔ Finding the first digit using log10 and Math.pow ✔ Counting number of digits • String conversion + length() • Iterative division (n/10) • Mathematical approach using log10 Date & Mathematical Sequences ✔ Finding day before/after N days using modular arithmetic ✔ Arithmetic Progression (AP): a + (n-1)d ✔ Geometric Progression (GP): a * r^(n-1) Bitwise & Number Properties ✔ Right Shift / Left Shift → n >> k and n << k ✔ Even or Odd check → n % 2 or n & 1 ✔ Largest of three numbers using ternary operator and Collections.max() Number Problems ✔ Leap Year (conditional logic and isLeap() method) ✔ Palindrome Number ✔ Anagram Number Patterns ✔ Pyramid patterns ✔ Number-based patterns 💡 Why this is important: Practicing number logic and pattern problems improves algorithmic thinking, mathematical reasoning, and control over loops and conditions in Java. These fundamentals play a key role in solving coding problems and building strong programming logic. Consistently strengthening my Core Java fundamentals step by step. #Java #CoreJava #Programming #JavaDeveloper #BackendDevelopment #ProblemSolving #CodingPractice #LearningJourney
To view or add a comment, sign in
-
-
Understanding Constructors : Every object in Java has a beginning. But how that object is born matters for the stability of your entire application. A Constructor is a special block of code that is called when an instance of a class is created. It looks like a method, but it has two unique rules: 1.It must have the same name as the class. 2.It cannot have a return type (not even void). The 3 Types of Constructors You Need to Know: 1️⃣ The Default Constructor: If you don't write one, Java provides a "no-argument" constructor for you automatically. 2️⃣ No-Arg Constructor: A manual constructor with no parameters, often used to set default values. 3️⃣ Parameterized Constructor: This is where the magic happens. You pass data in at the moment of creation to ensure your object starts in a valid state. Key Concepts: Memory Allocation: Constructors don't actually "create" the object (the new keyword does that); the constructor initializes the memory that was just allocated. Overloading: You can have multiple constructors in one class as long as their parameter lists are different. The this Keyword: Essential for distinguishing between class variables and constructor parameters when they have the same name. ⚠️ The "Hidden Trap": Did you know that as soon as you write one parameterized constructor, Java stops providing the automatic default constructor? This is a common source of compilation errors for beginners! TAP Academy #JavaProgramming #BackendDevelopment #CodingBasics #SoftwareEngineering #LearningToCode
To view or add a comment, sign in
-
-
Today I explored the concept of Functional Interface in Java. A Functional Interface is an interface that contains only one abstract method, but it can also include: ✔ Default methods ✔ Static methods ✔ Private methods ✔ Private static methods This concept became even more powerful with the introduction of Lambda Expressions in Java 8 (JDK 1.8). Lambda expressions help developers write cleaner, shorter, and more readable code. 📌 I also learned different ways to implement a Functional Interface: 1️⃣ Using an Outer Class 2️⃣ Using an Inner Class 3️⃣ Using an Anonymous Inner Class 4️⃣ Using a Lambda Expression Among these, Lambda Expressions make the implementation much simpler and reduce boilerplate code. 💡 Example of Lambda Expression: Calculator c = (a, b) -> System.out.println(a + b); This learning helped me understand how modern Java makes coding more concise and efficient. I’m currently improving my Java Full Stack Development skills and sharing my learning journey step by step. #Java #JavaDeveloper #TapAcademy
To view or add a comment, sign in
-
-
In my previous post, I introduced Classes and Objects — the foundation of 𝐎𝐛𝐣𝐞𝐜𝐭-𝐎𝐫𝐢𝐞𝐧𝐭𝐞𝐝 𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 (𝐎𝐎𝐏) in Java. But a structure alone isn’t enough. A mobile phone isn’t useful just because it exists 📱 It becomes useful when it can make calls, send messages, or play music. That behavior is what methods bring to a class. ⚙️ 𝐌𝐞𝐭𝐡𝐨𝐝𝐬 A method is a 𝒃𝒍𝒐𝒄𝒌 𝒐𝒇 𝒄𝒐𝒅𝒆 that performs a specific task. Instead of writing the same logic again and again, we define it once inside a method and simply call it whenever needed. This makes programs: ✔ cleaner ✔ reusable ✔ easier to maintain 🔹 Common Types of Methods in Java • No parameters, no return value • With parameters, no return value • No parameters, with return value • With parameters, with return value Each type helps a program interact with data in different ways. I’ve attached simple examples for each type of method in the code snippet below 👇 Next, I’ll explore Constructors — how objects receive their initial values the moment they are created. #Java #CoreJava #OOP #Methods #Programming #LearningJourney #BuildInPublic
To view or add a comment, sign in
-
-
🚀 DSA Journey – Day 4 (Java) Today I moved deeper into Functions in Java (Methods) and explored how Java handles memory and parameters internally. In Java, functions are called methods, and I understood the structure clearly: static returnType methodName(parameters) { // method body } 📘 What I learned today: 🔹 Pass by Value in Java Java is strictly pass by value. For primitive types (int, char, double, etc.) Only a copy of the value is passed. So swapping two numbers inside a method does NOT affect the original variables. For objects (arrays, strings, classes) A copy of the reference is passed. So modifying the object inside the method affects the original object. It is not pass by reference because Java does not expose raw pointers like C/C++. 🔹 Scoping & Shadowing Local variables exist only inside their block/method Class-level variables can be accessed across methods Shadowing happens when a local variable hides a class variable with the same name 🔹 Variable Arguments (Varargs) Using: datatype... v Allows passing multiple values Internally treated as an array Must always be the last parameter 🔹 Method Overloading Multiple methods with the same name but different parameters (Changing type or number of parameters) This improves readability and flexibility of code. Today’s session made me realize that understanding how methods behave internally is crucial before moving deeper into DSA. 📌 Next: Strengthening arrays and problem-solving. Step by step. Consistency over speed. #DSA #Java #LearningInPublic #Day4 #BTechStudent #AspiringSoftwareEngineer
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