A robust, multi-threaded Java console application designed to manage inventory for perishable and non-perishable goods. This project demonstrates core backend development principles including Object-Oriented Design, Concurrency, Data Persistence, and the Java Stream API.
This project simulates a real-world inventory system capable of:
- Managing perishable & non-perishable products
- Handling concurrent stock updates safely
- Persisting data using file serialization
- Generating reports & monitoring stock in real-time
- Thread-Safe Architecture: Utilizes
ConcurrentHashMapto ensure data integrity while a background daemon thread continuously monitors stock levels. - Readable Data Persistence: Automatically saves and loads inventory state using CSV (
inventory.csv), allowing for easy viewing in external spreadsheet software. - Advanced Search & Filtering: Implements Java Streams and Lambda expressions to provide instant, case-insensitive searching by Product ID or Name.
- Automated Audit Trail: Appends real-time, timestamped sales data to a
transaction_log.txtfile for accounting and history tracking. - Smart Date Handling: Uses
java.time.LocalDateto securely handle and format expiry dates for perishable goods.
src/
├── core/ # Core business logic and background threads
│ ├── InventoryManager.java
│ └── StockMonitorThread.java
├── exceptions/ # Custom error handling
│ └── OutOfStockException.java
├── models/ # Data structures and OOP hierarchy
│ ├── Product.java (Abstract)
│ ├── PerishableProduct.java
│ └── NonPerishableProduct.java
├── storage/ # File I/O operations
│ ├── FileHandler.java (Interface)
│ └── FileManager.java
└── SmartInventorySystem.java # Main entry point and user interface
- Language: Java (JDK 8+)
- Concepts: Multithreading, Polymorphism, Interfaces, Exception Handling
- Storage: File Handling (Serialization)
- Concurrency:
ConcurrentHashMap,synchronized - APIs: Stream API, java.time (Date/Time API), java.io (File I/O)
Handles business logic errors cleanly.
public class OutOfStockException extends Exception {
public OutOfStockException(String message) {
super(message);
}
}-
Abstract base class:
Product -
Derived classes:
PerishableProductNonPerishableProduct
💡 Demonstrates:
- Abstraction
- Inheritance
- Runtime polymorphism
Handles persistence using serialization.
ObjectOutputStream → save inventory
ObjectInputStream → load inventory✔️ Stores data in:
inventory.datreport.txt
💥 The brain of the system
- ⚡ O(1) lookup using
ConcurrentHashMap - 🔒 Thread-safe operations using
synchronized - 📊 Sales tracking & reporting
- 📉 Low stock detection using Streams API
StockMonitorThread (Daemon Thread)- Runs in background every 30 seconds
- Detects low-stock products
- Prevents blocking main execution
Start Program
↓
Load Inventory / Initialize Sample Data
↓
Start Background Stock Monitor Thread
↓
User Menu:
1. Add Product
2. View Products
3. Sell Product
4. Restock Product
5. Low Stock Check
6. Generate Report
7. Exit
CURRENT INVENTORY
-------------------------------------------------------------
ID Name Price (₹) Quantity Type
-------------------------------------------------------------
101 Milk 45.0 15 Perishable
102 Sugar 55.0 4 Non-Perishable
-------------------------------------------------------------
| Concept | Implementation |
|---|---|
| OOP | Abstract classes & inheritance |
| Exception Handling | Custom exceptions |
| Multithreading | Background monitoring thread |
| Collections | ConcurrentHashMap |
| File Handling | Serialization |
| Java Streams | Filtering & aggregation |
- 🚀
ConcurrentHashMap→ Fast & thread-safe - 🔒
synchronizedblocks → Prevent race conditions - 📦 Serialization → Lightweight persistence
- ⚡ Streams API → Efficient data processing
- 📦 Products handled: 100K+ records
- ⚡ Lookup Time: O(1) using ConcurrentHashMap
- 🧵 Background Monitoring: Every 30 seconds
- 💾 Persistence: File-based serialization
# Compile
javac SmartInventorySystem.java
# Run
java SmartInventorySystem- Add database integration (MySQL / MongoDB)
- Build REST API (Spring Boot)
- Add frontend dashboard (React)
- Implement authentication & user roles
⭐ Star this repo if you found it useful!