📘 Core Java – Method Overloading Method Overloading allows multiple methods with the same name but different parameters in the same class. ✅️It also known as compile-time polymorphism ✅️It improves code readability and flexibility. 🔷️Different ways to Overload a Method 🔸️1.by changing number of arguments 🔸️2.by changing the data type ▪️🔸️1.by changing number of arguments: “Method overloading in Java can be achieved by changing the number of arguments. When methods have the same name but a different number of parameters, the compiler decides which method to call at compile time.” ▪️🔸️2.by changing the data type: “Method overloading can be achieved by changing the data type of parameters. When methods have the same name but different parameter data types, the compiler selects the appropriate method.” #Java #CoreJava #OOP #MethodOverloading #LearningJourney
Java Method Overloading Explained
More Relevant Posts
-
Constructors in Java : • A Constructor is a special method used to initialize objects. • It has the same name as the class and no return type. • Constructors are called automatically when an object is created. Types of Constructors in Java: 1. Default Constructor • Has no parameters. • Initializes objects with default values. • Provided by the compiler if no constructor is defined. 2. Parameterized Constructor • Accepts parameters. • Used to initialize objects with specific values. • Helps in setting data at the time of object creation. 3. Private Constructor • Declared using the private keyword. • Restricts object creation outside the class. • Commonly used in Singleton design pattern. 4. Copy Constructor • Initializes an object using another object of the same class. • Used to copy values from one object to another. • Achieved by passing an object as a parameter. #Java #ConstructorsInJava #OOP #JavaBasics #FullStackJava
To view or add a comment, sign in
-
-
🚀 Array in Java – Quick Concept An Array in Java is a data structure used to store multiple values of the same data type in a single variable. Instead of creating many variables, arrays help keep code clean, fast, and organized. 🔹 Why use Arrays? ✅ Store multiple values efficiently ✅ Easy access using index ✅ Improves code readability ✅ Saves memory Arrays are the foundation for mastering data structures and writing optimized Java programs 💡 #Java #JavaProgramming #Arrays #CodingJourney #LearnJava #DeveloperLife 💻✨
To view or add a comment, sign in
-
🚀 Array in Java – Quick Concept An Array in Java is a data structure used to store multiple values of the same data type in a single variable. Instead of creating many variables, arrays help keep code clean, fast, and organized. 🔹 Why use Arrays? ✅ Store multiple values efficiently ✅ Easy access using index ✅ Improves code readability ✅ Saves memory Arrays are the foundation for mastering data structures and writing optimized Java programs 💡 #Java #JavaProgramming #Arrays #CodingJourney #LearnJava #DeveloperLife 💻✨
To view or add a comment, sign in
-
🚀 Array in Java – Quick Concept An Array in Java is a data structure used to store multiple values of the same data type in a single variable. Instead of creating many variables, arrays help keep code clean, fast, and organized. 🔹 Why use Arrays? ✅ Store multiple values efficiently ✅ Easy access using index ✅ Improves code readability ✅ Saves memory Arrays are the foundation for mastering data structures and writing optimized Java programs 💡 #Java #JavaProgramming #Arrays #CodingJourney #LearnJava #DeveloperLife 💻✨
To view or add a comment, sign in
-
Practiced the boolean data type in Java. At first, I didn’t think much about it, then I realized Java is very strict about conditions. This works: boolean flag = true; if (flag) { System.out.println("Runs"); // output: Runs } But this doesn’t: int x = 1; if (x) { System.out.println("Runs"); // compile-time error } Java doesn’t allow assumptions here. Conditions must be explicitly boolean nothing else. Still learning the basics and understanding why the rules exist. #Java #LearningInPublic #Beginner #DSA
To view or add a comment, sign in
-
💻 Memory Leak in Java – A Silent Performance Killer Memory leaks in Java don’t happen because GC fails — they happen because objects are still strongly referenced and never become eligible for garbage collection. 🔎 What happens? Heap memory keeps increasing → Full GC runs → Memory doesn’t drop → Eventually leads to OutOfMemoryError. ⚠️ Common Causes: ✔ Static collections holding objects ✔ Unclosed DB connections / streams ✔ ThreadLocal not removed ✔ Unbounded caches ✔ Listeners not deregistered 🛠 How to Identify: ✅ Monitor heap using JConsole / VisualVM ✅ Take heap dump using jmap ✅ Analyze in Eclipse MAT → Check Dominator Tree & GC Roots 💡 Remember: Garbage Collector removes unused objects — But it cannot remove objects you are still referencing. Performance is not just about writing code. It’s about writing memory-efficient code. #Java #MemoryLeak #GarbageCollection #JavaDeveloper #BackendDevelopment #InterviewPreparation 🚀
To view or add a comment, sign in
-
-
📌 Race Condition in Java A race condition occurs when multiple threads access and modify shared data at the same time, leading to inconsistent results. 1️⃣ Why Race Condition Happens • Shared mutable state • Multiple threads running concurrently • Lack of proper synchronization 2️⃣ Simple Example Two threads updating the same variable can overwrite each other’s changes, causing unexpected output. 3️⃣ Symptoms of Race Condition • Incorrect results • Non-deterministic behavior • Bugs that are hard to reproduce • Works sometimes, fails sometimes 4️⃣ Why It Is Dangerous • Breaks data consistency • Causes unpredictable application behavior • Difficult to debug and test 5️⃣ How Java Addresses This Java provides mechanisms like: • synchronized keyword • Locks • Atomic classes These ensure only one thread accesses critical sections at a time. 🧠 Key Takeaway Race conditions are not syntax errors. They are logical concurrency bugs. Understanding race conditions is the first step toward writing thread-safe Java code. #Java #Multithreading #Concurrency #ThreadSafety #BackendDevelopment
To view or add a comment, sign in
-
Java Array A data structure that stores multiple values of the same data type in a single variable. Arrays Class A utility class in Java that provides methods to perform operations on arrays such as sorting and searching. String A class used to represent a sequence of characters in Java; String objects are immutable. String Methods Predefined methods used to manipulate and retrieve information from String objects. StringBuffer and StringBuilder Classes used to create mutable strings; StringBuffer is thread-safe, while StringBuilder is faster but not thread-safe. Immutable and Mutable Immutable objects cannot be changed after creation, while mutable objects can be modified. Exception Handling A mechanism to handle runtime errors and maintain the normal flow of program execution. Shallow Copy and Deep Copy Shallow copy copies object references, while deep copy creates a new independent object. File Handling A process of creating, reading, writing, and deleting files in Java. Multithreading A feature that allows multiple threads to execute concurrently within a program. Synchronization A mechanism used to control access to shared resources in a multithreaded environment. Interthread Communication A technique that allows threads to communicate with each other during execution. Deadlock A situation where two or more threads wait indefinitely for each other’s resources. Daemon Thread A background thread that runs to support user threads and terminates when they finish. Inner Class A class defined inside another class to logically group related classes. Object Class The root superclass of all Java classes from which every class implicitly inherits. pdf Link :- https://lnkd.in/gXEWSAJ2 #Java #CoreJava #JavaDeveloper #JavaInterview #ProgrammingBasics #SoftwareDevelopment #LearnJava #StudentDeveloper #TechLearning
To view or add a comment, sign in
-
-
Understanding how Java handles memory is key to writing efficient, scalable applications. Here’s a concise breakdown of core concepts: 🗑️ What is Java Garbage Collection (GC) & How It Works GC is JVM’s automatic memory management process. It identifies and removes objects no longer referenced by the application, reclaiming heap memory. Works mainly via a reachability analysis starting from “GC Roots.” 🔄 Different Garbage Collection Algorithms Common algorithms in HotSpot JVM: • Serial GC: Single-threaded, for small apps. • Parallel/Throughput GC: Multi-threaded, maximizes throughput. • CMS (Concurrent Mark Sweep): Minimizes pause times (now deprecated). • G1 (Garbage First): Balanced throughput & latency for larger heaps. • ZGC & Shenandoah: Ultra-low pause times, scalable. 🔍 What is a Memory Leak in Java & How to Detect It A memory leak occurs when objects are no longer needed but still referenced, preventing GC. Common causes: static collections, unclosed resources, listeners. Detection tools: · jconsole / VisualVM · Heap dump analysis with Eclipse MAT or jhat · Profilers (YourKit, JProfiler) 📌 Soft, Weak, & Phantom References Explained · SoftReference: Objects cleared when memory is low. Good for caches. · WeakReference: GC collects eagerly; useful for canonical mappings (e.g., WeakHashMap). · PhantomReference: Enables post-mortem cleanup actions, accessed only via reference queues. 💬 Q&A Q: Which GC should I choose for a low-latency web service? A: For modern applications, G1 is a reliable default. For very large heaps and strict low-latency requirements (pause times < 10ms), consider ZGC or Shenandoah. Q: Can GC completely prevent memory leaks? A: No. GC only collects unreachable objects. If you unintentionally retain references (e.g., in a static Map), it’s a logical leak—GC can’t help. Regular profiling is essential. Q: When would I use a PhantomReference? A: Primarily for safer native resource cleanup or post-finalization logging, as they offer more control than finalizers. #Java #MemoryManagement #GarbageCollection #Performance #SoftwareEngineering #JVM
To view or add a comment, sign in
-
It’s easy to forget how much chaos Java had before generics… until you look at code that still relies on raw types. Once you see how type parameters actually shape safety and structure in collections, it becomes obvious why this feature changed everything. If you want a clean walkthrough of the fundamentals that many devs gloss over, this article lays it out clearly. https://bit.ly/4rlvIbG
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