Interfaces also allow a class to follow multiple contracts at the same time. Unlike classes, where a class can extend only one parent class, a class in Java can implement multiple interfaces. Things that became clear : • a class can implement more than one interface • each interface can define a different set of behaviours • the implementing class must provide implementations for all the methods • this approach allows combining different capabilities in a single class • it helps achieve flexibility while avoiding multiple inheritance of classes A simple example shows how multiple interfaces can be implemented : interface ICalculator { void add(int a, int b); void sub(int a, int b); } interface IAdvancedCalculator { void mul(int a, int b); void div(int a, int b); } class CalculatorImpl implements ICalculator, IAdvancedCalculator { public void add(int a, int b) { System.out.println(a + b); } public void sub(int a, int b) { System.out.println(a - b); } public void mul(int a, int b) { System.out.println(a * b); } public void div(int a, int b) { System.out.println(a / b); } } This structure allows the class to support operations defined by multiple interfaces while keeping responsibilities organized. #java #oop #programming #learning #dsajourney
Lakhyadeep Sen’s Post
More Relevant Posts
-
Refactoring for Clarity: Array Manipulation in Java 👨💻 I’ve just finished a practical exercise on array manipulation. While the goal was simple (summing two arrays), I used it as an opportunity to apply improvements. - Method decomposition: Separated concerns into specialized methods (Read, Calculate, Display). - Input validation: Built a robust loop to handle invalid inputs and prevent crashes. - Data Formatting: Used printf to create a clear, readable results table. Small improvements in logic and organization make a huge difference in software quality. #Java #Algorithms #CleanCode #Backend #LearningToCode
To view or add a comment, sign in
-
-
🔄 Java Multithreading I’ve used thread.start() a hundred times — but never stopped to think what actually happens next. 🤔 Threads in Java go through a few states — and understanding them makes debugging so much easier. Here’s the quick flow 👇 NEW → When you create a thread object but haven’t started it yet. Thread t = new Thread(() -> {}); RUNNABLE → After calling start(). It’s ready to run, waiting for CPU time. BLOCKED / WAITING / TIMED_WAITING → When it’s paused — maybe waiting for a lock or sleeping. Thread.sleep(1000); TERMINATED → Once run() finishes, the thread’s life ends. Why does this matter? Because knowing where a thread is can help you spot issues like deadlocks, long waits, or threads that never end. Next time your code hangs, check its state — it often tells the full story. And if you’ve ever debugged a “stuck” thread, share how you figured it out 💬 🔗 Follow Aman Mishra for more Backend real-talk and production lessons. 𝗜’𝘃𝗲 𝗰𝗼𝗺𝗽𝗶𝗹𝗲𝗱 𝘁𝗵𝗼𝘀𝗲 𝗹𝗲𝗮𝗿𝗻𝗶𝗻𝗴𝘀 𝗶𝗻𝘁𝗼 𝗮 𝗝𝗮𝘃𝗮 𝗠𝘂𝗹𝘁𝗶𝘁𝗵𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗚𝘂𝗶𝗱𝗲, 𝗰𝗼𝘃𝗲𝗿𝗶𝗻𝗴 𝘁𝗵𝗲 𝗲𝘅𝗮𝗰𝘁 𝗾𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 𝘁𝗵𝗮𝘁 𝗸𝗲𝗲𝗽 𝘀𝗵𝗼𝘄𝗶𝗻𝗴 𝘂𝗽. 𝗢𝗳𝗳𝗲𝗿𝗶𝗻𝗴 5𝟬% 𝗼𝗳𝗳 𝗳𝗼𝗿 𝗮 𝗹𝗶𝗺𝗶𝘁𝗲𝗱 𝘁𝗶𝗺𝗲!👇 𝗚𝗲𝘁 𝘁𝗵𝗲 𝗴𝘂𝗶𝗱𝗲 𝗵𝗲𝗿𝗲: https://lnkd.in/giGubpBt 𝗨𝘀𝗲 𝗰𝗼𝗱𝗲 𝗝𝗔𝗩𝗔𝟱𝟬
To view or add a comment, sign in
-
-
💡 Understanding the var Keyword in Java While learning modern Java, I came across the var keyword — a small feature that makes code cleaner, but only when used correctly. Here’s how I understand it 👇 In Java, when we declare a variable using var, the compiler automatically determines its data type based on the value assigned. For example: java var name = "Akash"; Here, Java infers that name is of type String. ⚠️ One important clarification: It’s not the JVM at runtime — type inference happens at compile time, so Java remains strongly typed. ### 📌 Key Rules of var ✔️ Must be initialized at the time of declaration java var a = "Akash"; // ✅ Valid var b; // ❌ Invalid ✔️ Can only be used inside methods (local variables) ❌ Not allowed for: * Instance variables * Static variables * Method parameters * Return types ### 🧠 Why use var? It helps reduce boilerplate and makes code cleaner, especially when the type is obvious: java var list = new ArrayList<String>(); ### 🚫 When NOT to use it Avoid `var` when it reduces readability: java var result = getData(); // ❌ unclear type ✨ My takeaway: `var` doesn’t make Java dynamic — it simply makes code more concise while keeping type safety intact. I’m currently exploring Java fundamentals and system design alongside frontend development. Would love to hear how you use var in your projects 👇 Syed Zabi Ulla PW Institute of Innovation #Java #Programming #LearningInPublic #100DaysOfCode #Developers #CodingJourney
To view or add a comment, sign in
-
-
Functional Optics for Modern Java – Part 6: From Theory to Practice. In the final instalment of the series, Magnus Smith brings the concepts of functional optics into real-world Java development. The blog explores how ideas like composability and effect-aware updates can move beyond theory and be applied to complex domain models in a practical, maintainable way. A thoughtful conclusion to the series that balances functional programming principles with the realities of modern Java. Read the full blog here: https://buff.ly/tvH7t66 #ModernJava #FunctionalOptics #JavaDevelopement
To view or add a comment, sign in
-
Day 94/100: #LeetCodeChallenge – Grid Partitioning in Java 🧩💻 Another day, another algorithmic deep dive! Today’s problem was about determining whether a grid can be partitioned in a specific way. While the problem may seem straightforward at first, the real challenge lies in handling edge cases, optimizing for efficiency, and ensuring clean, maintainable code. 🔍 Key takeaways from today’s solution: Understanding 2D array traversal and prefix sums Handling edge cases like 1x1 grids early Writing readable code that can scale with larger test cases Even though the sample output shows "You must run your code first," the process of thinking through the logic, testing edge cases, and refining the approach is where the real growth happens. Every problem adds another tool to the problem-solving toolkit. 🚀 Consistency > Intensity. Day 94 is in the books. On to the final sprint! #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving#GridPartitioning #DataStructuresAndAlgorithms #TechJourney#SoftwareEngineering #CodeNewbie #DeveloperLife #AlgorithmDesign#ConsistencyIsKey
To view or add a comment, sign in
-
-
💡 What I Learned About Java Interfaces (OOP Concept) I explored Interfaces in Java, and realized that they are not just about rules — they play a key role in achieving abstraction, flexibility, and clean design in applications. 🔹 Interfaces & Inheritance Interfaces are closely related to inheritance, where classes implement interfaces to follow a common structure. 🔹 Abstraction Interfaces enable abstraction. Before Java 8, they supported 100% abstraction, but now they can also include additional method types. 🔹 Polymorphism & Loose Coupling Interface references can point to different objects → making code more flexible, scalable, and maintainable. 🔹 Multiple Inheritance Java supports multiple inheritance through interfaces, allowing a class to implement multiple interfaces. 🔹 Functional Interface A functional interface contains only one abstract method. It can be implemented using: 1️⃣ Regular class 2️⃣ Inner class 3️⃣ Anonymous class 4️⃣ Lambda expression 🔹 Java 8 Enhancements Interfaces became more powerful with: ✔️ default methods (with implementation) ✔️ static methods ✔️ private methods ✔️ private static methods 🔹 Variables in Interface All variables are implicitly public static final (constants). 🔹 No Object Creation Interfaces cannot be instantiated, but reference variables can be created. 🚀 Conclusion: Interfaces are a core part of Java OOP that help build scalable, maintainable, and loosely coupled systems. #Java #OOPS #Interfaces #Programming #Learning #Java8 #Coding
To view or add a comment, sign in
-
-
💡 Java isn’t as simple as “new Object() = heap memory” Most developers learn: 👉 new Object() → Heap allocation 👉 Reference → Stack ✔️ Good for basics… but not the full story. 🚀 What really happens in modern Java? With JIT (Just-In-Time Compiler), the JVM can optimize away object creation completely. Yes, you read that right. void process() { Object obj = new Object(); System.out.println(obj.hashCode()); } 👉 If obj is used only inside the method and doesn’t “escape” ➡️ JVM may: Skip heap allocation ❌ Allocate on stack ⚡ Or eliminate the object entirely 🔥 🧠 The core concept: Escape Analysis If an object: ❌ Does NOT leave the method → Optimized ✅ Escapes (returned, shared, stored) → Heap allocation ⚠️ Common misconception ❌ “Avoid creating objects to save memory” ✔️ Reality: JVM is smarter than that Premature optimization can: Make code ugly Reduce maintainability Give no real performance gain 🔧 Static vs Object? ✔️ Use static when no state is needed ✔️ Use objects when behavior depends on data 👉 It’s not about avoiding new 👉 It’s about writing clean, logical design 🏁 Final takeaway Java is not just compiled — it adapts at runtime 🔥 The JVM decides: What to allocate What to remove What to optimize 👨💻 Write clean code. 📊 Measure performance. ⚡ Trust the JVM. #Java #JVM #Performance #Backend #SoftwareEngineering #CleanCode
To view or add a comment, sign in
-
I’ve written a simple blog breaking down the real difference between blocking, parking, and virtual threads in Java — and explaining what exactly gets paused (OS thread vs continuation) when your code “waits.” https://lnkd.in/g5DxUNMW
To view or add a comment, sign in
-
Recently, I revised some core Java concepts, and honestly, things started making more sense when I connected them practically. Polymorphism was one of the interesting parts. Method overloading happens at compile time, where the compiler already knows which method to call. But method overriding is different — the JVM decides at runtime, which makes it more dynamic. That’s where I understood the idea of early binding and late binding. Early binding is fixed during compilation, while late binding happens when the program is actually running. Dynamic method dispatch is just this in action — the JVM figuring out which method to execute based on the object. I also revised relationships in OOP. Inheritance follows an “is-a” relationship, like a cargo plane is a plane. Association is more of a “has-a” relationship, and it can be either strong (composition) or loose (aggregation). And one thing that helped me connect everything — Java code first becomes bytecode, and then JVM runs it. That’s where all the runtime decisions happen. Revisiting basics really helps in understanding how things actually work behind the scenes. #Java #OOP #Learning #CodingJourney
To view or add a comment, sign in
-
-
When an object is created in Java, it needs some initial values to start working. Who assigns those values? 𝑆𝑎𝑑𝑙𝑦… 𝐽𝑎𝑣𝑎 𝑑𝑜𝑒𝑠𝑛’𝑡 𝑟𝑒𝑎𝑑 𝑜𝑢𝑟 𝑚𝑖𝑛𝑑𝑠 𝑦𝑒𝑡 😅 That’s where constructors come in. ⚙️ 𝐂𝐨𝐧𝐬𝐭𝐫𝐮𝐜𝐭𝐨𝐫𝐬 A constructor is a special method in Java that is automatically executed when an object is created. Its main purpose is to initialize the object with the required values. For example, when we create a mobile object 📱, it may need values like: • brand • price Without constructors, we would have to create the object first and then assign values separately. A constructor allows us to set those values at the time of object creation, making the code cleaner and easier to manage. 🔹 𝐓𝐲𝐩𝐞𝐬 𝐨𝐟 𝐂𝐨𝐧𝐬𝐭𝐫𝐮𝐜𝐭𝐨𝐫𝐬 𝐢𝐧 𝐉𝐚𝐯𝐚 • Default Constructor – assigns default values to an object • Parameterized Constructor – allows passing values while creating the object I’ve attached a simple example in the code snippet below to show how constructors work 👇 #Java #CoreJava #OOP #Constructors #Programming #LearningJourney #BuildInPublic
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