DAY 18: CORE JAVA TAP Academy 🚀 Understanding Method Overloading in Java Method Overloading is one of the core concepts of Compile-Time Polymorphism in Java. It allows a class to have multiple methods with the same name but different parameter lists. Let’s break down how method overloading is observed and identified 👇 🔹 1. Method Name The method name must be the same. Example: add() can have multiple definitions within the same class. 🔹 2. Number of Parameters If the number of parameters is different, the method is overloaded. int add(int a, int b) int add(int a, int b, int c) 🔹 3. Type of Parameters Even if the number of parameters is the same, changing the data type makes it overloaded. int add(int a, int b) double add(double a, double b) 🔹 4. Order of Parameters If parameter types are the same but in a different order, it is still valid overloading. void display(int a, String b) void display(String b, int a) 🔹 5. Type Conversion (Implicit Casting) Java follows method matching rules: Exact match Widening (int → long → float → double) Autoboxing Varargs Example: void show(int a) void show(double a) If we call show(5), Java chooses the most specific match (int). 🔹 6. Ambiguity in Method Overloading Ambiguity occurs when Java cannot determine which method to call. Example: void test(int a, float b) void test(float a, int b) Calling test(10, 10) creates confusion because both methods are possible after type conversion. ⚠️ The compiler throws an error in such cases. 📌 Important Terms Related to Method Overloading ✔️ Compile-Time Polymorphism ✔️ Static Binding ✔️ Early Binding ✔️ Method Signature (method name + parameter list) ✔️ Implicit Type Promotion ✔️ Varargs ✔️ Autoboxing 💡 Key Rule to Remember Changing only the return type does NOT achieve method overloading. int sum(int a, int b) double sum(int a, int b) ❌ (Invalid) ✨ Method overloading improves code readability, flexibility, and reusability. It allows developers to perform similar operations in different ways without changing method names. Mastering this concept is essential for cracking Java interviews and writing clean object-oriented code. #Java #OOPS #Programming #SoftwareDevelopment #Coding #LearningJourney
Java Method Overloading Explained
More Relevant Posts
-
🚀 Day 35 – Core Java | Super Keyword, Method Types in Inheritance & Access Modifiers Today’s session connected multiple important concepts in Java Inheritance and clarified how classes interact with each other in real programs. 🔹 Super Keyword When both parent and child classes have the same variable or method, Java gives priority to the child class. To access the parent class version, Java provides the super keyword. Example: super.variableName super.methodName() ✔ Used to access parent variables ✔ Used to call parent methods Important difference: super() → used for constructor chaining super keyword → used to access parent properties and behaviors 🔹 Constructor Chaining Recap Constructor chaining can happen in two ways: 1️⃣ Within the same class this() 2️⃣ Between parent and child classes super() Important rule: Both this() and super() must be the first line of a constructor, so they cannot be used together in the same constructor. 🔹 Types of Methods in Inheritance In inheritance, methods fall into three categories: 1️⃣ Inherited Methods Methods that the child class directly acquires from the parent without any modification. Example: takeoff() land() 2️⃣ Overridden Methods Methods that the child class inherits and then modifies. Example: fly() Each plane type flies differently. Java uses: @Override This annotation helps: Documentation Detecting coding mistakes 3️⃣ Specialized Methods Methods created only in the child class. Example: carryCargo() carryPassengers() carryWeapons() These methods do not exist in the parent class. 🔹 Real Example Used in Class We designed a Plane system using inheritance. Parent Class: Plane Methods: takeoff() fly() land() Child Classes: CargoPlane PassengerPlane FighterPlane Each child: inherits takeoff() and land() overrides fly() adds specialized methods This demonstrated how code reuse reduces development effort. 🔹 Access Modifiers in Java To understand inheritance properly, we also explored Access Modifiers. Key observation: Public → Maximum visibility Private → Minimum visibility Visibility decreases in this order: public → protected → package access → private 💡 Biggest Takeaway Understanding inheritance is not just about writing extends. It requires clarity about: Constructor chaining Method overriding Code reuse Access control Class relationships These concepts are fundamental before moving to the next pillar of OOP – Polymorphism. #Day35 #CoreJava #Inheritance #SuperKeyword #MethodOverriding #JavaOOP #AccessModifiers #DeveloperJourney
To view or add a comment, sign in
-
-
📘 Java Learning – Multithreading (Part 1: Multitasking & Thread Creation) 🚀🎯 Starting my learning journey into Java Multithreading, one of the most powerful features of Java used for executing multiple tasks simultaneously. 🔰 Multitasking Executing several tasks simultaneously is called Multitasking. There are two types of multitasking: 👉 Process Based Multitasking 👉 Thread Based Multitasking 1️⃣ Process Based Multitasking Executing several tasks simultaneously where each task is a separate independent process. Example: Running multiple applications at the same time: • Browser • Music Player • Code Editor ✔ Best suited at Operating System level 2️⃣ Thread Based Multitasking (Multithreading) Executing several tasks simultaneously where each task is an independent part of the same program. Each independent path of execution is called a Thread. ✔ Best suited for Programmatic level 🎯 Objective of Multitasking • Improve system performance • Reduce response time 📌 Applications of Multithreading Multithreading is widely used in: • Video games • Multimedia graphics • Animations • High performance applications 🔰 Multithreading Support in Java Java provides rich API support for multithreading through: • Thread • Runnable • ThreadGroup • ThreadLocal ✔ Java provides built-in APIs for multithreading, and programmers use these APIs to create and manage threads. This makes multithreading easier in Java compared to C++. 🔰 Ways to Create a Thread A thread can be defined in two ways: 1️⃣ Extending Thread class 2️⃣ Implementing Runnable interface 📌 Example – Extending Thread Class class MyThread extends Thread { public void run() { for(int i=0;i<5;i++){ System.out.println("Child Thread"); } } } public class ThreadDemo { public static void main(String[] args) { MyThread t = new MyThread(); // instantiation of thread t.start(); // starting of a thread for(int i=0;i<5;i++){ System.out.println("Main Thread"); } } } 📌 start() does NOT directly execute run(). It does: start() ↓ JVM asks Thread Scheduler ↓ New Thread Created ↓ run() executes in new thread ⭐ Key Points • start() method creates a new thread • run() contains the task executed by thread • Multiple threads execute simultaneously More concepts like Thread Scheduler, start() vs run(), Thread Lifecycle in the next post. #Java #CoreJava #Multithreading #JavaDeveloper #Concurrency #LearningJourney
To view or add a comment, sign in
-
🚀 Day 127 of My Java Learning Journey 🤩 Hi Friends, Today I learned how to join two lists using Stream API in Java in a clean and modern way. Instead of using loops, we can use Stream.concat() to combine two lists easily. ------------------------------------------------------------------------------------------- 💻 Code ------------> import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class JoinTwoList { public static void main(String[] args) { List<Integer> list1 = List.of(1, 2, 3); List<Integer> list2 = List.of(4, 5, 6); List<Integer> joinList = Stream .concat(list1.stream(), list2.stream()) .collect(Collectors.toList()); System.out.println("Lists are Joined: " + joinList); } } ------------------------------------------------------------------------------------------- 🖥️ Output Lists are Joined: [1, 2, 3, 4, 5, 6] 🔎 Output Explanation list1.stream() converts first list into stream list2.stream() converts second list into stream Stream.concat() merges both streams Collectors.toList() converts the combined stream back into a list So both lists are joined into a single list. 📌 Important Concept 👉 Stream.concat(Stream s1, Stream s2) It is used to combine two streams into one stream. This method is very useful when working with collections in a functional programming style. 💡 Important Tip List.of() creates an immutable list. You cannot modify it (add/remove elements). If you need a modifiable list, wrap it like this: new ArrayList<>(List.of(1,2,3)); 🤔 Have You Tried This? Do you prefer: Using loops to join lists? Or using Stream API? Let me know your approach in the comments 👇 I am consistently improving my Java skills step by step. If you are also learning Java, let’s grow together 💪 #Java #JavaDeveloper #StreamAPI #Programming #CodingJourney #DevOps #BackendDevelopment #LearningEveryday #day127 #codewithyuvi #Logicalworld
To view or add a comment, sign in
-
-
🚀 Day 19 at TAP Academy – Exploring Java Arrays in Depth Today’s session was focused on gaining a deeper understanding of Java Arrays and how they are used in real programming scenarios. We started with a quick recap of the limitations of arrays, such as storing only homogeneous data, fixed size allocation, and the requirement of contiguous memory. 💡 One of the key topics covered was the three different ways to create arrays in Java: 1️⃣ Standard array creation using new keyword (most commonly used in real programs). 2️⃣ Creating arrays with predefined values using new int[]{} syntax. 3️⃣ Shorthand array initialization using {} without the new keyword. We also explored how arrays can be created for different primitive data types like byte, short, int, float, double, char, and boolean, along with the corresponding Scanner methods used to take input from users. 🔤 Another interesting concept was handling character input in Java, where we learned the workaround using: scan.next().charAt(0) since Java does not provide a direct nextChar() method. 📦 The session then moved to Arrays of Strings, which highlighted how Java treats Strings as objects and how they can be stored and accessed in arrays similar to primitive types. 👨💻 One of the most important parts of the class was learning about Arrays of Objects using an Employee class example. This helped in understanding: ✔ How objects are created and stored in arrays ✔ The concept of pass-by-reference ✔ How loops can be used to optimize code and avoid repetition when dealing with multiple objects This approach makes programs scalable and efficient, allowing the same logic to work whether we handle 2 objects or thousands of objects. ⚙️ Finally, we explored Command Line Arguments (String[] args), which clarified how Java programs can receive inputs directly from the command line during execution. This concept also introduced how all command-line inputs are treated as Strings, which leads into the next important topic — Java Strings. 📚 Key Takeaways from Today’s Session: • Different ways to create arrays in Java • Arrays with primitive data types and Scanner methods • Handling character input using charAt() • Working with arrays of Strings • Creating and managing arrays of objects • Understanding command line arguments in Java • Writing optimized and scalable code using loops Every session at TAP Academy continues to strengthen my core Java concepts and programming logic, bringing me one step closer to becoming a better developer. 💻✨ #Java #Programming #JavaArrays #LearningJourney #Coding #SoftwareDevelopment #TAPAcademy #JavaDeveloper 🚀
To view or add a comment, sign in
-
-
🚀 Day 39 – Core Java | Polymorphism, Upcasting & Downcasting Today’s session focused on understanding the third pillar of Object-Oriented Programming — Polymorphism and how it works internally in Java. 🔹 What is Polymorphism? The word Polymorphism comes from Greek: Poly → Many Morph → Forms Meaning: One entity behaving in multiple forms. In Java, this is achieved mainly using method overriding and inheritance. 🔹 Example Used A Plane parent class with a method: fly() Three child classes: CargoPlane PassengerPlane FighterPlane Each class overrides the fly() method and behaves differently. Example: Cargo Plane → flies at low height Passenger Plane → flies at medium height Fighter Plane → flies at high altitude This demonstrates one method → multiple behaviors. 🔹 Tight Coupling vs Loose Coupling Tight Coupling Child reference → Child object CargoPlane cp = new CargoPlane(); cp.fly(); Here both reference and object are child type. Loose Coupling (Used for Polymorphism) Parent reference → Child object Plane ref = new CargoPlane(); ref.fly(); Here: Parent reference Child object This allows polymorphic behavior. 🔹 Types of Methods in Inheritance 1️⃣ Inherited Method Method comes directly from parent. 2️⃣ Overridden Method Child modifies the parent method. 3️⃣ Specialized Method Method exists only in child class. Example: carryCargo() carryPassengers() carryWeapons() 🔹 Important Rule Using parent reference, we can access: ✔ Inherited methods ✔ Overridden methods ❌ Cannot access specialized methods. 🔹 Downcasting To access child-specific methods: Parent reference must behave like a child. Example: ((CargoPlane) (ref)).carryCargo(); This process is called Downcasting. 🔹 Upcasting Plane ref = new CargoPlane(); Child object assigned to parent reference. This is called Upcasting and it happens automatically in Java. 🔹 Advantages of Polymorphism 1️⃣ Code Reduction Common logic can be reused instead of repeating code. 2️⃣ Code Flexibility One method can handle multiple object types. Example: airport.permit(plane) The same method can accept: CargoPlane PassengerPlane FighterPlane 💡 Key Takeaway Polymorphism allows one interface to perform multiple behaviors, making Java programs: More flexible Easier to maintain Less repetitive It is one of the most powerful concepts used in real-world Java applications and interviews. #CoreJava #Polymorphism #JavaOOP #MethodOverriding #Upcasting #Downcasting #JavaLearning #DeveloperJourney #InterviewPreparation
To view or add a comment, sign in
-
-
Standard Signature of main() Method in Java In every programming language there must be an entry point of execution from where program execution begins. In C/C++, the entry point is the main() function, which is invoked by the Operating System. OS expects 0 as exit status indicating successful program execution so the return type of main is commonly int. In Java, the entry point is also the main() method, but it is invoked by the Java Virtual Machine (JVM) instead of the OS. Since the JVM handles execution internally, there is no need to return a status code, therefore the return type of the main method is always void. In Java, every method belongs to a class, so the main method must be defined inside a class. Example: class Main { void main() { // code } } However, this method cannot be executed by the JVM because it is not accessible outside the class. To allow the JVM to access it, the method must be declared public. class Main { public void main() { // code } } In Java, methods normally belong to objects and are invoked using an object reference. If the main method were not static, the JVM would have to create an object of the class before calling it. Since main is the entry point of every program, this would add unnecessary overhead. To allow the JVM to invoke the method without creating an object, the main method is declared static. class Main { public static void main() { // code } } But this method still cannot receive data from the command line arguments. To accept input from the command line during program execution, the main method takes a parameter which is an array of strings. Each element of this array represents one argument passed from the command line. Final standard signature of the main method: class Main { public static void main(String[] args) { // code } } Here: public → allows the JVM to access the method static → allows the JVM to call the method without creating an object void → no return value required String[] args → receives command line arguments However, for a beginner writing "public static void main(String[] args)" is overwhelming. So Java developer decided to introduce simplified syntax for new comer to maintain language acceptance and popularity among all. In newer Java versions, we can write a simpler program like: void main() { System.out.println("Hello"); } Introduced in JDK 21 and finally accepted in JDK 25 (2025). The compiler automatically wraps this into a class behind the scenes. However, this feature is mainly designed for learning and small scripts, while the traditional main method remains the standard approach used in real applications. Grateful to my mentor Syed Zabi Ulla for explaining these concepts so clearly and helping me build a strong foundation in programming. #OOP #Java #Programming #ComputerScience #LearningJourney #SoftwareDevelopment
To view or add a comment, sign in
-
🚀 Day 21 | Core Java Learning Journey 📌 Topic: Exception Handling Keywords in Java Today I learned the most important Java exception handling keywords: try, catch, finally, throw, throws — and the commonly confused finalize(). Understanding them is essential for writing clean, production-ready Java code 💡 🔹 try ✔ Wraps risky code ✔ Must be followed by catch or finally ✔ Cannot exist alone ✔ Multiple catch blocks allowed Syntax : try { // risky code } catch(Exception e) { // handling } 🔹 catch ✔ Handles exceptions from try ✔ Takes exception object as parameter ✔ Order matters (Child → Parent) ✔ Multiple catch blocks allowed 🔹 finally ✔ Always executes (whether exception occurs or not) ✔ Executes even if return statement is present ✔ Used for cleanup (files, DB, etc.) ✔ Won’t execute only if JVM crashes or System.exit() is called 🔹 throw ✔ Explicitly throws an exception ✔ Used inside method body ✔ Can throw checked & unchecked exceptions ✔ Followed by exception object throw new IllegalArgumentException("Invalid Age"); 🔹 throws ✔ Declares exception responsibility ✔ Used in method signature ✔ Mainly for checked exceptions ✔ Can declare multiple exceptions public void readFile() throws IOException { // code } 🔥 throw vs throws ✔ throw → Inside method body ✔ throws → In method declaration ✔ throw → Single exception ✔ throws → Multiple exceptions 🔹 finalize() (Important) ✔ NOT part of exception handling ✔ Belongs to Garbage Collection ✔ Defined in Object class ✔ Called before object destruction ✔ Deprecated (Java 9+) 🔥 finally vs finalize() ✔ finally → Exception handling block ✔ finalize() → GC method ✔ finally → (Almost) always runs ✔ finalize() → May or may not run 📌 Key Takeaways ✔ finally ensures cleanup ✔ throw creates exceptions ✔ throws delegates responsibility ✔ finalize() relates to memory management Small keywords — powerful concepts 💻🚀 Special thanks to Vaibhav Barde Sir . #CoreJava #JavaLearning #ExceptionHandling #JavaDeveloper #OOP #LearningJourney
To view or add a comment, sign in
-
-
🚀 Types of Inheritance in Java | Core Java OOPS As part of my Core Java learning at TAP Academy, I explored the different types of Inheritance in Java and their importance in Object-Oriented Programming (OOPS). 🔹 What is Inheritance? Inheritance is the process of acquiring the properties (variables) and behavior (methods) of one class (Parent) into another class (Child) using the extends keyword. It promotes: ✔ Code Reusability ✔ Logical Hierarchy ✔ Maintainability ✔ Runtime Polymorphism 📌 Types of Inheritance in Java 1️⃣ Single Inheritance One Parent → One Child The child class extends only one parent class. ✅ UML Diagram Parent ↑ Child 2️⃣ Multilevel Inheritance Grandparent → Parent → Child A class inherits from a parent class, and that parent class further inherits from another class. ✅ UML Diagram GrandParent ↑ Parent ↑ Child 3️⃣ Hierarchical Inheritance One Parent → Multiple Children Multiple child classes inherit from a single parent class. ✅ UML Diagram Parent / \ Child1 Child2 4️⃣ Hybrid Inheritance Combination of Single + Hierarchical inheritance. Java does not support hybrid inheritance directly using classes (because it may lead to ambiguity), but it can be achieved using interfaces. ✅ UML Diagram GrandChild | Parent / \ Child1 Child2 5️⃣ Multiple Inheritance (Not Supported in Java via Classes) Multiple parent classes → One child class Java does not allow multiple inheritance using classes because it causes the Diamond Problem. 🔶 What is Diamond Problem? The Diamond Problem is an ambiguity that arises when: A subclass inherits from two parent classes Both parent classes inherit from the same grandparent The subclass cannot determine which version of the method to inherit ❌ UML Diagram (Diamond Structure) GrandParent / \ Parent1 Parent2 \ / Child Because of this ambiguity, Java does not allow: class Child extends Parent1, Parent2 // ❌ Not Allowed However, Java supports multiple inheritance through interfaces. 🚫 Cyclic Inheritance (Not Allowed) Cyclic inheritance occurs when: A class tries to inherit from itself directly or indirectly. Example (Conceptually): Class A extends B Class B extends A // ❌ Not Allowed This creates an infinite inheritance loop, so Java restricts it. 🎯 Key Takeaways ✔ Java supports: Single Inheritance Multilevel Inheritance Hierarchical Inheritance ✔ Java does NOT support: Multiple Inheritance (via classes) Cyclic Inheritance ✔ Hybrid inheritance is achieved using interfaces in Java. Understanding inheritance deeply strengthens the foundation of Core Java OOPS and helps in designing scalable and maintainable applications. Grateful for the structured learning experience at TAP Academy as I continue building my strong Java fundamentals. #Java #CoreJava #OOPS #Inheritance #LearningJourney #Internship #TAPAcademy TAP Academy
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