explaingit

omborse08/car-rental-system-java-lld-project

0JavaAudience · developerComplexity · 2/5ActiveSetup · moderate

TLDR

Console Java practice project for a car rental system, persisting state in MySQL via JDBC with prepared statements and try-with-resources as a low-level design study.

Mindmap

mindmap
  root((Car-Rental-System))
    Inputs
      Car details
      Customer details
      Rental days
    Outputs
      Rental receipts
      MySQL records
      Console output
    Use Cases
      Practice Java LLD
      Learn JDBC safely
      Demo OOP layering
    Tech Stack
      Java
      JDBC
      MySQL
      Connector/J

Things people build with this

USE CASE 1

Study a three-layer Java app with data classes, a controller, and a JDBC database layer.

USE CASE 2

Practice writing prepared statements and try-with-resources blocks against a real MySQL server.

USE CASE 3

Use as a portfolio piece for a junior Java low-level design interview.

USE CASE 4

Extend the schema with a rentals table and add return-by-date logic.

Tech stack

JavaJDBCMySQL

Getting it running

Difficulty · moderate Time to first run · 30min

Needs JDK 8+, a running MySQL server, and the MySQL Connector/J driver on the classpath before the console app can start.

License is not stated in the available content.

In plain English

This repository is a small Java practice project that builds a console-style car rental system. The author frames it as a low-level design exercise that goes beyond the usual in-memory examples by saving the state of the rental into a real MySQL database. The point of the project is to show how object-oriented code, clean separation between business logic and database code, and a few defensive habits fit together in one place. The code is split into three layers. The first layer holds the data classes. A Car class represents a vehicle in the fleet, with brand, model name, base price, and an availability state. A Customer class holds customer details and how many days they want to rent for. A RentalReceipt class records a finished transaction by linking a customer to a car along with the total price. The second layer is a RentalSystem class that acts as the controller. It coordinates the workflow, holds temporary state in HashMaps, and decides when to update records. The third layer is a Database_Control class that talks to MySQL directly through JDBC. The README highlights a few specific habits the author wanted to demonstrate. All database access goes through prepared statements with placeholders rather than building queries by string concatenation, which the author calls SQL injection immunity. Every block that opens a connection, a statement, or a result set uses Java's try-with-resources pattern so those resources close even when a query fails. The code also handles edge cases like an empty fleet or a missing record so the console app does not crash with an unhandled exception. Running it locally needs JDK 8 or higher, a MySQL server, and the MySQL Connector/J driver on the classpath. The README includes the SQL script that creates the database called local and two tables, one for cars and one for customers. The cars table has an auto-incrementing id, brand, car name, base price, and a rental_status column that defaults to AVAILABLE. The customers table has an id, a customer name, and a days field. The project is small and personal in scope. It does not claim to be a production system; it is meant as a study piece showing one developer's take on encapsulation, single responsibility, and safe resource handling in a Java application that touches a database.

Copy-paste prompts

Prompt 1
Walk me through the Car, Customer, and RentalReceipt classes and how RentalSystem orchestrates a rental.
Prompt 2
Show me every JDBC call in Database_Control and explain how prepared statements and try-with-resources prevent SQL injection and resource leaks.
Prompt 3
Write the MySQL setup script for the local database with cars and customers tables matching the README schema.
Prompt 4
Add a new rentals table that records receipts persistently and refactor RentalSystem to write to it on each successful rental.
Prompt 5
Convert this console app into a small Spring Boot REST API while keeping the same OOP layering.
Open on GitHub → Explain another repo

Generated 2026-05-22 · Model: sonnet-4-6 · Verify against the repo before relying on details.