Programming in Java
Unit 5: Loops, Arrays & Enums
Master iteration, data storage with arrays, and type-safe constants with enumerations — build real Indian stock analyzers and student grade processors.
⏱️ 6 hrs theory + 5 hrs lab | 💰 ₹5K–₹20K/month | 📝 30 MCQs (Bloom's Mapped)
💼 Jobs: Backend Developer (₹5–10 LPA) | Software Engineer (₹6–15 LPA) | Competitive Programmer (₹8–20 LPA)
Opening Hook — The Engine Behind Every Product You Browse
🛒 How Flipkart Shows You Millions of Products in Milliseconds
Open Flipkart and search "wireless earbuds." Within 200 milliseconds, the app returns thousands of products — sorted by relevance, price, rating, and availability. Behind the scenes, Java code iterates through arrays of millions of product objects using optimised loops. Each product's price, rating, stock count, and seller info is stored in arrays and traversed using for loops, filtered using if conditions inside while loops, and categorised using enum types (ELECTRONICS, FASHION, HOME, etc.).
At NSE India, the Nifty 50 index recalculates every second during trading hours. A stock price analyzer takes an array of 375 one-minute candle prices (6.25 hours × 60 minutes), loops through them to compute moving averages, find day-high/day-low, detect crossover patterns, and flag breakout signals. Every one of these operations is fundamentally a loop iterating over an array.
Zerodha's Kite platform processes 15 million+ orders daily. Their backend, largely written in Java and Go, uses enum types for order status (PENDING, EXECUTED, CANCELLED, REJECTED) and arrays for real-time tick data. Without loops and arrays, modern trading platforms simply cannot exist.
for loop is the most-used control structure in production codebases — appearing in 94% of all Java projects on GitHub (2024 analysis). Arrays remain the #1 data structure in every programming language, used more than lists, maps, and trees combined.
Learning Outcomes — Bloom's Taxonomy Mapped
| Bloom's Level | Learning Outcome |
|---|---|
| 🔵 Remember | List the syntax of for, while, do-while loops and state rules for array declaration in Java |
| 🔵 Remember | Define enumeration, ordinal(), values(), and name() methods with correct signatures |
| 🔵 Understand | Explain the difference between for, enhanced for-each, while, and do-while loops with flowchart reasoning |
| 🔵 Understand | Describe how 1D and 2D arrays are stored in memory and why ArrayIndexOutOfBoundsException occurs |
| 🟢 Apply | Write a Java program using nested for loops to multiply two matrices and display the result |
| 🟢 Apply | Use java.util.Arrays methods (sort, binarySearch, fill, copyOf) to process student marks data |
| 🟢 Analyze | Compare the performance of for vs enhanced for-each for array traversal and identify when each is optimal |
| 🟢 Analyze | Debug a given loop-based program containing off-by-one errors, infinite loops, and incorrect break placement |
| 🟠 Evaluate | Assess whether to use arrays, ArrayList, or enum for a given real-world scenario with justification |
| 🟠 Evaluate | Critique a Nifty stock price analysis program for correctness, efficiency, and code quality |
| 🟠 Create | Design and implement a complete student marks analyzer using arrays, loops, and the Arrays utility class |
| 🟠 Create | Build an enum-based menu-driven application with EnumSet and EnumMap for an Indian railway booking scenario |