Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Online Book Store in Java
Next article icon

Online Book Store in Java

Last Updated : 10 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

An online bookstore is a platform that allows us to browse through a collection of books. We can also check details like title, author, price, and make purchases. In this article, we are going to build a simple online bookstore using Java. With the help of this project, we will gain hands-on experience with core Java concepts like streams, collections, and OOP (object-oriented programming).

In this article, we are going to build a basic online book store system with the ability to store, filter, and search for books. We will create different classes to keep the code more clean and organized, similar to the approach used in real-world software development.

Working of the Online Book Store System

Here is how our online book store system is going to work:

  • A list of books will be stored with details like title, author, price, and published date.
  • Users will be able to filter books based on their price.
  • The books can be grouped by their publication year.
  • Users can search for a specific book by its title.

Project Structure

The image below demonstrates the project structure

Project-Structure


We will organize the code into these parts which are listed below:

  • Book Class: This class represents a book's details.
  • BookStore Class: This class manage the book store inventory, handling filtering, searching and grouping of books.
  • BookStoreApp: This is the main class where all the store operations are performed.

Let's now try to implement the code.

Java Online Book Store Project Implementation

1. Book.java

This class is used to represent a book in the store, with attributes such as title, author, price and publish date.

Java
package com.bookstore;  import java.time.LocalDate;  public class Book {     private String title;     private String author;     private double price;     private LocalDate publishDate;      public Book(String title, String author, double price, LocalDate publishDate) {         this.title = title;         this.author = author;         this.price = price;         this.publishDate = publishDate;     }      public String getTitle() {         return title;     }      public String getAuthor() {         return author;     }      public double getPrice() {         return price;     }      public LocalDate getPublishDate() {         return publishDate;     }      @Override     public String toString() {         return "Book{Title='" + title + "', Author='" + author + "', Price=" + price + ", Publish Date=" + publishDate + "}";     } } 


2. BookStore Class

The BookStore class is where the main logic for filtering, grouping, and searching books resides.

Java
package com.bookstore;  import java.time.LocalDate; import java.util.*; import java.util.function.Predicate; import java.util.stream.Collectors;  public class BookStore {      private List<Book> books;      public BookStore() {         books = new ArrayList<>();         books.add(new Book("Java Programming", "Geek1", 39.99, LocalDate.of(2021, 1, 15)));         books.add(new Book("Learning Java 8", "Geek2", 49.99, LocalDate.of(2020, 5, 10)));         books.add(new Book("Advanced Java", "Geek3", 59.99, LocalDate.of(2021, 8, 20)));         books.add(new Book("Spring Framework", "Geek4", 29.99, LocalDate.of(2019, 11, 30)));     }      // Filtering books based on price     public List<Book> filterBooksByPrice(double maxPrice) {         return books.stream()                 .filter(book -> book.getPrice() <= maxPrice)                 .collect(Collectors.toList());     }      // Grouping books by year     public Map<Integer, List<Book>> groupBooksByYear() {         return books.stream()                 .collect(Collectors.groupingBy(book -> book.getPublishDate().getYear()));     }      // Searching books by title using Optional     public Optional<Book> searchBookByTitle(String title) {         return books.stream()                 .filter(book -> book.getTitle().equalsIgnoreCase(title))                 .findFirst();     }      // Display all books     public void displayBooks() {         books.forEach(System.out::println);     } } 


3. BookStoreApp.java

This class will be the entry point for running the application. It calls the method of the BookStore class to display and perform operations on the book list.

Java
package com.bookstore;  import java.time.LocalDate; import java.util.*; import java.util.function.Predicate; import java.util.stream.Collectors;  public class BookStore {      private List<Book> books;      public BookStore() {         books = new ArrayList<>();         books.add(new Book("Java Programming", "Geek1", 39.99, LocalDate.of(2021, 1, 15)));         books.add(new Book("Learning Java 8", "Geek2", 49.99, LocalDate.of(2020, 5, 10)));         books.add(new Book("Advanced Java", "Geek3", 59.99, LocalDate.of(2021, 8, 20)));         books.add(new Book("Spring Framework", "Geek4", 29.99, LocalDate.of(2019, 11, 30)));     }      // Filtering books based on price     public List<Book> filterBooksByPrice(double maxPrice) {         return books.stream()                 .filter(book -> book.getPrice() <= maxPrice)                 .collect(Collectors.toList());     }      // Grouping books by year     public Map<Integer, List<Book>> groupBooksByYear() {         return books.stream()                 .collect(Collectors.groupingBy(book -> book.getPublishDate().getYear()));     }      // Searching books by title using Optional     public Optional<Book> searchBookByTitle(String title) {         return books.stream()                 .filter(book -> book.getTitle().equalsIgnoreCase(title))                 .findFirst();     }      // Display all books     public void displayBooks() {         books.forEach(System.out::println);     } } 

Output:

file


How to Run the Project in IntelliJ IDEA?

To run the project on IntelliJ IDEA we just need to follow these steps which are listed below:

  • Open IntelliJ IDEA and create a new Java project.
  • Start creating the classes and the structure must be look like this:
    • Book.java
    • BookStore.java
    • BookStoreApp.java
  • Save all the files.
  • Run the BookStoreApp class.
Running-the-project

Next Article
Online Book Store in Java

M

musklf2s
Improve
Article Tags :
  • Java
  • Java Projects
Practice Tags :
  • Java

Similar Reads

    Local IDE vs Online IDE in Java
    An integrated development environment (IDE) is software that combines ordinary developer tools into a single graphical user interface for developing applications (GUI). An IDE usually consists of the following components: 1. Source code editor: It is a text editor that can help you write software co
    5 min read
    JRE in Java
    Java Runtime Environment (JRE) is an open-access software distribution that has a Java class library, specific tools, and a separate JVM. In Java, JRE is one of the interrelated components in the Java Development Kit (JDK). It is the most common environment available on devices for running Java prog
    4 min read
    How to Start Learning Java?
    Java is one of the most popular and widely used programming languages and platforms. A platform is an environment that helps to develop and run programs written in any programming language. Java is fast, reliable, and secure. From desktop to web applications, scientific supercomputers to gaming cons
    8 min read
    Top 5 Open Source Java Frameworks
    Almost 30 years and still Ruling the software industry, over the years Java has ranked among the top three most popular programming languages in the world with numerous applications, including back-end development projects, big data and machine learning projects, and obviously, web and Android devel
    7 min read
    Java Networking
    When computing devices such as laptops, desktops, servers, smartphones, and tablets and an eternally-expanding arrangement of IoT gadgets such as cameras, door locks, doorbells, refrigerators, audio/visual systems, thermostats, and various sensors are sharing information and data with each other is
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences