Programming in Java
Unit 10: Nested Classes & Lambda Expressions
From verbose anonymous classes to elegant one-liners — master lambda expressions, functional interfaces, and method references to write modern, expressive Java.
⏱ 6 hrs theory + 4 hrs lab | 💰 ₹10K–₹30K/month | 📝 30 MCQs (Bloom's Mapped)
💼 Jobs this unlocks: Java Backend Developer (₹5–10 LPA) | Spring Boot Engineer (₹8–18 LPA) | Full-Stack Java Developer (₹6–14 LPA)
Opening Hook — One Line That Changed Java Forever
🏢 How Swiggy Calculates Your Delivery Fee in One Line of Java
Every time you order biryani on Swiggy, a delivery fee is calculated based on distance, restaurant load, surge pricing, and weather. Before Java 8, Swiggy's engineering team would have written something like this:
Java — Before (Anonymous Class) interface FeeCalculator { double calculate(Order order); } FeeCalculator calculator = new FeeCalculator() { @Override public double calculate(Order order) { return order.getDistance() * 2.5; } };
With Java 8 lambdas, this becomes one line:
Java — After (Lambda) Function<Order, Double> feeCalculator = order -> order.getDistance() * 2.5;
One line of Java replacing 20 lines of anonymous class boilerplate. That's not just syntactic sugar — it's a paradigm shift. Lambdas make Java code more readable, more composable, and more functional. Every major Indian tech company — Swiggy, Zomato, Flipkart, Paytm, PhonePe, Razorpay — writes Java this way today.
Learning Outcomes — Bloom's Taxonomy Mapped
| Bloom's Level | Learning Outcome |
|---|---|
| 🔵 Remember | Define nested class, inner class, static nested class, anonymous class, lambda expression, and functional interface |
| 🔵 Remember | List the 4 types of method references in Java with their syntax patterns |
| 🔵 Understand | Explain why verbose anonymous classes led to the introduction of lambda expressions in Java 8 |
| 🔵 Understand | Describe the relationship between functional interfaces and lambda expressions — why lambdas need exactly one abstract method |
| 🟢 Apply | Write lambda expressions with zero, one, and multiple parameters in different syntax forms |
| 🟢 Apply | Use built-in functional interfaces (Predicate, Function, Consumer, Supplier) in Java programs |
| 🟢 Apply | Replace anonymous class implementations with equivalent lambda expressions |
| 🟢 Analyze | Compare static nested, inner, local, and anonymous classes — determine appropriate use cases for each |
| 🟠 Analyze | Differentiate between the 4 types of method references and select the correct form for a given scenario |
| 🟠 Evaluate | Assess when to use lambda expressions vs method references vs anonymous classes in production code |
| 🟠 Evaluate | Critique legacy Java codebases and identify opportunities for lambda-based refactoring |
| 🔴 Create | Design a functional-style data processing pipeline using lambdas and java.util.function interfaces |