Real World Example

Meet ShopEase

Throughout the Java full stack materials you will build ShopEase, a small e-commerce backend similar to what powers Flipkart or Amazon India, just much simpler. Customers browse products, add them to a cart and place orders.

EntityMain fields
Productid, name, description, price, stock, category
Categoryid, name (Electronics, Books, Fashion ...)
Userid, name, email, password, role
CartItemuser, product, quantity
Order / OrderItemorder with status and total; one item per product bought

The Big Picture

React app / Postman  --HTTP + JSON-->  ShopEase (Spring Boot)  --SQL-->  MySQL
                                        |  ProductController   |
                                        |  ProductService      |
                                        |  ProductRepository   |

In this basic level you set up the project, learn Spring Core and configuration, and publish your first read-only product API. Later levels add full CRUD, validation, a database, security and deployment.

The Product Model in Plain Java

Example

Before any framework, here is the ShopEase product catalogue as plain Java. Spring Boot will later turn exactly this data into JSON over HTTP.

import java.math.BigDecimal;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<Product> catalogue = List.of(
            new Product(1, "Boat Rockerz 450", "Wireless headphones", new BigDecimal("1499.00"), 25, "Electronics"),
            new Product(2, "Clean Code", "Book by Robert C. Martin", new BigDecimal("599.00"), 40, "Books"),
            new Product(3, "Cotton T-Shirt", "Regular fit, navy blue", new BigDecimal("399.00"), 0, "Fashion"));

        for (Product p : catalogue) {
            String status = p.stock() > 0 ? "in stock" : "OUT OF STOCK";
            System.out.printf("#%d %-17s Rs.%8s  %-12s %s%n", p.id(), p.name(), p.price(), p.category(), status);
        }
    }
}

record Product(long id, String name, String description, BigDecimal price, int stock, String category) {}

Output

#1 Boat Rockerz 450  Rs. 1499.00  Electronics  in stock
#2 Clean Code        Rs.  599.00  Books        in stock
#3 Cotton T-Shirt    Rs.  399.00  Fashion      OUT OF STOCK

Practice

Exercise: Add a fourth product (any phone, category "Electronics", stock 10) and print only the products that are in stock.

Show answer
for (Product p : catalogue) {
    if (p.stock() > 0) {
        System.out.println(p.name() + " - Rs." + p.price());
    }
}