Skip to content

mani1505-star/Library_Management_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Library Management System

A Java desktop application demonstrating industry best practices, clean architecture, and modern software design patterns.

🎯 Overview

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.


✨ Key Features

πŸ“š Book Management

  • βœ… 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

πŸ‘₯ User Management

  • βœ… Add new users/students
  • βœ… View all registered users
  • βœ… User lookup by ID/name
  • βœ… User role management (future)

πŸ“€ Issue & Return System

  • βœ… 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

πŸ” Authentication & Authorization

  • βœ… Admin login (admin/admin123)
  • βœ… Guest login (guest/guest)
  • βœ… Role-based UI (admin-only features hidden for guests)
  • βœ… Session management

πŸ’Ύ Data Persistence

  • βœ… CSV file storage (default, no database needed)
  • βœ… JDBC MySQL support (optional, configurable)
  • βœ… Automatic data load on startup
  • βœ… Real-time save on all operations

βš™οΈ Configuration

  • βœ… Centralized AppConfig.java
  • βœ… Toggle CSV vs JDBC mode
  • βœ… Customizable fine policy
  • βœ… Database credentials in one place

File Structure

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

πŸ› οΈ Technology Stack

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)

Compile

javac *.java

All .class files generated in same directory.

Run

java Main

GUI window opens automatically.


πŸš€ Quick Start

1. Login

  • Username: admin
  • Password: admin123

2. Add a Book (Admin only)

  • Go to Books tab
  • Enter Title: Harry Potter
  • Enter Author: J.K. Rowling
  • Click Add Book

3. Add a User (Admin only)

  • Go to Users tab
  • Enter User Name: John Doe
  • Click Add User

4. Issue a Book

  • Go to Issue/Return tab
  • Enter Book ID: 1
  • Enter User ID: 1
  • Click Issue Book

5. Return a Book

  • Go to Issue/Return tab
  • Enter Book ID: 1
  • Click Return Book
  • βœ… Fine calculated automatically

βš™οΈ Configuration

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";
}

Switch to MySQL Mode

  1. Set USE_JDBC = true in AppConfig.java
  2. Create database:
    CREATE DATABASE librarydb;
  3. Update JDBC credentials if different
  4. Recompile and run:
    javac *.java
    java Main

Tables auto-create on first run.


πŸ” Authentication & Authorization

Role Access
Admin Add/delete books, add users, view all
Guest View books, issue/return, view users (read-only)

Login Credentials

Type Username Password
Admin admin admin123
Guest guest guest

πŸ’° Fine Calculation System

Policy

  • Issue Period: 14 days (default)
  • Fine: Rs. 5 per day after limit
  • Formula: Fine = (Days Used - 14) Γ— 5 (if Days Used > 14)

Example

  • Book issued: 2026-03-26
  • Book returned: 2026-04-15 (20 days later)
  • Late days: 20 - 14 = 6 days
  • Fine: 6 Γ— 5 = Rs. 30

πŸ—„οΈ Database Setup (MySQL Mode)

Create Database

CREATE DATABASE librarydb;
USE librarydb;

❌ Troubleshooting

Issue: java.lang.ClassNotFoundException

Solution: Ensure all .java files compiled:

javac *.java

Issue: NotFoundException: Book not found: 999

Solution: Check book ID exists. Use Search to find valid IDs.

Issue: SQLException when USE_JDBC=true

Solution:

  1. Verify MySQL running: mysql -u root -p
  2. Database exists: SHOW DATABASES; β†’ check librarydb
  3. Update credentials in AppConfig.java
  4. Recompile: javac *.java

Issue: FileNotFoundException: books.csv

Solution: First run creates files automatically. If error persists:

rm *.csv
javac *.java
java Main

πŸ‘¨β€πŸ’» Author

Logic Assisted by AI (ChatGPT, Claude)

Your Name
GitHub: [Mani Singh] (https://github.com/mani1505-star/Library_Management_System.git)

About

Developed a Java-based Library Management System using OOP. Implemented features like add, search, issue, return, and delete books. Used ArrayList and file handling for data storage, with exception handling for robust and reliable performance.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages