🚀 Starting My Java Learning Journey – Day 9 🔹 Topic: Method Overloading in Java Method Overloading is a feature in Java that allows a class to have multiple methods with the same name but different parameters. It helps improve code readability and flexibility. 📌 Ways to Achieve Method Overloading 1️⃣ Different number of parameters 2️⃣ Different data types of parameters 📌 Example Program public class Main { // Method with two int parameters static int add(int a, int b) { return a + b; } // Method with three int parameters static int add(int a, int b, int c) { return a + b + c; } public static void main(String[] args) { System.out.println(add(5, 10)); System.out.println(add(5, 10, 15)); } } Output: 15 30 💡 Key Points: ✔ Method overloading allows multiple methods with the same name ✔ Methods must differ in number or type of parameters ✔ Helps make programs more flexible and readable #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #MethodOverloading
Java Method Overloading Explained
More Relevant Posts
-
📘 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
-
-
🚀 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
-
🚀 Starting My Java Learning Journey – Day 13 ♦Topic: Exception Handling in Java Exception Handling is used to handle runtime errors so that the program does not crash abruptly. It helps in maintaining the normal flow of the program. ✅ Types of Exceptions 1)Checked Exceptions → Checked at compile time 2) Unchecked Exceptions → Occur at runtime ✅ Keywords Used in Exception Handling ✔ try → block where code is written ✔ catch → handles the exception ✔ finally → always executes (optional) ✔ throw → used to explicitly throw an exception ✔ throws → declares exceptions ✅ Example Program public class Main { public static void main(String[] args) { try { int result = 10 / 0; // may cause exception System.out.println(result); } catch (ArithmeticException e) { System.out.println("Cannot divide by zero"); } finally { System.out.println("Execution completed"); } } } Output: Cannot divide by zero Execution completed 💡 Key Points: ✔ Prevents program crash ✔ Helps handle runtime errors ✔ Improves program reliability #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #ExceptionHandling
To view or add a comment, sign in
-
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
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
-
🚀 Day 16 of My Java Learning Journey Today, I explored one of the most important OOP concepts in Java — Constructors 🔥 🔹 What I Learned: • Constructor is a special method used to initialize objects • It has the same name as the class • No return type (not even void) • Automatically called when object is created 🔹 Types of Constructors: • Default Constructor • Parameterized Constructor 💡 Key Insight: Java does not have a built-in copy constructor like C++, but we can create it manually if needed. 🧠 Realization: Constructors make object creation more structured and efficient — they are like the “starting point” of any object in Java. Consistency + Practice = Growth my mentor Aman Soni Vidhya Code Gurukul #Java #OOP #Programming #LearningJourney #CodeNewbie #100DaysOfCode #Developers #TechSkills
To view or add a comment, sign in
-
-
🚀 Day 3 of My Java Learning Journey – Control Statements in Java Today, I learned how programs make decisions and repeat tasks using Control Statements in Java. These are essential for building logic in real-world applications. 🔹 Types of Control Statements: ➤ 1. if-else Statement Used for decision making 👉 Executes code based on conditions if (x > 10) { System.out.println("Greater than 10"); } else { System.out.println("Less than or equal to 10"); } ➤ 2. switch Statement Used when we have multiple choices 👉 Cleaner alternative to multiple if-else switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; default: System.out.println("Invalid day"); } ➤ 3. Loops (Repetition Statements) Used to execute code multiple times ✔ for loop – when number of iterations is known ✔ while loop – when condition is checked before execution ✔ do-while loop – executes at least once for(int i = 1; i <= 5; i++) { System.out.println(i); } 💡 Key Learning: Control statements help in decision-making and repeating tasks, making programs smarter and more dynamic. 📌 Practiced writing programs using if-else, switch, and loops to strengthen my logic-building skills. #Java #Programming #CodingJourney #LearningJava #ControlStatements #100DaysOfCode #Developers 🚀
To view or add a comment, sign in
-
🚀 Day 7 of My Java Learning Journey Today I learned about Control Flow Statements in Java, focusing on Conditional Statements. 📌 These statements help control the flow of execution based on conditions. 🔹 Types of Conditional Statements I Covered: 🔸 1. if Statement Executes code only if condition is true 🔸 2. if-else Statement Executes one block if true, another if false 🔸 3. else-if Ladder Used to check multiple conditions 🔸 4. Nested if if statement inside another if 💡 Example: int marks = 75; if(marks >= 80){ System.out.println("Excellent"); } else if(marks >= 50){ System.out.println("Pass"); } else { System.out.println("Fail"); } Understanding these concepts is very important for building logic in real-world applications. Building consistency step by step 💪 🔗 Check my code here: https://lnkd.in/gDP4A9r6 If you are also learning Java, let’s connect and grow together 🤝 #Java #JavaDeveloper #Programming #CodingJourney #LearningInPublic #SoftwareDevelopment
To view or add a comment, sign in
-
-
Day 28 -What I Learned in a Day(JAVA) Today I started learning Looping Statements in Java. Loops are used to execute a block of code repeatedly until a certain condition becomes false. They help reduce code repetition and make programs more efficient. In Java, there are mainly three types of loops: • while loop • do-while loop • for loop Today I focused on the while loop. 🔹 What is a While Loop? A while loop executes a block of code repeatedly as long as the condition is true. The condition is checked before the loop executes, so if the condition is false initially, the loop will not run. Syntax of While Loop: initialization; while(condition) { // statements increment / decrement; } What I Practiced Today: ✔ Practiced 3 basic while loop programs ✔ Built a calculator program using while loop and switch statement ✔ Learned how loops control program flow and reduce repetitive code Every day I’m taking small steps to improve my Java programming skills and strengthen my understanding of core concepts. Practiced 👇 #Java #JavaLearning #Programming #CodingJourney #Loops #WhileLoop
To view or add a comment, sign in
-
🚀 Day 29 | Core Java Learning Journey 📌 Topic: TreeSet in Java Today, I learned about TreeSet, an important class in the Java Collections Framework used when we need sorted and unique elements. 🔹 TreeSet in Java ✔ TreeSet is a class that implements NavigableSet ✔ It also indirectly implements SortedSet and Set ✔ Introduced in JDK 1.2 ✔ Stores unique elements only (no duplicates allowed) 🔹 Data Structure Used ✔ Based on Self-Balancing Binary Search Tree (Red-Black Tree) ❗ (important correction) ✔ Elements are stored in sorted order 🔹 Key Features ✔ Does NOT follow insertion order ✔ Follows natural sorting order (default) ✔ Allows custom sorting using Comparator ✔ Does NOT allow null elements ❌ ✔ Stores homogeneous data (same type, for proper comparison) 📌 Important Methods • add() – add element • remove() – delete element • contains() – check element • first() – returns first (smallest) element • last() – returns last (largest) element • higher() – next greater element • lower() – next smaller element 📌 Performance ✔ Operations like add, remove, search → O(log n) 📌 When to Use TreeSet? ✔ When you need: ✅ Sorted data ✅ Unique elements ✅ Range-based operations 💡 Note: Unlike HashSet, TreeSet focuses on sorting rather than speed. 🙏 Special thanks to Vaibhav Barde Sir for the guidance! 🔥 #CoreJava #JavaLearning #JavaDeveloper #TreeSet #SortedSet #NavigableSet #JavaCollections #Programming #LearningJourney
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