Day 40 of Learning Java: Method Overloading Instead of creating different method names for similar tasks, we can use the same method name but change the parameters — and Java figures out which one to call. -So what exactly is Method Overloading? It’s when multiple methods in the same class have: ✔ Same name ✔ Different parameter list That’s it. Simple idea, but very powerful. -Ways to overload a method • Change the type of parameters • Change the number of parameters • Change the order of parameters Example- Think of a login system: Login using username + password Login using mobile + password Both are login actions, right? So instead of writing different method names, we just overload: login(String username, String password) login(long mobile, String password) Same method name → different ways to use it -Another relatable one Payment systems 👇 COD UPI Card Net Banking Instead of: paymentByUPI(), paymentByCard()… We can just do: payment() payment(String upi) payment(long card) payment(String user, String pass) - Important things I learned • Just changing return type won’t work (it gives error) • Overloading happens at compile time • Works with static, private, and even final methods • Yes, even main() can be overloaded (but JVM only runs the standard one) #Java #LearningInPublic #100DaysOfCode #Programming #OOP #CodingJourney
Java Method Overloading Explained
More Relevant Posts
-
🚀 Starting My Java Learning Journey – Day 16 🔹 Topic: Encapsulation in Java. Encapsulation is one of the core OOP concepts. It is the process of wrapping data (variables) and code (methods) into a single unit (class). It also helps in data hiding. 📌 How to Achieve Encapsulation? ✔ Declare variables as private. ✔ Provide public getter and setter methods to access and update values. 📌 Example Program class Student { private String name; // Getter method public String getName() { return name; } // Setter method public void setName(String name) { this.name = name; } } public class Main { public static void main(String[] args) { Student s1 = new Student(); s1.setName("John"); System.out.println(s1.getName()); } } Output: John 💡 Key Points: ✔ Protects data from unauthorized access. ✔ Improves security and flexibility. ✔ Achieved using private variables + getters/setters. #Java#JavaLearning #Programming #BackendDevelopment #CodingJourney #Encapsulation #OOP#
To view or add a comment, sign in
-
📘✨ Collections and Framework Introduction to ArrayList in Java – Conceptual Overview 🚀 Continuing my learning, I focused on the theory behind ArrayList, a fundamental part of Java’s data handling 📋 🔹 ArrayList is a class that implements a dynamic array, meaning its size can change automatically during runtime 🔄 🔹 It belongs to the Java Collections Framework and is widely used for storing and managing data efficiently 💡 Core Properties: ✔ Preserves insertion order 📑 ✔ Allows duplicate elements 🔁 ✔ Provides random (index-based) access ⚡ ✔ Dynamically resizes as data grows 📈 💡 Performance Insight ⚙️ - Fast for accessing elements (O(1)) - Slower for inserting/removing elements in between (due to shifting) - Better suited for read-heavy operations 💡 Behind the Scenes 🔍 - Internally uses an array structure - When capacity is full, it creates a larger array and copies elements - Default capacity grows automatically 💡 Use Cases 🌍 📌 Managing lists of students, products, or records 📌 Applications where order matters 📌 Situations where frequent searching/access is required 💡 Drawbacks ⚠️ ❌ Not efficient for frequent insertions/deletions ❌ Not thread-safe without synchronization 🎯 Final Thought 💡 ArrayList offers a perfect balance between simplicity and performance, making it one of the most commonly used data structures in Java 💻✨ #Java #ArrayList #Collections #Programming #CodingLife #Developer #LearningJourney #HarshitT #TapAcademy
To view or add a comment, sign in
-
-
Day 58/200 - Java Learning Journey 🌱 ✨ Sharing what I learned today in Java. 📚 Today I learned about Encapsulation in Java Today's Topic: Encapsulation ✴️ Encapsulation: 👉 It means wrapping(hiding) the data (variables,methods) and providing the controlled access. 🔯 Advantages/Features: 🔺 Security 🔺 Hiding the data 🔺 Controlled access 🔺 Validation 🔺 Flexibility 🔆 How to hide the data ❓ ▪️ By making those variables,methods to be private. 1️⃣ Setters: 👉 These are used to set the data. 2️⃣ Getters: 👉 Get or return the data. 🔸 Syntax: For setters: access_modifier returntype(void) settersName(){ -------------//data } For getters: access_modifier returntype gettersName(){ return value; } 💠 Without setters we cant use getters. 💠 Without getters we can set the value by using setters. 👎 Drawback: 👉 In Encapsulation for each and every variables we need to use setters to set the value to those variables. #Java#Encapsulation#OOPS#DailyLearning#Consistency#Meghana M#10000 Coders#
To view or add a comment, sign in
-
-
📘 Day 6 of Java Learning Series 🔹 Control Statements in Java (if-else, loops) Control statements help us control the flow of execution in a program. They allow decision-making and repetition of tasks. 🔸 1. if-else Statement (Decision Making) Used when we want to execute code based on a condition. 💡 Example: int age = 18; if (age >= 18) { System.out.println("You can vote"); } else { System.out.println("You cannot vote"); } 🔸 2. Loops (Repetition) Loops help us execute a block of code multiple times. 👉 for loop (when number of iterations is known) for (int i = 1; i <= 5; i++) { System.out.println(i); } 👉 while loop (runs while condition is true) int i = 1; while (i <= 5) { System.out.println(i); i++; } ✅ Key Takeaways: ✔ if-else → decision making ✔ loops → repetition ✔ for loop → fixed iterations ✔ while loop → condition-based execution 💬 Which loop do you use more – for or while? 👉 Follow me for more Java content 🚀 #Java #Programming #100DaysOfCode #Developers #Learning #CoreJava
To view or add a comment, sign in
-
-
🚀 Core Java Learning Journey Explored Constructors in Java and the rules for writing them ☕ 🔹 What is a Constructor? A constructor is a special method used to initialize objects. It is automatically called when an object is created. 📌 Key Features of Constructors: ✅ Same name as the class ✅ No return type (not even "void") ✅ Automatically invoked during object creation ✅ Used to initialize instance variables 🔹 Types of Constructors: ✔️ Default Constructor ✔️ Parameterized Constructor 📌 Rules for Writing Constructors: 🔸 Constructor name must be the same as the class name 🔸 It should not have any return type 🔸 Can be overloaded (multiple constructors in one class) 🔸 Cannot be static, final, or abstract 🔸 If no constructor is written, Java provides a default constructor 💡 Example: class Student { int id; String name; Student(int i, String n) { // Parameterized constructor id = i; name = n; } } 🎯 Key Takeaway: Constructors make object initialization easy and are a fundamental part of Object-Oriented Programming in Java. Learning and growing at Dhee Coding Lab 💻 #Java #CoreJava #Constructors #OOP #Programming #LearningJourney #FullStackDevelopment
To view or add a comment, sign in
-
🚀 Exploring Method Overloading in Java As part of my journey in mastering Object-Oriented Programming in Java, I recently explored one of the most powerful concepts of Polymorphism — Method Overloading. 💡 What is Method Overloading? Method overloading is the process of creating multiple methods with the same name in a class, but with different parameter lists. It allows the same action to behave differently based on the input — making programs more flexible and readable. 🔹 Three Ways to Achieve Method Overloading A method can be overloaded by changing: 1️⃣ Number of parameters 2️⃣ Data types of parameters 3️⃣ Order/sequence of parameters ❌ Invalid Case If two methods have the same name + same parameters but different return types, it is NOT valid overloading and results in a compile-time error. Example: int area(int, int) float area(int, int) → Compilation Error 🚫 🧠 Why is it called False (Virtual) Polymorphism? To the user, it looks like one method performing multiple tasks (one-to-many). But internally, each call maps to a separate method (one-to-one) — hence the term False Polymorphism. ⚡ Type Promotion in Overloading If an exact match is not found, Java automatically promotes smaller data types to larger ones: byte → short → int → long → float → double This makes method overloading even more powerful and flexible! 👩💻 Simple Example class AreaCalculator { int area(int l, int b) { return l * b; } double area(double r) { return 3.14 * r * r; } int area(int side) { return side * side; } } TAP Academy ✨ Learning these core OOP concepts is helping me build stronger foundations in Java and improve my problem-solving skills step by step. #Java #OOP #Programming #CodingJourney #ComputerScience #LearningInPublic
To view or add a comment, sign in
-
-
One of the most confusing things in Java (at least for me) 👇 👉 final vs finally vs finalize They sound similar… but mean completely different things 😅 🔹 final 👉 Used to restrict something • final variable → value can’t change • final method → can’t be overridden • final class → can’t be extended 🔹 finally 👉 Used in exception handling • Block that always executes • Runs whether exception occurs or not Used for cleanup (closing resources, etc.) 🔹 finalize 👉 Method called before garbage collection • Used for cleanup (rarely used now) • Not reliable → generally avoided 🧠 Simple way I remember it 👉 final → restriction 👉 finally → always runs 👉 finalize → cleanup before GC Still learning, but separating these made things much clearer 💡 If you’re learning Java, did this confuse you too? 😄 #Java #Developers #Programming #LearningInPublic #BackendDevelopment
To view or add a comment, sign in
-
-
🚀 Day 49 – Mastering ArrayList Methods in Java Today I focused on one of the most powerful parts of the Java Collections Framework – the ArrayList and its important methods. 📌 Key Learnings: 🔹 Dynamic data structure (resizable array) 🔹 Allows duplicates & maintains insertion order 🔹 Efficient data manipulation using built-in methods 💡 Methods I explored: ✔ add() – Insert elements ✔ add(index, value) – Insert at specific position ✔ addAll() – Merge collections ✔ remove() / removeAll() – Delete elements ✔ retainAll() – Keep common elements ✔ set() – Replace values ✔ get() – Access elements ✔ size() – Count elements ✔ contains() – Search elements ✔ subList() – Extract partial data ✔ clear() – Remove all data ✔ trimToSize() – Optimize memory 🔥 Key Insight: Understanding the difference between add() vs set() is crucial: add() → shifts elements set() → replaces elements 📊 These methods are not just theory — they are heavily used in real-world applications for managing and processing data efficiently. 💭 Takeaway: Mastering ArrayList methods improves problem-solving and builds a strong foundation in Java programming. #Java #ArrayList #CollectionsFramework #Programming #CodingJourney #JavaDeveloper #Learning #Day49
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 14 🔹 Topic: Final Keyword & Static Keyword in Java In Java, final and static are important keywords used to control behavior of variables, methods, and classes. ✅ Final Keyword The final keyword is used to restrict modification. ✔ final variable → value cannot be changed ✔ final method → cannot be overridden ✔ final class → cannot be inherited ✅ Static Keyword The static keyword is used for memory management and sharing data. ✔ Belongs to the class, not objects. ✔ Shared among all objects. ✔ Can be accessed without creating an object. 💡 Key Points: ✔ final → restricts changes ✔ static → shared among all objects #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #JavaFinal #JavaStatic
To view or add a comment, sign in
-
🚀 Mastering TreeSet in Java: Hierarchy & Powerful Methods While diving deeper into the Java Collections Framework, I explored the structure and capabilities of TreeSet—a class that combines sorting, uniqueness, and efficient navigation. 🔷 TreeSet Hierarchy (Understanding the Backbone) The hierarchy of TreeSet is what gives it its powerful features: 👉 TreeSet ⬇️ extends AbstractSet ⬇️ implements NavigableSet ⬇️ extends SortedSet ⬇️ extends Set ⬇️ extends Collection ⬇️ extends Iterable 💡 This layered structure enables TreeSet to support sorted data, navigation operations, and collection behavior seamlessly. 🔷 Important Methods in TreeSet TreeSet provides several methods for efficient data handling and navigation: 📌 Basic Retrieval first() → Returns the first (smallest) element last() → Returns the last (largest) element 📌 Range Operations headSet() → Elements less than a given value tailSet() → Elements greater than or equal to a value subSet() → Elements within a specific range 📌 Removal Operations pollFirst() → Removes and returns first element pollLast() → Removes and returns last element 📌 Navigation Methods ceiling() → Smallest element ≥ given value floor() → Largest element ≤ given value higher() → Element strictly greater than given value lower() → Element strictly less than given value 🔷 When to Use TreeSet? TreeSet is the right choice when you need: ✔️ Sorted Order (automatic ascending order) ✔️ No Duplicate Entries ✔️ Efficient Range-Based Operations ✔️ Navigation through elements (closest matches) 📊 Time Complexity: Insertion → O(log n) Access/Search → O(log n) 💡 Key Insight: TreeSet internally uses a self-balancing tree (Red-Black Tree), which ensures consistent performance and sorted data at all times. 🎯 Understanding TreeSet not only strengthens your knowledge of collections but also helps in solving real-world problems involving sorted and dynamic datasets. #Java #TreeSet #JavaCollections #Programming #DataStructures #LearningJourney 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