A Java desktop application demonstrating industry best practices, clean architecture, and modern software design patterns.
This project is a complete Library Management System built with:
- Core Java (OOP principles)
- Layered Architecture (Model-Service-Repository pattern)
- Swing GUI with tabs and tables
- CSV & JDBC persistence (CSV by default, MySQL optional)
- Authentication system (Admin/Guest roles)
- Fine calculation for late book returns
- Comprehensive error handling and validation
Perfect for: Portfolio, interview prep, learning Java architecture patterns.
- β Add new books (title, author)
- β View all books in table format
- β Search books by ID or title
- β Delete books (admin-only)
- β Track availability status
- β Monitor issue/return dates
- β Add new users/students
- β View all registered users
- β User lookup by ID/name
- β User role management (future)
- β Issue books to users
- β Track issue date (stored)
- β Return books with automatic fine calculation
- β Fine: Rs. 5 per day after 14-day limit
- β Display fine amount on return
- β
Admin login (
admin/admin123) - β
Guest login (
guest/guest) - β Role-based UI (admin-only features hidden for guests)
- β Session management
- β CSV file storage (default, no database needed)
- β JDBC MySQL support (optional, configurable)
- β Automatic data load on startup
- β Real-time save on all operations
- β
Centralized
AppConfig.java - β Toggle CSV vs JDBC mode
- β Customizable fine policy
- β Database credentials in one place
javProject/
βββ AppConfig.java # Configuration & constants
βββ Book.java # Book model with CSV serialization
βββ User.java # User model with CSV serialization
βββ FineCalculator.java # Fine calculation logic
β
βββ LibraryRepository.java # Repository interface (contract)
βββ CsvLibraryRepository.java # CSV-based persistence
βββ JdbcLibraryRepository.java # MySQL-based persistence
βββ RepositoryException.java # Custom exception
βββ NotFoundException.java # Custom exception
β
βββ LibraryService.java # Core business logic
βββ AuthService.java # Authentication & role management
β
βββ LibraryGUI.java # Swing UI (main view)
βββ Main.java # Entry point
β
βββ DatabaseManager.java # Utility for DB operations
βββ books.csv # Auto-generated (CSV mode)
βββ users.csv # Auto-generated (CSV mode)
βββ README.md # This file
| Layer | Technology |
|---|---|
| Language | Java 8+ |
| UI Framework | Swing (javax.swing) |
| Data Storage | CSV (default) / MySQL 5.7+ (optional) |
| JDBC | MySQL Connector/J |
| Design Pattern | MVC / Layered Architecture |
| Build | javac (no build tool required) |
javac *.javaAll .class files generated in same directory.
java MainGUI window opens automatically.
- Username:
admin - Password:
admin123
- Go to Books tab
- Enter Title:
Harry Potter - Enter Author:
J.K. Rowling - Click Add Book
- Go to Users tab
- Enter User Name:
John Doe - Click Add User
- Go to Issue/Return tab
- Enter Book ID:
1 - Enter User ID:
1 - Click Issue Book
- Go to Issue/Return tab
- Enter Book ID:
1 - Click Return Book
- β Fine calculated automatically
Open AppConfig.java:
public class AppConfig {
// Storage mode
public static final boolean USE_JDBC = false; // Set true for MySQL
// MySQL config (if USE_JDBC=true)
public static final String JDBC_URL = "jdbc:mysql://localhost:3306/librarydb?useSSL=false&serverTimezone=UTC";
public static final String JDBC_USER = "root";
public static final String JDBC_PASSWORD = "password";
// Fine policy (in Rupees, per day)
public static final int MAX_BOOK_ISSUE_DAYS = 14;
public static final int FINE_PER_LATE_DAY = 5;
// Default credentials
public static final String ADMIN_USERNAME = "admin";
public static final String ADMIN_PASSWORD = "admin123";
public static final String GUEST_USERNAME = "guest";
public static final String GUEST_PASSWORD = "guest";
}- Set
USE_JDBC = trueinAppConfig.java - Create database:
CREATE DATABASE librarydb;
- Update JDBC credentials if different
- Recompile and run:
javac *.java java Main
Tables auto-create on first run.
| Role | Access |
|---|---|
| Admin | Add/delete books, add users, view all |
| Guest | View books, issue/return, view users (read-only) |
| Type | Username | Password |
|---|---|---|
| Admin | admin |
admin123 |
| Guest | guest |
guest |
- Issue Period: 14 days (default)
- Fine: Rs. 5 per day after limit
- Formula:
Fine = (Days Used - 14) Γ 5(if Days Used > 14)
- Book issued: 2026-03-26
- Book returned: 2026-04-15 (20 days later)
- Late days: 20 - 14 = 6 days
- Fine: 6 Γ 5 = Rs. 30
CREATE DATABASE librarydb;
USE librarydb;Solution: Ensure all .java files compiled:
javac *.javaSolution: Check book ID exists. Use Search to find valid IDs.
Solution:
- Verify MySQL running:
mysql -u root -p - Database exists:
SHOW DATABASES;β checklibrarydb - Update credentials in
AppConfig.java - Recompile:
javac *.java
Solution: First run creates files automatically. If error persists:
rm *.csv
javac *.java
java MainLogic Assisted by AI (ChatGPT, Claude)
Your Name
GitHub: [Mani Singh] (https://github.com/mani1505-star/Library_Management_System.git)