Programming in Java
Unit 11: Exceptions, Assertions & Multithreading
From graceful error handling to concurrent execution — master Java's exception hierarchy, assertion mechanisms, and multithreading to build production-grade applications like Zerodha and Paytm.
⏱️ 8 hrs theory + 6 hrs lab | 💰 ₹15K–₹50K/month | 📝 30 MCQs (Bloom's Mapped)
💼 Jobs this unlocks: Java Backend Developer (₹6–12 LPA) | Multithreaded Systems Engineer (₹8–18 LPA) | Fintech Developer (₹10–25 LPA)
Opening Hook — When 10 Lakh Orders Hit Zerodha at 9:15 AM
🏢 How Zerodha Handles ₹15 Lakh Crore Without Crashing
Every trading day at 9:15 AM, the Indian stock market opens. In that single second, Zerodha processes over 10 lakh concurrent buy/sell orders. Each order is a separate thread. When two traders try to modify the same shared portfolio balance simultaneously, Java's synchronized keyword ensures only one thread touches the balance at a time — preventing ₹15 lakh crore worth of data corruption.
But what happens when a UPI payment to Zerodha fails mid-transaction? A network timeout? An invalid stock symbol? The system doesn't crash — it catches the exception gracefully, logs the error, sends you a friendly "Order failed — please retry" message, and keeps running for the other 9,99,999 orders.
This unit teaches you both pillars: Exceptions (how to handle failures without crashing) and Multithreading (how to run thousands of tasks simultaneously). Together, they make Java the #1 language for fintech, banking, and high-frequency trading systems across India.
Learning Outcomes — Bloom's Taxonomy Mapped
| Bloom's Level | Learning Outcome |
|---|---|
| 🔴 Remember | List the exception hierarchy: Throwable → Error/Exception → RuntimeException, and differentiate checked vs unchecked exceptions |
| 🔴 Remember | Identify the five states in the Java thread lifecycle: NEW → RUNNABLE → BLOCKED → WAITING → TERMINATED |
| 🟠 Understand | Explain the execution flow of try-catch-finally and how try-with-resources auto-closes resources |
| 🟠 Understand | Describe how synchronized prevents race conditions in concurrent access to shared data |
| 🟢 Apply | Write custom checked and unchecked exceptions (InsufficientBalanceException) with exception chaining |
| 🟢 Apply | Create multithreaded programs using Thread class, Runnable interface, and lambda expressions |
| 🟡 Analyze | Analyze deadlock scenarios and determine prevention strategies using lock ordering |
| 🟡 Analyze | Compare Thread class extension vs Runnable implementation vs lambda-based thread creation |
| 🔵 Evaluate | Evaluate when to use ExecutorService thread pools vs manual thread management in production systems |
| 🔵 Evaluate | Assess the trade-offs of assert vs exception throwing for input validation in different deployment scenarios |
| 🟣 Create | Design a producer-consumer system (Zerodha Order Book) using wait/notify with full exception handling |
| 🟣 Create | Build a multithreaded bank transfer simulation with synchronized blocks and custom exception chains |