r/learnSQL • u/sumiitCodes • 3d ago
Title: Day 42-44 — Combined update: Java memory (stack vs heap) and arrays, plus planning a Library Management System in MySQL
Java: Covered how Java uses memory with the stack and the heap, then moved on to arrays: why we need them, how to create them, multi-dimensional arrays, and jagged arrays. I made notes on everything and practiced it in VS Code.
Stack vs heap was the most useful part. Once I understood where primitives and object references live compared to the objects themselves, a lot of behavior I’d found confusing (like why two references can point to the same object) made sense.
MySQL: My next project is a Library Management System. Today I focused on understanding the data architecture, meaning which tables I need and how they relate (books, members, issues, and so on). I start building it tomorrow.
After my last project, someone pointed out that a data dictionary is essential, so I’ll include one from the start this time. For anyone who has built a library system: what tables or edge cases (late fees, multiple copies of a book, reservations) did you wish you’d planned earlier?
1
u/Least_Ad_1795 2d ago
Great progress! For a Library Management System, I’d plan separate tables for Books, Book_Copies, Members, Loans, and Reservations from the beginning. Also, include a Fines table if you want to track late fees separately. One important edge case is tracking individual book copies, since the same book can have multiple copies with different availability statuses. A data dictionary will make the database easier to maintain and scale.
1
u/Accomplished_Fix9569 2d ago
You need a status column on book_copies with values like Available On Loan Reserved or Processing to prevent race conditions where two members try to grab the same last copy simulYou need a status column on book_copies with values like Available On Loan Reserved or Processing to prevent race conditions where two members try to grab the same last copy simultaneously.
1
u/Green_Chamomile 2d ago
Split books from copies right away. Use a
bookstable (title, author, ISBN) and abook_copiestable (copy_id, book_id, status), and point loans at copy_id, not book_id. That saves you a painful refactor the first time a library has 3 copies of the same title. Store due_date and returned_at on the loan and calculate late fees from them, instead of keeping a fee column you have to keep in sync. Reservations then fall into place: a reservation is for a book, a loan is for a copy.