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)

Section A

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.

🇮🇳 Flipkart🇮🇳 NSE India🇮🇳 Zerodha🇮🇳 Amazon India🇮🇳 Infosys🇮🇳 TCS
A single Google search triggers approximately 1,000 computers working in parallel, each running loops over arrays of indexed web pages. The Java 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.
Section B

Learning Outcomes — Bloom's Taxonomy Mapped

Bloom's LevelLearning Outcome
🔵 RememberList the syntax of for, while, do-while loops and state rules for array declaration in Java
🔵 RememberDefine enumeration, ordinal(), values(), and name() methods with correct signatures
🔵 UnderstandExplain the difference between for, enhanced for-each, while, and do-while loops with flowchart reasoning
🔵 UnderstandDescribe how 1D and 2D arrays are stored in memory and why ArrayIndexOutOfBoundsException occurs
🟢 ApplyWrite a Java program using nested for loops to multiply two matrices and display the result
🟢 ApplyUse java.util.Arrays methods (sort, binarySearch, fill, copyOf) to process student marks data
🟢 AnalyzeCompare the performance of for vs enhanced for-each for array traversal and identify when each is optimal
🟢 AnalyzeDebug a given loop-based program containing off-by-one errors, infinite loops, and incorrect break placement
🟠 EvaluateAssess whether to use arrays, ArrayList, or enum for a given real-world scenario with justification
🟠 EvaluateCritique a Nifty stock price analysis program for correctness, efficiency, and code quality
🟠 CreateDesign and implement a complete student marks analyzer using arrays, loops, and the Arrays utility class
🟠 CreateBuild an enum-based menu-driven application with EnumSet and EnumMap for an Indian railway booking scenario