Java Library Management System Project

The Java Library Management System is one of the most popular beginner-to-intermediate Java projects. It helps developers understand how to apply Object-Oriented Programming (OOP) concepts such as classes, objects, encapsulation, constructors, collections, loops, conditional statements, and user input to build a real-world application.

A Library Management System allows librarians to manage books efficiently by adding new books, issuing books to students, returning books, searching for books, and viewing all available books.

In this project, we’ll create a console-based Library Management System that is simple to understand and can be extended into a desktop or web application later.

Project Features

This Library Management System includes the following features:

  • Add a new book
  • View all books
  • Search a book by ID
  • Issue a book
  • Return a book
  • Delete a book
  • Display available books
  • Exit the application

Technologies Used

  • Java
  • Object-Oriented Programming (OOP)
  • ArrayList
  • Scanner Class
  • Loops
  • Switch Statement
  • Methods

Project Structure


LibraryManagement
│
├── Book.java
├── Library.java
└── LibraryManagement.java

File 1: Book.java


public class Book {
    private int id;
    private String title;
    private String author;
    private boolean issued;
    public Book(int id, String title, String author) {
        this.id = id;
        this.title = title;
        this.author = author;
        this.issued = false;
    }
    public int getId() {
        return id;
    }
    public String getTitle() {
        return title;
    }
    public String getAuthor() {
        return author;
    }
    public boolean isIssued() {
        return issued;
    }
    public void setIssued(boolean issued) {
        this.issued = issued;
    }
}

File 2: Library.java


import java.util.ArrayList;
public class Library {
    private ArrayList books = new ArrayList();
    public void addBook(Book book) {
        books.add(book);
        System.out.println("Book Added Successfully.");
    }
    public void displayBooks() {
        if (books.isEmpty()) {
            System.out.println("No Books Available.");
            return;
        }
        System.out.println("\n-------------------------------");
        for (Book book : books) {
            System.out.println("Book ID : " + book.getId());
            System.out.println("Title   : " + book.getTitle());
            System.out.println("Author  : " + book.getAuthor());
            System.out.println("Status  : " +
                    (book.isIssued() ? "Issued" : "Available"));
            System.out.println("-------------------------------");
        }
    }
    public void searchBook(int id) {
        for (Book book : books) {
            if (book.getId() == id) {
                System.out.println("Book Found");
                System.out.println("Title : " + book.getTitle());
                System.out.println("Author : " + book.getAuthor());
                return;
            }
        }
        System.out.println("Book Not Found.");
    }
    public void issueBook(int id) {
        for (Book book : books) {
            if (book.getId() == id) {
                if (!book.isIssued()) {
                    book.setIssued(true);
                    System.out.println("Book Issued Successfully.");
                } else {
                    System.out.println("Book Already Issued.");
                }
                return;
            }
        }
        System.out.println("Book Not Found.");
    }
    public void returnBook(int id) {
        for (Book book : books) {
            if (book.getId() == id) {
                if (book.isIssued()) {
                    book.setIssued(false);
                    System.out.println("Book Returned Successfully.");
                } else {
                    System.out.println("Book Was Not Issued.");
                }
                return;
            }
        }
        System.out.println("Book Not Found.");
    }
    public void deleteBook(int id) {
        for (Book book : books) {
            if (book.getId() == id) {
                books.remove(book);
                System.out.println("Book Deleted Successfully.");
                return;
            }
        }
        System.out.println("Book Not Found.");
    }
    public void availableBooks() {
        boolean found = false;
        System.out.println();
        for (Book book : books) {
            if (!book.isIssued()) {
                found = true
                System.out.println(book.getId() + " - " +
                        book.getTitle());
         }
        }
        if (!found) {
            System.out.println("No Available Books.");
        }
    }
}

File 3: LibraryManagement.java


import java.util.Scanner;
public class LibraryManagement {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Library library = new Library();
       int choice;
        do {
            System.out.println("\n========== LIBRARY MANAGEMENT ==========");
            System.out.println("1. Add Book");
            System.out.println("2. Display Books");
            System.out.println("3. Search Book");
            System.out.println("4. Issue Book");
            System.out.println("5. Return Book");
            System.out.println("6. Delete Book");
            System.out.println("7. Available Books");
            System.out.println("8. Exit");
            System.out.print("Enter Choice: ");
            choice = scanner.nextInt();
            switch (choice) {
               case 1:
                    System.out.print("Book ID: ");
                    int id = scanner.nextInt();
                    scanner.nextLine();
                   System.out.print("Book Title: ");
                   String title = scanner.nextLine();
                    System.out.print("Author Name: ");
                    String author = scanner.nextLine();
                    library.addBook(new Book(id, title, author));
                    break;
                case 2:
                    library.displayBooks();
                    break;
                case 3:
                   System.out.print("Enter Book ID: ");
                    library.searchBook(scanner.nextInt());
                   break;
                case 4:
                    System.out.print("Enter Book ID: ");
                    library.issueBook(scanner.nextInt());
                    break;
                case 5:
                    System.out.print("Enter Book ID: ");
                    library.returnBook(scanner.nextInt())
                    break;
                case 6:
                    System.out.print("Enter Book ID: ");
                    library.deleteBook(scanner.nextInt());
                    break;
                case 7:
                    library.availableBooks();
                    break;
                case 8:
                    System.out.println("Thank You!")
                    break;
                default:
                    System.out.println("Invalid Choice.");
            }
        } while (choice != 8);
        scanner.close();
    }
}

Sample Output


========== LIBRARY MANAGEMENT ==========
1. Add Book
2. Display Books
3. Search Book
4. Issue Book
5. Return Book
6. Delete Book
7. Available Books
8. Exit
Enter Choice: 1
Book ID: 101
Book Title: Java Programming
Author Name: James Gosling

Book Added Successfully.

Display Books


-------------------------------
Book ID : 101
Title   : Java Programming
Author  : James Gosling
Status  : Available
-------------------------------

Issue Book


Enter Book ID: 101

Book Issued Successfully.

Return Book


Enter Book ID: 101

Book Returned Successfully.

Search Book


Enter Book ID: 101
Book Found
Title : Java Programming
Author : James Gosling

Delete Book


Enter Book ID: 101

Book Deleted Successfully.

Project Workflow

The application works as follows:

  1. Display the main menu.
  2. The librarian selects an option.
  3. If adding a book, the program stores it in an ArrayList.
  4. Books can be searched using their unique ID.
  5. Books can be issued or returned by updating their status.
  6. The application displays all books or only available books.
  7. The application exits when the user selects the Exit option.

Java Concepts Used

This project demonstrates the following Java concepts:

  • Classes and Objects
  • Encapsulation
  • Constructors
  • Methods
  • ArrayList
  • Scanner Class
  • Loops
  • Switch Statement
  • If-Else Conditions
  • Boolean Variables
  • Method Calling
  • Object Creation

Possible Enhancements

You can improve this project by adding the following features:

  • Member registration
  • Student login
  • Librarian login
  • Fine calculation for overdue books
  • Book categories (Programming, Science, History, etc.)
  • ISBN number support
  • Search by title or author
  • Book reservation system
  • Issue date and return date
  • Save books in a MySQL database
  • File handling to store books permanently
  • Java Swing or JavaFX graphical user interface
  • Admin dashboard
  • Reports for issued and returned books
  • Barcode support
  • Email notifications for due dates

Learning Outcomes

After completing this project, you will understand how to:

  • Build a menu-driven Java application.
  • Design reusable classes using OOP principles.
  • Store and manage data using ArrayList.
  • Implement CRUD (Create, Read, Update, Delete) operations.
  • Search, update, and delete records.
  • Organize code into multiple Java classes.
  • Build a scalable project that can later integrate with databases or web frameworks.

Conclusion

The Java Library Management System Project is an excellent hands-on project for beginners and intermediate learners. It demonstrates how to combine core Java concepts such as classes, objects, methods, collections, loops, and conditional statements into a practical application.

This console-based version is easy to understand and serves as a strong foundation for more advanced projects. As your skills grow, you can extend it by integrating databases like MySQL, implementing user authentication, adding a graphical user interface with Swing or JavaFX, or even converting it into a web application using Spring Boot. Working on enhancements like these will strengthen your understanding of Java development and prepare you for real-world software projects.

Related Java Tutorials