Skip to content

akankshaagroya/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 comprehensive Java-based desktop application for managing library operations including book inventory, user management, and book lending/returning operations. This system features a graphical user interface (GUI) built with Java Swing and implements object-oriented programming principles.

📚 Table of Contents

🔍 Overview

The Library Management System is a desktop application designed to automate and streamline library operations. It provides a user-friendly graphical interface for librarians to manage books, users, and lending operations efficiently. The system is built using Java and follows the Model-View-Controller (MVC) architectural pattern.

What Makes This System Special?

  • Pure Java Implementation: No external databases required - uses in-memory data structures
  • Swing GUI: Professional desktop interface with background images and responsive design
  • Object-Oriented Design: Clean separation of concerns with dedicated model classes
  • Real-time Updates: Immediate reflection of all operations in the interface
  • Error Handling: Comprehensive validation and user-friendly error messages

🏗️ System Architecture

The application follows a layered architecture pattern:

┌─────────────────────────────────────┐
│           Presentation Layer        │
│         (LibraryGUI.java)          │
├─────────────────────────────────────┤
│            Main Layer               │
│           (Main.java)               │
├─────────────────────────────────────┤
│            Model Layer              │
│  (Book.java, User.java, Library.java) │
└─────────────────────────────────────┘

Package Structure Explained

src/
├── main/
│   └── Main.java          # Application entry point
├── models/
│   ├── Book.java          # Book entity with properties and operations
│   ├── User.java          # User entity with issued books tracking
│   └── Library.java       # Core business logic and data management
└── gui/
    └── LibraryGUI.java    # Complete user interface implementation

🧩 Core Components Deep Dive

1. Book Class (src/models/Book.java)

The Book class represents the fundamental entity in our library system.

Properties:

  • title (String): The book's title
  • author (String): The book's author
  • quantityAvailable (int): Current number of copies available for lending

Key Methods:

public void issue()         // Decrements available quantity when book is issued
public void returnBook()    // Increments available quantity when book is returned
public String toString()    // Provides formatted string representation for display

Special Implementation Details:

  • Quantity Management: The system automatically tracks available copies
  • Thread Safety: Methods are designed to be atomic operations
  • Data Validation: Prevents negative quantities through conditional logic

2. User Class (src/models/User.java)

Represents library users with their personal information and borrowed books.

Properties:

  • name (String): User's full name
  • id (int): Unique identifier for each user
  • issuedBooks (List): Dynamic list of currently borrowed books

Key Features:

  • Dynamic Book Tracking: Uses ArrayList for flexible book management
  • Unique Identification: Each user has a distinct ID for easy lookup
  • Encapsulation: Private fields with public getter methods

3. Library Class (src/models/Library.java)

The central management class that orchestrates all library operations.

Core Collections:

private List<Book> books;   // Master catalog of all books
private List<User> users;   // Registry of all registered users

Critical Methods:

  • addBook(Book book): Adds books to the library catalog
  • addUser(User user): Registers new users in the system
  • getUserById(int id): Retrieves user by unique ID with O(n) search

Data Management Strategy:

  • Uses ArrayList for dynamic sizing
  • Implements linear search for user lookup
  • No persistence layer - data exists only during application runtime

4. LibraryGUI Class (src/gui/LibraryGUI.java)

The complete user interface implementation using Java Swing.

GUI Architecture:

  • Layout Manager: BorderLayout for main container
  • Button Organization: GridLayout for systematic button arrangement
  • Background Handling: Dynamic image scaling with component listeners

Event-Driven Programming: Each button implements the ActionListener interface:

addUserButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        // Handle user addition logic
    }
});

💾 Data Management System

Memory-Based Storage

This system uses in-memory data structures instead of traditional databases:

Advantages:

  • ✅ No database setup required
  • ✅ Fast data access (all in RAM)
  • ✅ Simple deployment
  • ✅ No external dependencies

Trade-offs:

  • ❌ Data lost when application closes
  • ❌ Limited by available RAM
  • ❌ No concurrent user support
  • ❌ No data persistence

Data Structure Choices

ArrayList vs Array: The system uses ArrayList<> instead of fixed arrays because:

  • Dynamic resizing as books/users are added
  • Built-in methods like add(), remove()
  • Type safety with generics
  • Automatic memory management

Linear Search Implementation:

public User getUserById(int id) {
    for (User user : users) {
        if (user.getId() == id) {
            return user;
        }
    }
    return null;  // User not found
}

Time Complexity: O(n) - searches through all users sequentially

🎨 User Interface Design

Swing Components Breakdown

Main Window Structure:

setTitle("Library Management System");
setSize(1000, 800);                    // Fixed window size
setDefaultCloseOperation(EXIT_ON_CLOSE); // Proper application termination
setLayout(new BorderLayout());         // Flexible layout management

Background Image Implementation

Dynamic Scaling System:

ImageIcon backgroundImage = new ImageIcon("./images/pexels-technobulka-2908984.jpg");
Image scaledImage = backgroundImage.getImage().getScaledInstance(
    getWidth(), getHeight(), Image.SCALE_SMOOTH);

Responsive Resize Handling:

addComponentListener(new java.awt.event.ComponentAdapter() {
    public void componentResized(java.awt.event.ComponentEvent evt) {
        // Automatically rescale background when window is resized
    }
});

Button Layout Strategy

GridLayout Configuration:

buttonPanel.setLayout(new GridLayout(6, 1, 10, 3));
//                                   ↑   ↑   ↑   ↑
//                                rows cols hgap vgap

This creates:

  • 6 rows, 1 column
  • 10 pixels horizontal spacing
  • 3 pixels vertical spacing

🚀 Installation & Setup

Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Any Java IDE (Eclipse, IntelliJ IDEA, VS Code) or command line

Installation Steps

  1. Clone or Download the Repository

    git clone <repository-url>
    cd Library-Management-System
  2. Verify Java Installation

    java -version
    javac -version
  3. Compile the Application

    # Navigate to the project root
    javac -d . src/main/Main.java src/models/*.java src/gui/*.java
  4. Run the Application

    java src.main.Main

Project Structure Setup

Ensure your directory structure matches:

Library-Management-System/
├── images/
│   └── pexels-technobulka-2908984.jpg
├── src/
│   ├── main/Main.java
│   ├── models/
│   └── gui/
└── README.md

📖 Usage Guide

Starting the Application

  1. Run the main class: src.main.Main
  2. The GUI window opens with a background image
  3. Six operational buttons appear on the left side

Core Operations

1. Adding Users

  • Click "Add User"
  • Enter user's full name
  • Provide a unique numeric ID
  • System validates ID uniqueness

Error Handling:

  • Empty names rejected
  • Duplicate IDs prevented
  • Non-numeric IDs handled gracefully

2. Adding Books

  • Click "Add Book"
  • Enter book title, author name, and quantity
  • All fields validated for completeness
  • Quantity must be positive number

3. Issuing Books

  • Click "Issue Book"
  • Enter exact book title (case-insensitive)
  • Provide user ID
  • System checks book availability and user existence

Business Logic:

  • Decrements book quantity
  • Adds book to user's issued list
  • Prevents issuing unavailable books

4. Returning Books

  • Click "Return Book"
  • Enter book title and user ID
  • System verifies user has this book issued

Return Process:

  • Increments book quantity
  • Removes book from user's issued list
  • Validates return legitimacy

5. Viewing Data

  • View Books: Displays all books with availability
  • View Users: Shows users with their issued books

🔧 Code Structure & Patterns

Object-Oriented Principles

Encapsulation:

public class Book {
    private String title;      // Private fields
    private String author;
    private int quantityAvailable;
    
    public String getTitle() { // Public getter methods
        return title;
    }
}

Single Responsibility Principle:

  • Book: Manages book data and operations
  • User: Handles user information and issued books
  • Library: Orchestrates overall library operations
  • LibraryGUI: Manages user interface exclusively

Design Patterns Used

Model-View-Controller (MVC):

  • Model: Book, User, Library classes
  • View: LibraryGUI class
  • Controller: Event listeners within LibraryGUI

Observer Pattern (Implicit): GUI buttons observe user actions and trigger appropriate model updates

Error Handling Strategy

Input Validation:

if (name == null || name.trim().isEmpty()) {
    JOptionPane.showMessageDialog(null, "User name cannot be empty!");
    return;
}

Exception Handling:

try {
    id = Integer.parseInt(JOptionPane.showInputDialog("Enter User ID:"));
} catch (NumberFormatException ex) {
    JOptionPane.showMessageDialog(null, "Invalid User ID! Please enter a number.");
}

✨ Key Features

1. Real-Time Inventory Management

  • Automatic quantity updates during issue/return operations
  • Immediate availability checking
  • Dynamic display updates

2. User-Friendly Interface

  • Intuitive button-based navigation
  • Clear error messages and confirmations
  • Responsive design with background scaling

3. Data Integrity

  • Duplicate user ID prevention
  • Book availability validation
  • Return legitimacy verification

4. Comprehensive Reporting

  • Complete book catalog viewing
  • User-specific issued books tracking
  • Real-time availability status

🔧 Technical Implementation Details

Memory Management

Object Lifecycle:

  • Objects created when users/books are added
  • References maintained in ArrayList collections
  • Garbage collection handles cleanup automatically

Performance Characteristics:

  • Book/User addition: O(1) amortized
  • User lookup: O(n) linear search
  • Book search: O(n) linear search
  • Memory usage: Proportional to number of books + users

GUI Threading

Event Dispatch Thread: All GUI operations run on the Event Dispatch Thread (EDT):

SwingUtilities.invokeLater(() -> {
    LibraryGUI gui = new LibraryGUI(library);
    gui.setVisible(true);
});

String Comparison

Case-Insensitive Matching:

if (book.getTitle().equalsIgnoreCase(title)) {
    // Match found regardless of case
}

🔮 Future Enhancements

Database Integration

  • Replace ArrayList with database connectivity
  • Implement CRUD operations with SQL
  • Add data persistence

Advanced Features

  • Book reservation system
  • Due date tracking and overdue notifications
  • Search and filter capabilities
  • Report generation (PDF/Excel)

User Interface Improvements

  • Table-based data display (JTable)
  • Advanced search functionality
  • Multi-language support
  • Theme customization

Security & Access Control

  • User authentication system
  • Role-based permissions (Admin/Librarian)
  • Audit trail logging

Performance Optimizations

  • HashMap for O(1) user lookup
  • Indexed search capabilities
  • Pagination for large datasets
  • Background operations threading

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages