This week focuses on handling runtime errors gracefully and mastering Java’s Collections Framework for managing groups of data. Students will also learn how to iterate efficiently using Iterators and Enhanced For Loops.
-
Understanding different types of errors:
- Compilation, Runtime, and Logical errors
-
Exception hierarchy (
Throwable,Exception,Error) -
Checked vs Unchecked exceptions
-
Using
try,catch,finallyblocks -
Throwing exceptions manually with
throw -
Declaring exceptions with
throws -
Creating custom exceptions
-
Best practices for clean, readable error handling
-
Purpose of the Collections Framework
-
List, Set, and Map interfaces
-
Key implementations:
ArrayListHashSet,HashMap,
-
Understanding:
- Duplicates and uniqueness
- Ordered vs unordered collections
- Accessing elements (by index or key)
-
Choosing the right collection for different use cases
-
Traversing collections safely and efficiently
-
Enhanced For Loop (for-each):
- Simple traversal for reading data
- Best for read-only operations
-
Iterator Interface:
- Methods:
hasNext(),next(),remove() - Safe element removal during iteration
- Preventing
ConcurrentModificationException
- Methods:
-
Using
forEach()and lambda expressions (Java 8+)- Functional style iteration
- Method references (
System.out::println)
- Combining Collections with Exception Handling (e.g., handling missing keys, empty lists, or invalid data)
- Using Iterators to filter data dynamically
- Nesting Lists and Maps for real-world data modeling
-
Practice
try-catch-finallywith different exception types -
Create and handle custom exceptions
-
Work with Lists, Sets, and Maps to manage collections of data
-
Write programs using Iterators and for-each loops
-
Build mini-projects combining OOP and collections concepts:
- Library Management
- Movie Catalog
- Student Grade Tracker
By the end of Week 4, students will:
- Understand and apply exception handling effectively
- Know when to use checked vs unchecked exceptions
- Be confident using Java Collections (List, Set, Map)
- Traverse collections with Iterators and enhanced for loops
- Write cleaner, safer, and more maintainable Java code