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)

Section A

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.

🇮🇳 Swiggy🇮🇳 Zomato🇮🇳 Flipkart🇮🇳 Paytm🇮🇳 PhonePe🇮🇳 Razorpay
Java 8 (which introduced lambdas in March 2014) is the most adopted Java version in history. Over 75% of Java applications worldwide run on Java 8 or later. In India alone, more than 10 million developers use Java daily, and lambda proficiency is now a non-negotiable requirement in 90%+ of Java job descriptions on Naukri.com and LinkedIn India.
Section B

Learning Outcomes — Bloom's Taxonomy Mapped

Bloom's LevelLearning Outcome
🔵 RememberDefine nested class, inner class, static nested class, anonymous class, lambda expression, and functional interface
🔵 RememberList the 4 types of method references in Java with their syntax patterns
🔵 UnderstandExplain why verbose anonymous classes led to the introduction of lambda expressions in Java 8
🔵 UnderstandDescribe the relationship between functional interfaces and lambda expressions — why lambdas need exactly one abstract method
🟢 ApplyWrite lambda expressions with zero, one, and multiple parameters in different syntax forms
🟢 ApplyUse built-in functional interfaces (Predicate, Function, Consumer, Supplier) in Java programs
🟢 ApplyReplace anonymous class implementations with equivalent lambda expressions
🟢 AnalyzeCompare static nested, inner, local, and anonymous classes — determine appropriate use cases for each
🟠 AnalyzeDifferentiate between the 4 types of method references and select the correct form for a given scenario
🟠 EvaluateAssess when to use lambda expressions vs method references vs anonymous classes in production code
🟠 EvaluateCritique legacy Java codebases and identify opportunities for lambda-based refactoring
🔴 CreateDesign a functional-style data processing pipeline using lambdas and java.util.function interfaces