Day 44 of Sharing What I’ve Learned🚀 Functional Interfaces & Lambda Expressions in Java In the previous post, I spoke about the different types of methods in interfaces. Building on that, I’ve been working with one of the most powerful concepts introduced in Java 8 — Functional Interfaces and Lambda Expressions. 🔹 What is a Functional Interface? A functional interface is an interface that contains only one abstract method. Even if it has multiple default or static methods, it is still considered functional as long as there is only one abstract method. Example: @FunctionalInterface interface Vehicle { void ride(); } 🔹 Ways to Implement a Functional Interface While working with this, I revisited the different approaches: 1️⃣ Using a Normal Class class Bicycle implements Vehicle { public void ride() { System.out.println("Pedal the cycle"); } } 2️⃣ Using an Inner Class class Outer { class Bicycle implements Vehicle { public void ride() { System.out.println("Riding from inner class"); } } } 3️⃣ Using an Anonymous Inner Class Vehicle v = new Vehicle() { public void ride() { System.out.println("Riding using anonymous class"); } }; 4️⃣ Using Lambda Expression (Java 8+) 🚀 Vehicle v = () -> { System.out.println("Riding using lambda"); }; 🔹 Why Lambda is Powerful ✔ Reduces boilerplate code ✔ Improves readability ✔ Encourages functional-style programming ✔ Widely used in Streams & modern Java APIs 🔹 Key Insight A lambda expression works only with functional interfaces, because Java needs exactly one method to implement. 🔹 Realization Earlier, implementing interfaces meant writing full classes. Now, the same behavior can be written in a single line using lambda, making Java much more concise and expressive. 🔹 What’s Next Moving ahead, I’ll be diving into Exception Handling, which plays a major role in building robust applications. #Java #CoreJava #OOP #FunctionalInterface #Lambda #Java8 #Programming #DeveloperJourney #100DaysOfCode #CodingJourney #Day44 Grateful for guidance from Sharath R, Harshit T, TAP Academy
Java Functional Interfaces & Lambda Expressions Explained
More Relevant Posts
-
🚀 **Day 6/30 – LeetCode Java Challenge** Today was not “easy wins.” This one actually demanded proper problem-solving. Worked on a **robot collision simulation problem** involving positions, directions, and health values. This wasn’t just coding — it required structuring the problem correctly before even thinking about implementation. 📊 **Result:** ✔️ Accepted (2433/2433 test cases) ⚡ Runtime: 50 ms (Beats 54.78%) 💾 Memory: Moderate 💡 **What actually mattered today:** * Sorting + stack = powerful combination for collision-type problems * Simulation problems expose weak logic very quickly * If your approach is unclear, your code will collapse under edge cases Let’s be honest: This solution works, but it’s not efficient enough. 54% runtime means there’s still a lot of room to optimize. The real takeaway is understanding the **approach**, not celebrating the acceptance. Most people stop at “Accepted.” That’s a mistake. The real growth starts after that. Day 6 done. More depth, less surface-level coding. Archana J E Bavani k Divya Suresh Deepika Kannan Hari priya B Harini B Bhavya B Devipriya R Kezia H Vaishnavi Janaki #LeetCode #Java #DSA #ProblemSolving #Consistency #30DaysOfCode #Algorithms
To view or add a comment, sign in
-
-
Day 14 of my coding journey — Extracting Unique Words using Java Streams Today I explored a clean and efficient way to extract unique words from a string using Java Streams. Instead of writing multiple loops and conditional checks, I leveraged the power of functional programming: Grouped words using a frequency map Filtered out words that appear more than once Collected only truly unique words in a concise pipeline What I really liked about this approach is how readable and expressive the code becomes. It clearly shows what we want to achieve rather than how step-by-step. Key takeaway: Writing optimized code is not just about performance — it’s also about clarity, maintainability, and using the right abstractions. Every day I’m getting more comfortable thinking in terms of streams, transformations, and data flow. If you have alternative approaches or optimizations, I’d love to hear them. #Day14 #Java #CodingJourney #JavaStreams #BackendDevelopment #ProblemSolving #CleanCode
To view or add a comment, sign in
-
-
Day 46 of Sharing What I’ve Learned🚀 Different Ways to Handle Exceptions in Java Continuing with exception handling, I explored how Java provides multiple ways to handle exceptions effectively depending on the situation. 🔹1. Using try-catch The most common way to handle exceptions: try { int c = a / b; } catch (ArithmeticException e) { System.out.println("Cannot divide by zero"); } ✔ Handles specific exceptions ✔ Prevents abrupt program termination 🔹 2. Multiple catch blocks We can handle different exceptions separately: try { int arr[] = new int[5]; arr[10] = 50; } catch (ArithmeticException e) { System.out.println("Arithmetic Error"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Array Index Issue"); } ✔ Helps in precise error handling ✔ Improves debugging 🔹3. Using finally block This block always executes (whether exception occurs or not): try { int c = a / b; } catch (Exception e) { System.out.println("Error occurred"); } finally { System.out.println("Execution completed"); } ✔ Used for cleanup (closing files, DB connections) 🔹 4. Using throw keyword Used to explicitly throw an exception: if (b == 0) { throw new ArithmeticException("Invalid denominator"); } ✔ Useful for custom validations 🔹5. Using throws keyword Used to declare exceptions in method signature: public void readFile() throws IOException { // code } ✔ Passes responsibility to the caller 🔹Key Insight Different situations require different handling strategies: ✔ try-catch → immediate handling ✔ multiple catch → specific handling ✔ finally → cleanup ✔ throw → manual exception creation ✔ throws → delegation 🔹 Realization Handling exceptions is not just about avoiding crashes — it’s about writing code that behaves predictably even in unexpected situations. That’s what makes applications reliable. #Java #CoreJava #ExceptionHandling #Programming #DeveloperJourney #100DaysOfCode #CodingJourney #Day46 grateful for guidance from, Sharath R , TAP Academy
To view or add a comment, sign in
-
-
Day 56 of Sharing What I’ve Learned🚀 TreeSet in Java — Sorted & Unique Elements After exploring how LinkedHashSet maintains insertion order, I moved to something even more powerful — TreeSet. 👉 It not only stores unique elements but also keeps them automatically sorted 🔹 What is TreeSet? TreeSet is an implementation of the Set interface that stores unique elements in sorted order. 👉 It is internally based on a Red-Black Tree (self-balancing binary search tree) 🔹 How does TreeSet store & sort data? 👉 Elements are stored in a tree structure, not randomly 👉 While inserting, elements are placed in a way that keeps the tree balanced 👉 Data is always arranged in ascending order (default) ✔ Smallest element → left side ✔ Largest element → right side ✔ In-order traversal → gives sorted output 🔹 Why use TreeSet? ✔ Sorted Data Elements are always in ascending order ✔ No Duplicates Just like other Sets, duplicates are not allowed ✔ Navigable Operations Supports methods like higher(), lower(), ceiling(), floor() 🔹 Key Features ✔ Stores unique elements ✔ Automatically sorts elements ✔ Does NOT allow null values ✔ Slower than HashSet & LinkedHashSet (due to sorting) 🔹 Important Methods ✔ add() ✔ remove() ✔ contains() ✔ first() / last() ✔ higher() / lower() 🔹 When should we use TreeSet? 👉 Use TreeSet when: ✔ You need sorted data ✔ You want range-based operations ✔ You need navigation (greater/smaller elements) 🔹 When NOT to use? ❌ When order doesn’t matter → use HashSet ❌ When insertion order matters → use LinkedHashSet ❌ When performance is critical (faster ops needed) 🔹 Key Insight 💡 TreeSet is like a self-sorting set — 👉 You don’t sort the data, it sorts itself automatically 🔹 Day 56 Realization 🎯 Data structures are not just about storing data… 👉 they define how efficiently you can retrieve, organize, and use it #Java #TreeSet #DataStructures #CollectionsFramework #Programming #DeveloperJourney #100DaysOfCode #Day56 Grateful for guidance from, Sharath R TAP Academy
To view or add a comment, sign in
-
-
💡 **Why Java Collection Framework is a Game Changer in Problem Solving** While going through my **Tata ILP training**, I’ve been spending time understanding the **Java Collection Framework**, and honestly, it completely changes the way you approach problems. Instead of thinking in terms of complex logic first, collections help you **organize data efficiently** — and that itself solves half the problem. 🔹 Need fast lookups? → Use a HashMap 🔹 Need unique elements? → HashSet does it instantly 🔹 Need ordering or sorting? → Lists and Trees make it simple What I realized is that most coding problems are not about writing long code, but about **choosing the right data structure**. Once that’s clear, the solution becomes much easier. To practice this, I worked on a small implementation and uploaded it on GitHub 📂 🔗 https://lnkd.in/gaRSsveu I’ve also added **proper comments in the code** so that anyone going through it can clearly understand the thought process and logic. Still learning, still improving — one concept at a time 🚀 #Java #JavaCollections #ProblemSolving #TataILP #CodingJourney #GitHub #LearnToCode #GrowthMindset
To view or add a comment, sign in
-
-
🚀 Exploring the Collection Framework in Java Ever wondered how Java efficiently manages large amounts of data? 🤔 Recently, I stepped into the Collection Framework—a powerful concept used for handling data effectively. 🔍 What is the Collection Framework? It is a collection of classes and interfaces that help in storing, manipulating, retrieving, and processing data easily. 💡 Why use it? ✔ Easy to store data ✔ Easy to manipulate ✔ Easy to retrieve ✔ Easy to process 📌 Core Interfaces: • List • Set • Map 🔗 Started with List Interface: Explored implementations like: • ArrayList • LinkedList • ArrayDeque • PriorityQueue 📊 What I analyzed: • Usage • Initial capacity • Heterogeneous data support ➡️ Then explored: • Insertion order • Duplicates • Null handling ➡️ Also looked into: • Constructors • Internal structure • Hierarchy 🔄 Ways to Access Elements: • For loop • For-each loop ➡️ Advanced ways: • Iterator • ListIterator 👉 Key Difference: Iterator moves only forward, whereas ListIterator supports both forward and backward traversal. 🌍 Real-Life Use Case: Imagine building a student management system 📚 • Use ArrayList to store and display student records • Use LinkedList for frequent insertions/deletions • Use PriorityQueue for priority-based processing 💡 Key Takeaway: Choosing the right data structure depends on the use case and performance requirements. 💻 Mini Code Example: import java.util.*; public class Demo { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("Python"); for(String lang : list) { System.out.println(lang); } } } ✨ Special thanks to Sharath R for the clear and practical explanation! TAP Academy Bibek Singh #Java #Collections #CollectionFramework #ArrayList #LinkedList #DataStructures #OOP #Programming #FullStackDevelopment #LearningJourney #Coding #Developer #TapAcademy
To view or add a comment, sign in
-
-
I struggled with the “100 days” part of #100DaysOfJava. And that’s exactly why this series mattered. Day 26 was in 2021. Day 66 was in 2023. Day 91 was in 2025. Day 99 was in 2026. So no, this wasn’t a clean streak. But it was real. I started this challenge thinking I was learning Java. APIs. Language features. Concurrency utilities. Small patterns. Useful tricks. What actually happened? Alongside Java, I ended up learning something much bigger: how systems behave, and how abstractions make complex system usable. I stopped asking: “What does this API do?” I started asking: “What is this system actually doing?” That question pulled me into: • memory leaks • heap dumps • JMX • off-heap memory • memory mapping • virtual threads • event loops • startup time • work distribution • concurrency failure modes Somewhere along the way, I realized: The best learning doesn’t come from collecting more information. It comes from breaking a mental model and rebuilding it. I thought virtual threads were just green threads. I thought event loops might become obsolete. I thought memory mapping was a neat API trick. I thought `.parallel()` would “just work.” Each time, the real lesson was one level deeper than the API. So Day 100 is not really a finish line. It’s a retrospective on what this challenge actually changed: how I think, how I debug, how I learn, and how I look at software systems. If this series taught me one thing, it’s this: It started as learning Java. It ended as learning how systems behave. Day 100 : https://lnkd.in/grGi5QZJ And this is not the end of the writing. I’m starting a bi-weekly Substack newsletter, Chaos;Code;Clarity, where I’ll keep writing about software systems and AI. If that sounds interesting, I shared more at the end of the blog. #Java #100DaysOfJava #SoftwareEngineering #JVM #Concurrency #SystemsThinking
To view or add a comment, sign in
-
🚀 Day 4 of 50 Days Coding Challenge Today I solved a problem on Hashing Pattern 🔹 Problem: Two Sum 🔹 Approach: First tried brute force using nested loops (checking all pairs) Then optimized using HashMap (Hashing concept) to reduce time complexity 🔹 Key Learning: Instead of checking every pair, we can store values and directly check if the required complement exists. This reduces time complexity from O(n²) → O(n) 🚀 Also learned an important concept: 👉 need = target - current element 🔹 Time Complexity: O(n) 🔹 Code (Java): import java.util.*; class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> map = new HashMap<>(); for(int i = 0; i < nums.length; i++) { int need = target - nums[i]; if(map.containsKey(need)) { return new int[]{map.get(need), i}; } map.put(nums[i], i); } return new int[]{-1, -1}; } } 💡 Consistency > Motivation #coding #leetcode #100DaysOfCode #java #programming #dsa #learning #hashmap
To view or add a comment, sign in
-
🚀 Day 38 of Learning Java — Problem Solving Mode ON! Every day is a new challenge, and today was no different. I solved the 'Minimum Distance to Target Element' problem and even caught a bug in my own code — and that's where the real learning happened! 💡 ━━━━━━━━━━━━━━━━━━━━━ 🧩 The Problem: Given an array of numbers, a target value, and a start index — find the minimum distance between the start index and any occurrence of the target. ━━━━━━━━━━━━━━━━━━━━━ 🔍 My Approach: ✅ Initialize minDistance = Integer.MAX_VALUE (as infinity placeholder) ✅ Loop through the array ✅ Whenever nums[i] == target, calculate Math.abs(i - start) ✅ Update minDistance using Math.min() ✅ Return the smallest distance found ━━━━━━━━━━━━━━━━━━━━━ 🐛 Bug I Found In My Own Code: I was calculating everything correctly but at the end I wrote: return 0; ❌ Instead of: return minDistance; ✅ One small mistake = always returns 0, no matter what! This is why code review and testing matters. 🔎 ━━━━━━━━━━━━━━━━━━━━━ 📚 Concepts I Practiced Today: → Linear Search — O(n) Time Complexity → Integer.MAX_VALUE — infinity placeholder trick → Math.abs() — always get positive distance → Math.min() — track the smallest value → Debugging — finding and fixing your own bugs ━━━━━━━━━━━━━━━━━━━━━ 💬 Lesson of the Day: You don't have to be perfect. You just have to be consistent. Write the code. Find the bug. Fix it. Learn. Repeat. 🔁 38 days down. Many more to go. Let's keep building! 💪☕ ━━━━━━━━━━━━━━━━━━━━━ #Day38OfJava #JavaProgramming #LeetCode #ProblemSolving #DSA #CodeNewbie #LearnToCode #JavaDeveloper #ArrayProblems #CodingJourney #JavaBeginner #Programming #CodeEveryDay #TechLearning #LinkedInLearning #SoftwareDevelopment #OpenToWork
To view or add a comment, sign in
-
🚀 Day 55 of #100DaysOfCode — Getting Started with Multithreading in Java Over the past 2 days, I explored one of the most important concepts in Java: Multithreading 🔥 💡 What I Learned 🧵 What is Multithreading? Multithreading allows a program to execute multiple tasks simultaneously, improving performance and efficiency ⚡ 👉 Instead of running tasks one after another, we can run them in parallel. ⚙️ Creating Threads in Java 1️⃣ Using Thread Class Extend the Thread class Override the run() method Start using start() 2️⃣ Using Runnable Interface (Best Practice ✅) Implement Runnable Pass it to a Thread object Start execution using start() 🧠 Key Takeaways ✔ Runnable is preferred over Thread (better design & flexibility) ✔ Supports multiple inheritance ✔ Separates task from execution ✔ Helps in building scalable backend systems ⚠️ Important Concept 👉 Difference between: run() ❌ (normal method call) start() ✅ (creates new thread) 🔥 Real-World Use Cases Backend APIs Payment systems Real-time applications Inventory & billing systems (like the one I'm building 🏪) 🚀 What’s Next? ➡️ Synchronization ➡️ Race Conditions ➡️ ExecutorService (Thread Pool) Learning multithreading feels like unlocking a new level in Java 💪 Huge thanks to my mentor Suresh Bishnoi for simplifying complex concepts like multithreading and pushing me to keep learning consistently. #Java #Multithreading #100DaysOfCode #BackendDevelopment #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