This repository contains a collection of lab assignments completed as part of the Advanced Object-Oriented Programming course.
All lab assignments have been fully implemented and completed as part of academic coursework, demonstrating practical understanding of OOP concepts, design patterns, and concurrent systems.
- Graph implemented using Adjacency List
- Adjacency structure built using Map-based representation
- Breadth First Search (BFS) traversal
- Input validation and exception handling
- Modular class design
Key Implementation Detail:
The graph is represented using a Map<Integer, List<Integer>> to efficiently model connections between vertices.
- Object-oriented modeling of cities and routes
- Custom graph structure for representing travel connections
- Separation of concerns (City, Graph, Test classes)
- Validation and structured exception handling
- Snakes and Ladders board modeled as a directed graph
- Extends
Graphclass from Lab 01 using inheritance - Immutable snake and ladder positions using
Map.copyOf() - Minimum dice rolls to win calculated using BFS
Optional<Integer>used for null-safe jump destination handling- Stream API and lambda expressions for functional game logic
- Input validation with
IllegalArgumentExceptionfor invalid board configurations
Key Implementation Detail:
The board overrides addEdge() to block bidirectional edges and maintains its own directed adjacency list to model one-way moves including snake and ladder jumps.
- Efficient range query handling using Segment Tree
- Supports range sum queries and point updates
- Tree built using array-based representation
- Optimized space using power-of-two padding
- Recursive tree construction and query resolution
Advanced Implementation:
- Generic Segment Tree using Java Generics (
<T>) - Supports multiple operations via
BinaryOperator<T> - Implemented for Sum, Minimum, and GCD queries
- Implements publish-subscribe model
- Multiple observers: Dashboard, Alerts, Logging, Mobile Push
- Loose coupling between subject and observers
- Fault-tolerant notification mechanism
- Multiple pricing strategies: Standard, Express, Scheduled, Subscription
- Runtime strategy switching using setter injection
- Demonstrates Open/Closed Principle
- Real-world pricing logic simulation
- Unified interface for multiple third-party weather APIs
- Handles:
- Unit conversion (Fahrenheit → Celsius)
- Data format transformation
- Demonstrates integration of incompatible systems
- Dynamic addition of behaviors:
- Encryption
- Compression
- Timestamping
- Translation
- Supports flexible chaining of operations
- Demonstrates Open/Closed Principle
- Real-world system combining multiple design patterns:
- Strategy (Discount handling)
- Adapter (Payment gateway integration)
- Observer (Order notifications)
- Clean separation of concerns
- Easily extensible architecture
- Eliminates large conditional logic using polymorphism
- Parent class defines workflow (Template Method)
- Subclasses handle object creation
- Implemented using:
- Abstract class version
- Interface-based version
- Demonstrates Open/Closed Principle
- Ensures single instance across application
- Implemented using:
- Double-Checked Locking (thread-safe)
- Enum Singleton (recommended approach)
- Demonstrates global access and shared state consistency
- Implementation using ReentrantLock and Condition
- Supports multiple producers and consumers
- Avoids race conditions and deadlocks
- Uses
signalAll()for proper thread coordination
- Real-world concurrency simulation of a live trading exchange
- Immutable
OrderandMatchedPairobjects (inherently thread-safe) OrderBookusing ReentrantLock (fair=true) + two Conditions:ordersAvailable— engine waits here; traders signal on new orderbookNotFull— traders wait here; engine signals after consuming a match
ExchangeStatsusing AtomicInteger / AtomicLong (lock-free counters) + ReadWriteLock for consistent price snapshotsTraderimplements Callable<String> — returns order summary viaFutureMatchingEngineimplements Callable<String> — single-thread consumerDashboardusing ScheduledExecutorService (prints live stats every 2s)StockExchangewires everything: newFixedThreadPool(3) for 5 traders, newSingleThreadExecutor() for engine- Full graceful shutdown:
shutdown()→awaitTermination()→shutdownNow() AtomicBoolean exchangeOpenas shared shutdown signal across all threads
-
Encapsulation (Lab 01)
-
Abstraction (Lab 01)
-
Inheritance & Method Overriding (Lab 02, Lab 03)
-
Modular class design (Lab 01, Lab 02)
-
Graph modeling using adjacency list (Lab 01, Lab 02)
-
BFS traversal algorithm (Lab 01, Lab 03)
-
Object-oriented problem modeling (Lab 02)
-
Exception handling (Lab 01, Lab 02, Lab 03)
-
Functional Programming (Streams, Lambdas, Predicates) (Lab 03)
-
Null Safety using
Optional(Lab 03) -
Immutability (Lab 03)
-
Segment Tree (Range Queries) (Lab 04)
-
Recursion and divide-and-conquer techniques (Lab 04)
-
Generics and functional interfaces (
BinaryOperator) (Lab 04) -
Behavioral Design Patterns (Observer, Strategy) (Lab 05)
-
Polymorphism (Lab 05, Lab 06, Lab 07)
-
Open/Closed Principle (Lab 05, Lab 06, Lab 08)
-
Structural Design Patterns (Adapter, Decorator) (Lab 06)
-
System design using multiple patterns (Lab 07)
-
Creational Design Patterns (Factory Method, Singleton) (Lab 08)
-
Template Method Pattern (Lab 08)
-
Thread-safe design (Double-Checked Locking, Enum Singleton) (Lab 08)
-
Concurrency and Multithreading (Lab 09)
-
Synchronization using
ReentrantLockandCondition(Lab 09) -
Immutability as thread-safety strategy (Lab 09)
-
volatilevisibility guarantee andAtomicBooleanfor shutdown flags (Lab 09) -
AtomicInteger/AtomicLonglock-free CAS operations (Lab 09) -
ReadWriteLock— multiple concurrent readers, exclusive writer (Lab 09) -
CallableandFuturefor retrieving results from threads (Lab 09) -
Thread pool types:
newFixedThreadPool,newSingleThreadExecutor(Lab 09) -
ScheduledExecutorServicefor periodic background tasks (Lab 09) -
Graceful executor shutdown pattern (Lab 09)
-
Two-Condition pattern (targeted
signal()vs wastefulnotifyAll()) (Lab 09)
- Java
- IntelliJ IDEA
- Git & GitHub
advanced-oop-java-labs
│
├── src
│ ├── Lab01_Graph_BFS
│ ├── Lab02_TravelGraph
│ ├── Lab03_SnakesAndLadders
│ ├── Lab04_SegmentTree
│ ├── Lab05_BehavioralDesignPatterns
│ ├── Lab06_StructuralDesignPatterns
│ ├── Lab07_Refactoring
│ ├── Lab08_CreationalDesignPattern
│ └── Lab09_multithreading
│
├── README.md
└── .gitignore