💡 Today’s Learning: Method Overloading in Java Today, I explored Method Overloading in more depth! 🚀 Yesterday, I learned that the Java compiler differentiates overloaded methods using: 1️⃣ Number of parameters 2️⃣ Data types of parameters 3️⃣ Sequence of parameters 4️⃣ Check impicit typecasting But today, I discovered one more key factor — 👉 Implicit Typecasting — the compiler also considers it while resolving overloaded methods. However, it can sometimes cause ambiguity in certain cases! ⚠️ I also noticed that several built-in methods in Java are overloaded: substring(int beginIndex) substring(int beginIndex, int endIndex) println() and print() in System.out printf() and format() methods 🧠 Quick Mind Map Recap 🌟 Method Overloading 🌟 │ ┌────────────────────────┼────────────────────────┐ │ │ │ 📘 Definition ⚙️ Compiler Checks 🧩 Built-in Examples │ ├─ Name │ ├─ Same method name ├─ No. of params ├─ println() ├─ Different params ├─ Data types ├─ print() │ ├─ Sequence of params ├─ substring() │ └─ Implicit typecasting └─ printf() │ 💭 Can cause ambiguity if compiler finds multiple matches 💻 Example: class Demo { void show(int a) { System.out.println("Int: " + a); } void show(double a) { System.out.println("Double: " + a); } public static void main(String[] args) { Demo d = new Demo(); d.show(10); // calls show(int) d.show(10.5); // calls show(double) d.show('A'); // implicit typecasting → int → show(int) } } 🔍 Bonus Concept: Can the main() method be overloaded? ✅ Yes! We can overload the main() method in Java. However, the JVM always starts execution from the standard method signature: public static void main(String[] args) If we create another overloaded main() method, JVM won’t call it automatically — we need to call it manually from the original main. Example: class Test { public static void main(String[] args) { System.out.println("Main method with String[] args"); main(10); // Calling overloaded main } public static void main(int a) { System.out.println("Overloaded main with int parameter: " + a); } } 🧩 So, JVM recognizes the main() method by its method signature — public static void main(String[] args) — not just by its name. ✨ Key Takeaway: Method Overloading improves code readability, reusability, and flexibility — a powerful concept in Java’s Object-Oriented Programming! 💪 #Java #OOPs #MethodOverloading #LearningJourney #Programming #CodeEveryday #JavaDeveloper
"Exploring Method Overloading in Java: Implicit Typecasting"
More Relevant Posts
-
🌟 Day 14 of My Java Learning Journey 🔥 💯 Hey everyone! 👋 ~ Today’s topic was all about decision-making in Java — how a program chooses which path to follow based on given conditions. 💡 . I explored how to find the greatest number among multiple values using nested if-else statements, one of the core parts of selection statements in Java. 💻 Here’s the code I worked on today: 👇 -------------------------------------code start-------------------------------------- public class FindGreaterNumberDemo2 { public static void main(String[] args) { int p = 11; int q = 22; int r = 33; int s = 44; if (p > r && p > s && p > q) { System.out.println("p is greater number "); } else if (q > s && q > p && q > r) { System.out.println("q is greater number"); } else if (r > p && r > s && r > q) { System.out.println("r is greater number"); } else { System.out.println("s is greater number"); } } } -------------------------------------code output------------------------------------ s is greater number ---------------------------------------code end-------------------------------------- . 🔍 Explanation: We have four integer variables: p, q, r, and s. Using an if-else-if ladder, we compare each number with the others using the logical AND (&&) operator. The first condition that turns out true will print which number is the greatest. If none of them match, the else block executes, showing that s is the greatest. . 💡 Key Takeaway: Selection statements like if, else if, and else help control the program’s logic — deciding what happens next depending on the condition. . 🚀 What’s next? In the upcoming posts, I’ll share many more real-world examples related to selection statements, so we can deeply understand how decision-making works in Java programs. Stay tuned — it’s gonna get crazy cool and more practical! 💻🔥 . #Java #100DaysOfCode #Day14 #JavaLearningJourney #FlowControl #IfElse #SelectionStatements #DevOps #Programming #CodingJourney #LearnJava #TechLearner #CodeNewbie .
To view or add a comment, sign in
-
-
🚀 Java Learning Series — Day 3 Topic: Exception and Its Types ☕ When we write a program, things don’t always go as planned Right??? Java gives us "Exceptions" — Special ways to handle those unexpected Bugs so our code doesn’t crash suddenly. ------------------------------------- 💡 Definition: An Exception is like a signal that something went wrong during program execution. Instead of stopping everything, Java lets us catch and handle it. ------------------------------------- ✅ Dont miss to read the Interview questions from this Topic in the end 💀😋 ------------------------------------- 🧩 Types of Exceptions: 1. CHECKED EXCEPTIONS → Problems Java expects you to handle before running (e.g., reading a missing file). ----Must fix---- 2. UNCHECKED EXCEPTIONS → Problems that happen while running (e.g., dividing by zero). 3. ERRORS (Bugs) → Serious system-level problems (e.g., memory full, system crash). ------------------------------------- 🧠 Simple Example: class ExceptionTypesStory { public static void main(String[] args) { try { int apples = 5; int kids = 0; int eachGets = apples / kids; // Oops! Unchecked exception System.out.println("Each kid gets: " + eachGets); } catch (ArithmeticException e) { System.out.println("Oops! Can't divide apples by zero kids."); } //See here how I handled the error 👇🏃 try { Thread.sleep(500); // Checked exception } catch (InterruptedException e) { System.out.println("Someone woke me up too early!"); } System.out.println("###_Story_over_###"); //Everything handled 😜smoothly } } ------------------------------------- ⚙️ Real-World Connections: 1. Online Shopping App– Item goes out of stock → Exception handled, shows “Out of Stock” instead of crashing. 2. Bank App – Network drops during payment → Checked exception, retried safely. 3. Music Player – Song file missing → Checked exception handled, plays next song. 5. Web Browser – Out of memory loading heavy tabs → Error, can’t recover easily. ------------------------------------- 🔥 Interview-Style Quick Questions — Exceptions in Java 1️⃣ What is the difference between Checked and Unchecked Exceptions? 2️⃣ Can we handle Errors using try-catch? If not, why? 3️⃣ Is it mandatory to handle Checked Exceptions? 4️⃣ What happens if you don’t handle an Unchecked Exception? 5️⃣ Can a single catch block handle multiple exceptions? 6️⃣ What is the parent class of all exceptions in Java? 7️⃣ What happens if you put finally block before catch? 8️⃣ Can we have a try block without catch? 9️⃣ What’s the difference between throw and throws in exception context? 🔟 Why is Exception Handling important in large-scale applications? #Java #100DaysOfJava #CodingJourney #ExceptionHandling #SoftwareEngineer #SoftwareEngineering #LearningNeverStops #MERNtoJavaJourney
To view or add a comment, sign in
-
-
💻 Day 11 of My Java Learning Journey 💯 ~ Understanding Short-Circuit Operators in Java (&& and ||) Today, I explored an important concept in Java: Short-Circuit Operators — && (AND) and || (OR). These operators help in making conditional statements more efficient by controlling how expressions are evaluated. 🔹 What Are Short-Circuit Operators? Short-circuiting means that Java stops evaluating further conditions once the result is determined. && (AND Operator): → If the first condition is false, the second condition is not evaluated. → Used when both conditions must be true. || (OR Operator): → If the first condition is true, the second condition is not evaluated. → Used when only one condition needs to be true. 🧩 Code Example -------------------------------------code start-------------------------------------- public class ShortCircuitDemo { public static void main(String[] args) { // && operator examples int x = 15, y = 12; if (--x >= 14 && --y <= 12) { --x; } else { --y; } System.out.println("x = " + x + " y = " + y); int p = 15, q = 12; if (--p >= 15 && --q <= 10) { --p; } else { --q; } System.out.println("p = " + p + " q = " + q); // || operator examples int a = 10, b = 5; if (++a >= 10 || ++b <= 5) { ++a; } else { ++b; } System.out.println("a = " + a + " b = " + b); int n = 8, m = 3; if (++n >= 10 || ++m <= 2) { ++n; } else { ++m; } System.out.println("n = " + n + " m = " + m); } } -------------------------------------code output-------------------------------------- x = 13 y = 11 p = 14 q = 11 a = 12 b = 5 n = 9 m = 4 -------------------------------------code end-------------------------------------- 💡 Key Takeaways && → If the first condition is false, the second is skipped. || → If the first condition is true, the second is skipped. Helps in optimizing code execution and avoiding unnecessary evaluations. Learning these small but impactful details helps me write smarter and more efficient Java code every day. 🚀 #Day11 #JavaLearning #ShortCircuitOperators #LogicalOperators #100DaysOfCode #JavaDevelopment #ProgrammingConcepts #DevOps #CodingJourney #YuviLearnsJava
To view or add a comment, sign in
-
-
I recently started learning Java. And learning it after Python feels like learning to drive manual after automatic 😅 Here's my roadmap and what I'm discovering at each stage: 1️⃣ Basic (Week 1-2) - Syntax & Variables, Data Types, Control Flow, Loops, Arrays. - I'm realising Java's strictness teaches discipline Python let me skip. - 𝘍𝘪𝘳𝘴𝘵 𝘴𝘵𝘳𝘶𝘨𝘨𝘭𝘦: Remembering semicolons and type declarations everywhere. 2️⃣ OOPs (Week 3-4) - Classes & Objects, Inheritance, Polymorphism, Abstraction, Encapsulation. - Everything MUST be in a class - no shortcuts. - Forces you to think in objects from day one. - Understanding why Java is called "𝘱𝘶𝘳𝘦𝘭𝘺 𝘰𝘣𝘫𝘦𝘤𝘵-𝘰𝘳𝘪𝘦𝘯𝘵𝘦𝘥" compared to Python's hybrid approach. 3️⃣ Collections (Week 5) - List, Set, Map, Generics, Iterators. - ArrayList vs LinkedList isn't just preference - it's understanding when fast access beats fast insertion. 4️⃣ Exception Handling (Week 6) - Try-Catch, Throw & Throws, Custom Exceptions. - Learning when to catch exceptions vs when to throw them. - Exception handling separates amateur code from production-ready code. 5️⃣ File I/O (Week 7) - FileReader/Writer, BufferedReader/Writer, Serialization. - Reading and writing files efficiently. Buffered I/O is significantly faster than basic I/O - matters at scale. - Serialization lets you save object states - crucial for real applications. 6️⃣ Multithreading (Week 8-9) - Thread & Runnable, Synchronization, Executors. - Mind-bending but powerful. Making programs do multiple things simultaneously without breaking. - 𝘏𝘢𝘳𝘥𝘦𝘴𝘵 𝘱𝘢𝘳𝘵 𝘴𝘰 𝘧𝘢𝘳: Understanding thread safety and avoiding race conditions. 7️⃣ Java 8+ (Week 10) - Lambda, Stream API, Functional Interfaces, Date & Time API. - Modern Java feels cleaner. Lambdas reduce boilerplate, Streams make data processing elegant. - This is where Java catches up to modern programming paradigms. 8️⃣ JDBC (Week 11) - Connection, Statements, Transactions. - Connecting Java to databases. Every backend application needs this. - Learning to write clean database code that doesn't leak connections or crash under load. 9️⃣ Frameworks (Week 12-14) - Spring Boot, Hibernate, Maven/Gradle. - The real world runs on frameworks. Spring Boot powers enterprise applications globally. - This is where Java's verbose nature pays off - frameworks handle the boilerplate. 🔟 Web Dev (Week 15-16) - Servlets & JSP, REST API, Spring MVC. - Building actual web applications. RESTful APIs are how modern apps communicate. - 𝘎𝘰𝘢𝘭: Build a complete backend system that can handle real traffic. 😥 Why am I learning Java when Python dominates AI? Enterprise systems run on Java. Python gets you started, Java gets you scale. Where are you in your Java journey? What's tripping you up? 👇 Follow Arijit Ghosh for daily shares and my learning journeys #Java #roadmap #programming
To view or add a comment, sign in
-
-
Java Developers! Your Ultimate Cheat Sheet is Here Whether you’re revising for interviews or writing production-grade code, remembering all Java keywords can be tricky. Here’s a quick reference guide that covers everything 1️⃣ Data Types: int, double, char, boolean, var 2️⃣ Control Flow: if, for, while, switch, yield 3️⃣ OOP Concepts: class, interface, extends, implements, super, this 4️⃣ Access Modifiers: public, private, protected 5️⃣ Exception Handling: try, catch, finally, throw, throws 6️⃣ Threads: synchronized, volatile 7️⃣ Modules (Java 9+): module, exports, requires, open 8️⃣ Sealed Classes (Java 17+): sealed, non-sealed, permits 9️⃣ Others: return, void, static, transient, assert, enum A must-have for every Java learner and developer who wants to code efficiently! Which section do you find most challenging to memorize? Free Courses you will regret not taking in 2025 👇 1. Python for Data Science, AI & Development https://lnkd.in/dU86J2eh 2. Crash Course on Python https://lnkd.in/dwBEaw4j 3. Python for Everybody https://lnkd.in/dERUNTkr 4. Data Analysis with Python https://lnkd.in/dCkR_UFW 5. Python 3 Programming Specialization https://lnkd.in/dbrtiZq9 6. Programming for Everybody https://lnkd.in/dPHeFia5 7. IBM Generative AI Engineering https://lnkd.in/dfwgQMkc 8. IBM AI Developer https://lnkd.in/drxG_Shn 9. Machine Learning Specialization https://lnkd.in/dX8DPYZd 10. AI For Everyone https://lnkd.in/dyuata4J 11. Artificial Intelligence (AI) https://lnkd.in/dX5XRi2N 12. Google Data Analytics https://lnkd.in/dvP__MU2 13. Google Cybersecurity https://lnkd.in/db6_ymtp 14. Google Project Management https://lnkd.in/dupKAyBF 15. Prompt Engineering Specialization https://lnkd.in/dBDur4fZ 16. IBM Data Science https://lnkd.in/dGPXtRm3 17. SQL https://lnkd.in/dPaRaeaB 18. Microsoft Cybersecurity Analyst https://lnkd.in/dFiSUbDm 19. Programming with Python and Java Specialization https://lnkd.in/d2JKYqnw 20. Statistics with Python Specialization https://lnkd.in/d8274rHu 21. AI Python for Beginners https://lnkd.in/dQycfi68 Follow Java Assignment Helper for more #Java #Programming #Developers #SoftwareEngineering #Coding #TechLearning #OOP #CodeWithJava #JavaDeveloper
To view or add a comment, sign in
-
-
⭐💻 Star Pattern Programs in Java 🚀 Learning Java becomes even more fun when you practice pattern programs! These Star Pattern Programs are a great way to improve your logic building, loop control, and problem-solving skills. ✅ Covers: • Basic to Advanced Star Patterns • Pyramid, Triangle & Diamond Patterns • Number & Character Patterns • Logical Thinking with Nested Loops 🎯 Perfect For: • Beginners learning Java fundamentals 🎓 • Students preparing for coding interviews 💼 • Developers improving logic-building & problem-solving skills ⚡ Start practicing these patterns today and build a solid foundation in Java programming! 👉 2000+ free courses free access https://lnkd.in/eSRBi64n 𝐅𝐫𝐞𝐞 𝐆𝐨𝐨𝐠𝐥𝐞 & 𝐈𝐁𝐌 𝐂𝐨𝐮𝐫𝐬𝐞𝐬 𝐢𝐧 𝟐𝟎𝟐6, 𝐃𝐨𝐧’𝐭 𝐌𝐢𝐬𝐬 𝐎𝐮𝐭 𝐨𝐫 𝐘𝐨𝐮’𝐥𝐥 𝐑𝐞𝐠𝐫𝐞𝐭 𝐈𝐭 𝐋𝐚𝐭𝐞𝐫! Introduction to Generative AI: https://lnkd.in/enQETEtu Google AI Specialization https://lnkd.in/ezYU6P3b Google Prompting Essentials Specialization: https://lnkd.in/eCAb5m3j Crash Course for Python https://lnkd.in/eNPZE74F Google Cloud Fundamentals https://lnkd.in/eMbczkqy IBM Python for Data Science https://lnkd.in/eCYYhCte IBM Full Stack Software Developer https://lnkd.in/eegYi7ya IBM Introduction to Web Development with HTML, CSS, JavaScript https://lnkd.in/eFs_bbRa IBM Back-End Development https://lnkd.in/ebiZfsM2 Full Stack Developer https://lnkd.in/eYy5bZKA Data Structures and Algorithms (DSA) https://lnkd.in/e7EMvayd Machine Learning https://lnkd.in/eNKpDUGN Deep Learning https://lnkd.in/ebDwXb24 Python for Data Science https://lnkd.in/e-csZZsf Web Developers https://lnkd.in/ezHuwkdR Java Programming https://lnkd.in/eQpQCmb8 Cloud Computing https://lnkd.in/ezQg7fN7
To view or add a comment, sign in
-
💡 My Java Journey: Understanding Encapsulation, Inheritance, Polymorphism & Abstraction When I first heard these four words — Encapsulation, Inheritance, Polymorphism, and Abstraction — I honestly thought Java was trying to speak another language 😅 They sounded complex and intimidating… But once I truly understood them, they changed how I think about writing clean, reusable, and scalable code. Here’s how I break them down 👇 🔒 Encapsulation The concept that taught me: “Protect your data, don’t expose it unnecessarily.” Encapsulation is all about binding data and methods together inside a single unit (class), and controlling access through getters/setters. Example: public class Employee { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } } ✅ Keeps your variables safe from accidental modification. ✅ Promotes modular, maintainable code. Think of it as data hiding with discipline. 🧬 Inheritance This one blew my mind when I realized how powerful code reusability could be. Inheritance means one class can acquire properties and behaviors of another class. Example: class Animal { void eat() { System.out.println("eating..."); } } class Dog extends Animal { void bark() { System.out.println("barking..."); } } ✅ Dog automatically inherits eat() from Animal. ✅ Avoids code duplication — and keeps your code DRY. It’s like saying: “Why reinvent the wheel when you can extend it?” 😎 🔁 Polymorphism A fancy word that simply means — one action, many forms. There are two main types: Compile-time (Method Overloading) Runtime (Method Overriding) Example: class Shape { void draw() { System.out.println("Drawing shape"); } } class Circle extends Shape { void draw() { System.out.println("Drawing circle"); } } ✅ The same method name behaves differently depending on the object type. That’s the beauty of dynamic behavior in Java. 🧠 Abstraction Abstraction taught me to focus on what the code does, not how it does it. Example: abstract class Vehicle { abstract void start(); } class Car extends Vehicle { void start() { System.out.println("Car starts with a key"); } } ✅ You define the “idea” in the abstract class. ✅ Concrete classes bring those ideas to life. Abstraction = Hiding complexity, showing functionality. 💬 My Takeaway ConceptWhat It TeachesEncapsulationKeep data safe & structuredInheritanceReuse code smartlyPolymorphismWrite flexible & dynamic codeAbstractionSimplify complex systems Understanding these four pillars changed the way I design every class and method. They’re not just OOP concepts — they’re principles of good software thinking. 💻✨ 💬 Your Turn: Which OOP concept took you the longest to truly understand — and how did you finally “get it”? Share your story 👇 — let’s learn from each other!
To view or add a comment, sign in
-
🚀 Day 9 of Learning OOPs in Java — Final Keyword 🌟 Hello Connections! Today, I learned about one of the most important non-access modifiers in Java — the final keyword. -> It helps make programs more secure, stable, and immutable. 🧠 Definition of final Keyword -> The final keyword in Java is used to restrict modifications. -> Once something is declared as final, it cannot be changed, overridden, or inherited, depending on whether it’s applied to a variable, method, or class. 1️⃣ final Keyword for Variables -> Variables can be static (class-level) or non-static (object-level). -> When declared as final, their values cannot be reassigned after initialization. 👉 Non-static final variable: -> Belongs to the object. -> Value can be assigned only once — either at declaration, inside a constructor, or within a non-static block. Syntax: final dataType variableName = value; 👉 Static final variable: -> Belongs to the class and is shared among all objects. -> Value must be assigned once — either at declaration or inside a static block. Syntax: static final dataType VARIABLE_NAME = value; 2️⃣ final Keyword for Methods -> The final keyword when used with methods restrict overriding in subclasses, ensuring the same method behavior across the hierarchy. 👉 Non-static final method: -> Belongs to the object. -> Can be overloaded but not overridden. Syntax: final returnType methodName(parameters) { } 👉 Static final method: -> Belongs to the class. -> Since static methods can’t be overridden, making them final adds an extra layer of protection. Syntax: static final returnType methodName(parameters) { } 3️⃣ final Keyword for Classes -> A final class cannot be inherited. -> A class declared as final cannot be extended by any subclass. 👉 Non-static final class: -> Commonly used to create a sealed class that cannot be extended. -> Acts as the last subclass in the hierarchy. Syntax: final class ClassName { } 👉 Static final class: -> Top-level classes cannot be static. -> Nested inner classes can be declared as static and final. Syntax: static final class InnerClassName { } ⚠️ Important Note: -> final and abstract cannot be used together — because abstract means "to be extended", while final means "cannot be extended". 💡 Quick Summary: -> final restricts modification — -> final variables can’t change, -> final methods can’t be overridden, -> final classes can’t be inherited. 📂 Source Code:https://lnkd.in/gyw98FUR #Day9 #Java #OOPs #LearningJourney #FinalKeyword #Programming #JavaDeveloper #CodeWithUpendra #100DaysOfCode #LearnJava 10000 Coders
To view or add a comment, sign in
-
-
🚀 Launching GPT-OSS Java: Pure Java LLM Inference in ~1000 Lines Excited to share my latest open-source project - a complete Java port of OpenAI's gpt-oss inference engine running on CPU, now available on https://lnkd.in/gzCXk-pH! 🎯 Key features: • 📚 Educational - Clean, readable code for understanding LLM Transformer internals • 🏗️ Complete gpt-oss architecture - Full implementation of MoE transformer with GQA, sliding window attention, RoPE, and SwiGLU • 💻 CPU inference - No GPU required, designed for consumer-grade commodity hardware on local machines or cloud compute instances • 🧠 Memory efficient - Runs gpt-oss-20b models on CPU with just 16GB RAM • ⚡ Performance optimized - Support KVCache and exploit modern JDK GC/JIT, parallel processing, SIMD Vector API, and fused operations • 🔢 MXFP4 dequantization - Handles original MXFP4 quantized MoE weights 📊 Performance highlights: • ~11 tokens/sec on Apple M3 Pro (12 CPUs, 36GB) • ~10 tokens/sec on AWS EC2 m5.4xlarge (8 physical cores, 16 vCPUs, 64GB) Inspired by llama.cpp and llama2.c, this project demonstrates that Java can achieve impressive performance for LLM inference when properly optimized. Check it out: https://lnkd.in/gzCXk-pH
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