<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: HAMAD ULLAH</title>
    <description>The latest articles on DEV Community by HAMAD ULLAH (@hamad_19).</description>
    <link>https://dev.to/hamad_19</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4145110%2Fe97a1b96-de26-4b42-a888-cab6c8617956.jpg</url>
      <title>DEV Community: HAMAD ULLAH</title>
      <link>https://dev.to/hamad_19</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hamad_19"/>
    <language>en</language>
    <item>
      <title>How I Structured a Java Library Management System with DAO and Service Layers</title>
      <dc:creator>HAMAD ULLAH</dc:creator>
      <pubDate>Sun, 27 Sep 2026 05:58:44 +0000</pubDate>
      <link>https://dev.to/hamad_19/how-i-structured-a-java-library-management-system-with-dao-and-service-layers-358k</link>
      <guid>https://dev.to/hamad_19/how-i-structured-a-java-library-management-system-with-dao-and-service-layers-358k</guid>
      <description>&lt;h1&gt;
  
  
  How I Structured a Java Library Management System with DAO and Service Layers
&lt;/h1&gt;

&lt;p&gt;When I started building a Library Management System in Java, I wanted to do more than connect a few SQL queries to a console menu. I wanted to understand how a database-backed Java application could be organized when it starts having multiple responsibilities.&lt;/p&gt;

&lt;p&gt;I built a console-based Library Management System using Java, JDBC, and MySQL. Instead of putting everything into one class, I separated the application into model, DAO, service, connection, and utility packages.&lt;/p&gt;

&lt;p&gt;The project gave me practical experience with something I had been learning conceptually: &lt;strong&gt;separating application responsibilities so that each part of the program has a clear purpose.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It also gave me a chance to work with a more realistic workflow than simple CRUD, particularly when issuing and returning books affects both transaction records and book availability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Built the Project
&lt;/h2&gt;

&lt;p&gt;I built this project as a way to practice Java in a larger application rather than working with isolated classes and small exercises.&lt;/p&gt;

&lt;p&gt;A library system has several related operations. Books need to be stored and searched, members need to be registered, and transactions need to connect members with books. When a book is issued, its available-copy count also needs to change. Returning a book reverses part of that process.&lt;/p&gt;

&lt;p&gt;That made the project useful for practicing database operations while also thinking about application structure.&lt;/p&gt;

&lt;p&gt;I also wanted to get more comfortable separating responsibilities. Instead of having the main class handle user input, SQL queries, business logic, and database connections, I wanted different parts of the application to handle different jobs.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the Application Does
&lt;/h2&gt;

&lt;p&gt;The application runs through a console menu.&lt;/p&gt;

&lt;p&gt;Users can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add books&lt;/li&gt;
&lt;li&gt;View books&lt;/li&gt;
&lt;li&gt;Search for books&lt;/li&gt;
&lt;li&gt;Delete books&lt;/li&gt;
&lt;li&gt;Add members&lt;/li&gt;
&lt;li&gt;View members&lt;/li&gt;
&lt;li&gt;Issue books&lt;/li&gt;
&lt;li&gt;Return books&lt;/li&gt;
&lt;li&gt;View book issue records&lt;/li&gt;
&lt;li&gt;Exit the application&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The application uses a MySQL database called &lt;code&gt;library_db&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The project is a plain Java application using JDBC directly rather than a framework such as Spring Boot or Hibernate. The IntelliJ project configuration uses JDK 19 and references MySQL Connector/J.&lt;/p&gt;

&lt;p&gt;That made the project particularly useful for me because I had to work directly with JDBC instead of having a framework hide the database interaction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Organizing the Project
&lt;/h2&gt;

&lt;p&gt;The source code is divided into several packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
├── app/
│   └── LibraryManagementSystem.java
├── connection/
│   └── DBConnection.java
├── dao/
│   ├── BookDao.java
│   ├── MemberDao.java
│   └── TransactionDao.java
├── model/
│   ├── Book.java
│   ├── BookIssue.java
│   ├── Member.java
│   └── Transactions.java
├── services/
│   ├── BookService.java
│   ├── MemberService.java
│   └── TransactionService.java
└── util/
    └── DateAndTime.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I divided the application into five main responsibilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model&lt;/strong&gt; — represents application data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DAO&lt;/strong&gt; — communicates with the database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service&lt;/strong&gt; — coordinates application operations and business logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connection&lt;/strong&gt; — provides database connectivity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Utility&lt;/strong&gt; — contains reusable functionality such as date handling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main application brings these parts together.&lt;/p&gt;

&lt;p&gt;This structure helped me understand that organizing code is not only about creating more classes. The important question is &lt;strong&gt;why each class exists and what responsibility belongs there.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Models: Representing Application Data
&lt;/h2&gt;

&lt;p&gt;The model classes represent the data used by the application.&lt;/p&gt;

&lt;p&gt;For example, the &lt;code&gt;Book&lt;/code&gt; class contains information such as the book ID, title, category, publication year, total copies, and available copies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;publish_year&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;total_copies&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;available_copies&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// getters and setters&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are also separate models for members and transactions.&lt;/p&gt;

&lt;p&gt;One interesting part of the project is &lt;code&gt;BookIssue&lt;/code&gt;. A transaction stored in the database contains IDs connecting a member and a book, but when displaying an issue record, I wanted information such as the member's name, phone number, and book title.&lt;/p&gt;

&lt;p&gt;That is where a separate representation becomes useful. The application does not have to expose the raw database structure directly to the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  The DAO Layer
&lt;/h2&gt;

&lt;p&gt;The DAO classes are responsible for database operations.&lt;/p&gt;

&lt;p&gt;There are separate DAOs for books, members, and transactions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BookDao
MemberDao
TransactionDao
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, &lt;code&gt;BookDao&lt;/code&gt; handles operations such as adding books, retrieving books, searching by ID, deleting books, and changing the number of available copies.&lt;/p&gt;

&lt;p&gt;One of the important things I learned while working with JDBC was to use &lt;code&gt;PreparedStatement&lt;/code&gt; rather than building SQL statements by concatenating user input.&lt;/p&gt;

&lt;p&gt;A simplified example from the book insertion code is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="s"&gt;"INSERT INTO book "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"(title,pub_year,category,total_copies,available_copies) "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"VALUES (?, ?, ?, ?, ?)"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DBConnection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getConnection&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PreparedStatement&lt;/span&gt; &lt;span class="n"&gt;ps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;prepareStatement&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPublish_year&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getCategory&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getTotal_copies&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getAvailable_copies&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

        &lt;span class="n"&gt;rowsAffected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;executeUpdate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The DAO knows how to communicate with MySQL, but it does not need to know how the console application collects the user's input.&lt;/p&gt;

&lt;p&gt;That separation was one of the clearest benefits of the architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the Service Layer Exists
&lt;/h2&gt;

&lt;p&gt;The service classes sit between the main application and the DAOs.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;BookService&lt;/code&gt; handles the process of collecting book information, creating a &lt;code&gt;Book&lt;/code&gt; object, and sending it to the DAO.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setCategory&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setPublish_year&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;publish_year&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setTotal_copies&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total_copies&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setAvailable_copies&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total_copies&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BookDao&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addBook&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a small but important piece of logic here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setAvailable_copies&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total_copies&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a new book is added, all of its copies are initially available.&lt;/p&gt;

&lt;p&gt;The service layer is therefore not just passing data between classes. It can make application-level decisions before the data reaches the database.&lt;/p&gt;

&lt;p&gt;This helped me understand the difference between &lt;strong&gt;business logic and database access&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The DAO answers a question such as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How do I insert this book into MySQL?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The service layer deals more with:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What should happen when a user adds a new book?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Keeping those responsibilities separate makes the code easier to reason about.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Most Interesting Workflow: Issuing a Book
&lt;/h2&gt;

&lt;p&gt;The issuing process was one of the most useful parts of the project because it involves several components working together.&lt;/p&gt;

&lt;p&gt;When &lt;code&gt;TransactionService.issueBook()&lt;/code&gt; runs, the application asks the user to select a member and a book. It then asks for a return date.&lt;/p&gt;

&lt;p&gt;Before creating the transaction, the return date is validated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;current_date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DateAndTime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;validDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nc"&gt;DateAndTime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;compareDate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current_date&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;return_date&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;validDate&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;issueBookHelper&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;member_id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;book_id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;current_date&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;return_date&lt;/span&gt;
    &lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid Return Date Entered"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the date is valid, a transaction object is created containing information such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Book ID&lt;/li&gt;
&lt;li&gt;Member ID&lt;/li&gt;
&lt;li&gt;Issue date&lt;/li&gt;
&lt;li&gt;Return date&lt;/li&gt;
&lt;li&gt;Fine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The transaction is then sent to &lt;code&gt;TransactionDao&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At the same time, the available quantity of the book needs to be updated.&lt;/p&gt;

&lt;p&gt;So one user action involves several parts of the application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
  ↓
TransactionService
  ↓
TransactionDao
  ↓
MySQL
  ↓
BookDao
  ↓
Update available copies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was where the layered structure became more than just a way of organizing files. It gave each part of the workflow a specific responsibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Updating Book Availability
&lt;/h2&gt;

&lt;p&gt;Book availability is a simple example of application logic that goes beyond basic CRUD.&lt;/p&gt;

&lt;p&gt;When a book is issued, the available-copy count is decreased:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;decrement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="s"&gt;"UPDATE book "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"SET available_copies = available_copies - 1 "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"WHERE id = ?"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the book is returned, the count can be increased:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="s"&gt;"UPDATE book "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"SET available_copies = available_copies + 1 "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"WHERE id = ?"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database therefore stores both the total number of copies and the number currently available.&lt;/p&gt;

&lt;p&gt;This made me think about data consistency in a way that simple insert and select operations did not.&lt;/p&gt;

&lt;p&gt;An operation such as issuing a book is not just:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT transaction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It also means:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create transaction
+
Update book availability
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That relationship is part of the application's business logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using SQL Joins for Issue Records
&lt;/h2&gt;

&lt;p&gt;Another part of the project that helped me understand database-backed applications better was retrieving information from multiple tables.&lt;/p&gt;

&lt;p&gt;The transaction table stores IDs that connect the transaction to a book and member. When displaying a record, however, the user needs more useful information.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TransactionDao.getBookRecord()&lt;/code&gt; uses SQL joins:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="s"&gt;"SELECT t.id, m.name, m.phone, b.title, "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"t.issue_date, t.return_date "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"FROM transactions t "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"JOIN book b ON t.book_id = b.id "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"JOIN member m ON t.member_id = m.id "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="s"&gt;"WHERE t.id = ?"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query combines information from the transaction, book, and member tables.&lt;/p&gt;

&lt;p&gt;The result is then represented using a &lt;code&gt;BookIssue&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;This was useful because it showed me that the objects used by an application do not always have to correspond exactly to one database table.&lt;/p&gt;

&lt;p&gt;A database might store normalized information across several tables, while the application can create an object representing the information needed for a particular operation or screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Date Handling and Fines
&lt;/h2&gt;

&lt;p&gt;The project also contains a &lt;code&gt;DateAndTime&lt;/code&gt; utility class for working with dates.&lt;/p&gt;

&lt;p&gt;It uses Java's &lt;code&gt;LocalDate&lt;/code&gt; and a &lt;code&gt;DateTimeFormatter&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;DateTimeFormatter&lt;/span&gt; &lt;span class="n"&gt;formatter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nc"&gt;DateTimeFormatter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofPattern&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"yyyy-MM-dd"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The utility provides operations for retrieving the current date and comparing or validating dates.&lt;/p&gt;

&lt;p&gt;The transaction system also includes fine handling. &lt;code&gt;TransactionDao.fineValidate()&lt;/code&gt; checks transaction records and updates the fine when a return date has passed.&lt;/p&gt;

&lt;p&gt;The project uses an &lt;code&gt;Iterator&lt;/code&gt; to process transaction records:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Iterator&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Transactions&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;transactions&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hasNext&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Transactions&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DateAndTime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;validateDate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getReturn_date&lt;/span&gt;&lt;span class="o"&gt;()))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// update fine&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gave me practical experience combining Java collections, date handling, and database operations in the same application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling Errors and JDBC Resources
&lt;/h2&gt;

&lt;p&gt;Exception handling is another area I practiced throughout the project.&lt;/p&gt;

&lt;p&gt;The main application handles invalid numeric input using &lt;code&gt;NumberFormatException&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NumberFormatException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="s"&gt;"Input Error: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getMessage&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="s"&gt;"Error: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getMessage&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The DAO classes also handle &lt;code&gt;SQLException&lt;/code&gt; when working with the database.&lt;/p&gt;

&lt;p&gt;For JDBC resources, I used try-with-resources:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DBConnection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getConnection&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PreparedStatement&lt;/span&gt; &lt;span class="n"&gt;ps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
             &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;prepareStatement&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// database operation&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was important because JDBC resources such as connections and statements should not be left open unnecessarily.&lt;/p&gt;

&lt;p&gt;Using try-with-resources made the cleanup automatic and made the database code easier to manage.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learned from the Project
&lt;/h2&gt;

&lt;p&gt;The biggest lesson from this project was that application structure becomes increasingly important as the number of responsibilities grows.&lt;/p&gt;

&lt;p&gt;In smaller Java exercises, it is easy to put everything into one class. As soon as an application has users, database operations, validation, transactions, and multiple types of data, that approach becomes difficult to maintain.&lt;/p&gt;

&lt;p&gt;This project made me think about questions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which class should contain this SQL query?&lt;/li&gt;
&lt;li&gt;Should this logic belong in the service or DAO?&lt;/li&gt;
&lt;li&gt;What object should represent data returned by a join?&lt;/li&gt;
&lt;li&gt;Where should date validation happen?&lt;/li&gt;
&lt;li&gt;What should happen to available copies when a book is issued?&lt;/li&gt;
&lt;li&gt;How should database resources be managed?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions helped me move from thinking only about whether my code works to thinking about &lt;strong&gt;how the code is organized&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I also became more comfortable with JDBC concepts such as &lt;code&gt;PreparedStatement&lt;/code&gt;, &lt;code&gt;ResultSet&lt;/code&gt;, SQL joins, &lt;code&gt;executeQuery()&lt;/code&gt;, &lt;code&gt;executeUpdate()&lt;/code&gt;, and try-with-resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Would Improve
&lt;/h2&gt;

&lt;p&gt;The project is a learning application, so there are several things I would improve if I continued developing it.&lt;/p&gt;

&lt;p&gt;First, I would move database configuration into external configuration rather than keeping connection details directly in application code. This would make the application easier and safer to configure across different environments.&lt;/p&gt;

&lt;p&gt;I would also strengthen the validation around issuing books. For example, the application should explicitly prevent an issue operation when a book has no available copies.&lt;/p&gt;

&lt;p&gt;Another improvement would be transaction management. Issuing a book can involve creating a transaction and changing the available-copy count. These related database operations would benefit from proper database transaction handling so they can succeed or fail together.&lt;/p&gt;

&lt;p&gt;I would also make exception handling more consistent. Some parts of the application return boolean values, while other parts print errors directly. A more consistent error-handling strategy would make the application easier to maintain.&lt;/p&gt;

&lt;p&gt;Finally, I would consider improving the project setup and documentation so that someone cloning the repository could configure the database and run the application with fewer manual steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building this Library Management System helped me understand something that is difficult to learn from small coding exercises alone: &lt;strong&gt;good application structure is about assigning responsibilities clearly.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The project uses plain Java, JDBC, and MySQL, which meant I could see the database interaction directly instead of relying on a framework to hide it.&lt;/p&gt;

&lt;p&gt;The model classes represent application data, the DAOs handle database operations, the services coordinate application logic, the connection class manages JDBC connectivity, and the utility class provides reusable date functionality.&lt;/p&gt;

&lt;p&gt;The book-issue workflow brought all of these pieces together. A single operation can involve user input, validation, object creation, database persistence, and updating book availability.&lt;/p&gt;

&lt;p&gt;That experience changed how I think about organizing Java applications. I started the project wanting to practice JDBC and database programming, but I finished with a better understanding of how different layers can work together to keep an application organized.&lt;/p&gt;

&lt;h3&gt;
  
  
  GitHub Repository
&lt;/h3&gt;

&lt;p&gt;The complete source code is available on GitHub:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/Hamadullah-Odho/LibraryManagementSystem.git" rel="noopener noreferrer"&gt;https://github.com/Hamadullah-Odho/LibraryManagementSystem.git&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>jdbc</category>
      <category>mysql</category>
      <category>oop</category>
    </item>
    <item>
      <title>How I Built a Student Course Registration System to Learn Java OOP</title>
      <dc:creator>HAMAD ULLAH</dc:creator>
      <pubDate>Sun, 27 Sep 2026 05:46:29 +0000</pubDate>
      <link>https://dev.to/hamad_19/how-i-built-a-student-course-registration-system-to-learn-java-oop-18g6</link>
      <guid>https://dev.to/hamad_19/how-i-built-a-student-course-registration-system-to-learn-java-oop-18g6</guid>
      <description>&lt;h1&gt;
  
  
  How I Built a Student Course Registration System to Learn Java OOP
&lt;/h1&gt;

&lt;p&gt;When I was learning Java, I reached a point where simply knowing how to create classes and objects was no longer enough. I wanted to understand how the different concepts of object-oriented programming fit together when building an actual application.&lt;/p&gt;

&lt;p&gt;At the time, two areas I was particularly interested in were &lt;strong&gt;abstraction&lt;/strong&gt; and &lt;strong&gt;exception handling&lt;/strong&gt;. Abstraction was especially confusing for me. I understood the syntax of an abstract class and an abstract method, but I was still asking myself a basic question: &lt;strong&gt;Why do I actually need abstraction?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of trying to understand the concept only through small examples, I decided to build a project around it.&lt;/p&gt;

&lt;p&gt;That project became a &lt;strong&gt;Student Course Registration System&lt;/strong&gt;, a console-based Java application that allows students to be registered, courses to be assigned to students, and administrators to access student and course information.&lt;/p&gt;

&lt;p&gt;The application is relatively small, but it gave me a practical environment to work with inheritance, encapsulation, abstraction, polymorphism, and exception handling together.&lt;/p&gt;

&lt;p&gt;More importantly, it helped me understand that knowing the syntax of an OOP concept and knowing when to use it are two different things.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Built This Project
&lt;/h2&gt;

&lt;p&gt;I built this project while I was learning Java OOP.&lt;/p&gt;

&lt;p&gt;My main goal was to stop treating OOP concepts as separate topics. I wanted to see what would happen when I had to use several of them in the same application.&lt;/p&gt;

&lt;p&gt;For example, I could create a simple example of inheritance and understand that one class can extend another. I could create an abstract class and understand how abstract methods work. But those examples did not always answer the more practical question of &lt;strong&gt;why I would design an application that way&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The Student Course Registration System gave me an opportunity to experiment with that.&lt;/p&gt;

&lt;p&gt;I wanted students to have their own information and enrollment behavior. I also wanted administrators to have their own authentication behavior. That naturally gave me different types of objects and relationships to work with.&lt;/p&gt;

&lt;p&gt;I was especially interested in abstraction because it was the concept I was having the most difficulty understanding.&lt;/p&gt;

&lt;p&gt;I knew what an abstract class looked like in Java, but I didn't initially understand why I would create a class that could not be instantiated directly.&lt;/p&gt;

&lt;p&gt;Building this project helped me start answering that question.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Application Structure
&lt;/h2&gt;

&lt;p&gt;The application is a console program with two main areas: a student portal and an admin portal.&lt;/p&gt;

&lt;p&gt;The student side handles operations such as registering students and enrolling them in courses. The admin side provides authentication and access to student and course information.&lt;/p&gt;

&lt;p&gt;The application's main menu is handled by the &lt;code&gt;Main&lt;/code&gt; class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;SystemManager&lt;/span&gt; &lt;span class="n"&gt;manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SystemManager&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// display menu&lt;/span&gt;

    &lt;span class="c1"&gt;// read selection&lt;/span&gt;

    &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;select&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;enrollStudent&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addCourse&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// ...&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I created a separate &lt;code&gt;SystemManager&lt;/code&gt; rather than putting all of the application logic inside &lt;code&gt;Main&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The main relationships between the classes can be simplified like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Main
  |
  v
SystemManager
  |
  +---- Student[]
  |
  +---- AdminSystem
  |
  +---- Course

User (abstract)
  |
  +---- Student

Admin (abstract)
  |
  +---- AdminSystem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was not intended to be a large enterprise architecture. I was mainly trying to learn how to divide responsibilities between objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dividing Responsibilities Between Classes
&lt;/h2&gt;

&lt;p&gt;The project contains several classes, and each one has a particular responsibility.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Main&lt;/code&gt; is responsible primarily for starting the application, displaying the menu, and receiving the user's selections.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SystemManager&lt;/code&gt; coordinates operations such as registering students, searching for students, displaying information, and enrolling students in courses.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Student&lt;/code&gt; represents a student and contains student-specific information and behavior.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;User&lt;/code&gt; contains information common to users and defines an abstract &lt;code&gt;displayDetails()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Admin&lt;/code&gt; provides the structure for an administrator, while &lt;code&gt;AdminSystem&lt;/code&gt; implements the administrator's login behavior.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Course&lt;/code&gt; represents the course-related part of the application.&lt;/p&gt;

&lt;p&gt;This separation was important to me because I was trying to move away from writing one large class that handled everything.&lt;/p&gt;

&lt;p&gt;I wanted the classes to have responsibilities of their own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Encapsulation: Keeping Data and Behavior Together
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Student&lt;/code&gt; class was one of the clearest places where I practiced encapsulation.&lt;/p&gt;

&lt;p&gt;Some of the common student information comes from the &lt;code&gt;User&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;fathername&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;rollno&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Student&lt;/code&gt; class provides getters and setters for accessing and modifying this information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;getAge&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The student's courses are stored inside the &lt;code&gt;Student&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;courses&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;coursecount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The courses array is private, so other parts of the application don't directly modify it.&lt;/p&gt;

&lt;p&gt;Instead, the &lt;code&gt;Student&lt;/code&gt; class provides an &lt;code&gt;enrollCourse()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;enrollCourse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;course&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;coursecount&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;courses&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;coursecount&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;course&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;coursecount&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was a useful example for me because it showed that encapsulation is not simply about making variables private.&lt;/p&gt;

&lt;p&gt;The object can also contain the behavior that operates on its data.&lt;/p&gt;

&lt;p&gt;In this case, the &lt;code&gt;Student&lt;/code&gt; object is responsible for managing its own course enrollment and enforcing the two-course limit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Inheritance
&lt;/h2&gt;

&lt;p&gt;I used inheritance in two parts of the application.&lt;/p&gt;

&lt;p&gt;The first relationship is between &lt;code&gt;User&lt;/code&gt; and &lt;code&gt;Student&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// common user information&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// student-specific information&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second is between &lt;code&gt;Admin&lt;/code&gt; and &lt;code&gt;AdminSystem&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Admin&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// administrator structure&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AdminSystem&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Admin&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// administrator implementation&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;User&lt;/code&gt; class contains information that can be shared by different types of users:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;fathername&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;rollno&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of repeating those fields in every user-related class, they can be defined in the parent class.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Student&lt;/code&gt; can then add behavior that is specific to students.&lt;/p&gt;

&lt;p&gt;This was where inheritance started to make more sense to me.&lt;/p&gt;

&lt;p&gt;Previously, I mostly thought of inheritance as a way to reuse code. Working on the project helped me see that it can also represent a relationship between classes.&lt;/p&gt;

&lt;p&gt;A student &lt;strong&gt;is a type of user&lt;/strong&gt;, so having &lt;code&gt;Student&lt;/code&gt; extend &lt;code&gt;User&lt;/code&gt; made sense within the design I was experimenting with.&lt;/p&gt;

&lt;h2&gt;
  
  
  The OOP Concept I Struggled With Most: Abstraction
&lt;/h2&gt;

&lt;p&gt;Abstraction was probably the most interesting part of this project for me because it was the concept I was struggling to understand before I started.&lt;/p&gt;

&lt;p&gt;I knew how to write an abstract class, but knowing the syntax wasn't enough.&lt;/p&gt;

&lt;p&gt;My &lt;code&gt;User&lt;/code&gt; class contains common user information and an abstract method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;fathername&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;rollno&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;displayDetails&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important part here is that &lt;code&gt;User&lt;/code&gt; does not provide the implementation of &lt;code&gt;displayDetails()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The subclass provides it.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;Student&lt;/code&gt; implements the method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;displayDetails&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Student Name : "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Father Name : "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;getFatherName&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Age : "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;getAge&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Roll No :"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;getRollno&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

    &lt;span class="c1"&gt;// display enrolled courses&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used a similar idea for the administrator side:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Admin&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;pin&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;pin&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;AdminSystem&lt;/code&gt; then provides the implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Override&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;pass&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;pin&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;pass&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was the point where abstraction became more practical for me.&lt;/p&gt;

&lt;p&gt;Before building the project, I was mostly thinking about abstraction as a Java feature. After using it, I started to understand it as a way of defining common structure while leaving certain behavior for subclasses to implement.&lt;/p&gt;

&lt;p&gt;I wouldn't say this project made me an expert in abstraction, but it changed the way I thought about it.&lt;/p&gt;

&lt;p&gt;Instead of asking only &lt;strong&gt;"How do I create an abstract class?"&lt;/strong&gt;, I started asking &lt;strong&gt;"What should be common, and what should be implemented differently by each subclass?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That was a much more useful question.&lt;/p&gt;

&lt;h2&gt;
  
  
  Seeing Polymorphism in the Project
&lt;/h2&gt;

&lt;p&gt;Polymorphism was another concept I practiced through the abstract classes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;User&lt;/code&gt; declares:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;displayDetails&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;while &lt;code&gt;Student&lt;/code&gt; provides the implementation.&lt;/p&gt;

&lt;p&gt;Similarly, &lt;code&gt;Admin&lt;/code&gt; declares:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;pin&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and &lt;code&gt;AdminSystem&lt;/code&gt; overrides the method.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;@Override&lt;/code&gt; annotation makes that relationship clear:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Override&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;pass&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// implementation&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What helped me was seeing that the parent class can define a behavior that subclasses are expected to provide, while each subclass can implement that behavior according to its own needs.&lt;/p&gt;

&lt;p&gt;This made polymorphism easier to understand than when I was learning it only from definitions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling Invalid Input With Exceptions
&lt;/h2&gt;

&lt;p&gt;Exception handling was another important part of the project.&lt;/p&gt;

&lt;p&gt;Because the application is console-based, it receives a lot of input from the user. Some of that input needs to be converted from strings into integers.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;select&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parseInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nextLine&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a user enters something that cannot be converted into an integer, a &lt;code&gt;NumberFormatException&lt;/code&gt; can occur.&lt;/p&gt;

&lt;p&gt;I handle this with a &lt;code&gt;try-catch&lt;/code&gt; block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;select&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parseInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nextLine&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

    &lt;span class="c1"&gt;// menu processing&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NumberFormatException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Selection cannot be non-numeric"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also use exception handling when registering a student:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nextLine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;fathername&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nextLine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parseInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nextLine&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;rollno&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parseInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nextLine&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

    &lt;span class="c1"&gt;// register student&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NumberFormatException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="s"&gt;"---- (Age - rollno ) cannot be non numeric ----"&lt;/span&gt;
    &lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="s"&gt;"---- Unexpected error occurred ----"&lt;/span&gt;
    &lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was useful because exception handling was no longer just something I had to memorize for an exam.&lt;/p&gt;

&lt;p&gt;I could see exactly why it was necessary.&lt;/p&gt;

&lt;p&gt;A console application depends on user input, and users don't always enter what the program expects. Handling the exception allows the program to respond with a message instead of immediately terminating.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the Objects Communicate
&lt;/h2&gt;

&lt;p&gt;The different classes work together through their objects.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Main&lt;/code&gt; creates a &lt;code&gt;SystemManager&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;SystemManager&lt;/span&gt; &lt;span class="n"&gt;manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SystemManager&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The manager maintains the student collection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;studentcount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a student is registered, the manager creates a &lt;code&gt;Student&lt;/code&gt; object and assigns its information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;studentcount&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;studentcount&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="na"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;studentcount&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="na"&gt;setRollno&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rollno&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;studentcount&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="na"&gt;setAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;studentcount&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="na"&gt;setFatherName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fathername&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;studentcount&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a course needs to be assigned, the manager finds the relevant student and calls the student's enrollment method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;enrolled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;enrollCourse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Student&lt;/code&gt; object then handles the enrollment itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;coursecount&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I liked this part of the design because the manager coordinates the operation, while the &lt;code&gt;Student&lt;/code&gt; object handles behavior that belongs specifically to the student.&lt;/p&gt;

&lt;p&gt;The administrator side works in a similar way.&lt;/p&gt;

&lt;p&gt;The application creates an &lt;code&gt;AdminSystem&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;AdminSystem&lt;/span&gt; &lt;span class="n"&gt;admin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AdminSystem&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and delegates authentication to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nc"&gt;Checklogin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;admin&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;login&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pin&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Working with these relationships helped me understand that OOP is not only about creating classes. The more important part is deciding &lt;strong&gt;how those objects should interact&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenges I Faced
&lt;/h2&gt;

&lt;p&gt;The biggest challenge wasn't writing individual Java statements. It was trying to design the application using OOP concepts while I was still learning what good OOP design actually meant.&lt;/p&gt;

&lt;p&gt;Abstraction was the clearest example.&lt;/p&gt;

&lt;p&gt;I knew that I could create an abstract class, but I didn't initially understand why I should.&lt;/p&gt;

&lt;p&gt;Building &lt;code&gt;User&lt;/code&gt; and &lt;code&gt;Admin&lt;/code&gt; as abstract classes forced me to think about what should be common and what should be implemented by subclasses.&lt;/p&gt;

&lt;p&gt;I also had to think about where particular behavior should live.&lt;/p&gt;

&lt;p&gt;For example, course enrollment is performed through:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;enrollCourse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The operation belongs to the &lt;code&gt;Student&lt;/code&gt; class rather than being implemented entirely inside &lt;code&gt;SystemManager&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That decision helped me understand the idea of giving an object responsibility for behavior related to its own data.&lt;/p&gt;

&lt;p&gt;I also learned that getting a program to work and designing it well are not always the same thing.&lt;/p&gt;

&lt;p&gt;The project works as a learning application, but there are several parts I would design differently if I built it again.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Would Improve
&lt;/h2&gt;

&lt;p&gt;The current project uses fixed-size arrays:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the student has a fixed course capacity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;courses&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These choices were enough for the project I was building at the time, but they are restrictive.&lt;/p&gt;

&lt;p&gt;If I rebuilt the application, I would consider using &lt;code&gt;ArrayList&lt;/code&gt; for the students and courses.&lt;/p&gt;

&lt;p&gt;That would make the application more flexible and remove the fixed limits.&lt;/p&gt;

&lt;p&gt;I would also revisit the &lt;code&gt;Course&lt;/code&gt; design.&lt;/p&gt;

&lt;p&gt;The current implementation uses static arrays for course names and codes. If I were redesigning the application today, I would think more carefully about representing individual courses as objects and how those objects should relate to students.&lt;/p&gt;

&lt;p&gt;The input validation could also be improved so that invalid input is handled consistently throughout the application.&lt;/p&gt;

&lt;p&gt;Most importantly, I would spend more time refining the class responsibilities.&lt;/p&gt;

&lt;p&gt;That is one of the things I understand better now than when I first built the project. OOP design isn't just about using inheritance, abstract classes, and getters and setters because they are available in Java. The real challenge is deciding whether those tools actually make the application easier to understand and maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learned From the Project
&lt;/h2&gt;

&lt;p&gt;The biggest lesson from this project was that knowing the definition of an OOP concept is different from knowing how to use it.&lt;/p&gt;

&lt;p&gt;I could read that encapsulation means bundling data and behavior, that inheritance allows one class to inherit from another, or that abstraction hides implementation details.&lt;/p&gt;

&lt;p&gt;But implementing those concepts in a real application forced me to think about them differently.&lt;/p&gt;

&lt;p&gt;Abstraction was particularly valuable because it was the concept I found confusing at the beginning.&lt;/p&gt;

&lt;p&gt;After working with &lt;code&gt;User&lt;/code&gt; and &lt;code&gt;Admin&lt;/code&gt; as abstract classes, I started to understand why a parent class might define common structure while leaving specific behavior to subclasses.&lt;/p&gt;

&lt;p&gt;I also became more comfortable with exception handling because I could see a real reason for catching exceptions instead of simply learning the syntax of &lt;code&gt;try&lt;/code&gt; and &lt;code&gt;catch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Another important lesson was about application design.&lt;/p&gt;

&lt;p&gt;When you build a small program, it is tempting to put everything in one place because that can be faster initially. But as soon as the application contains several different responsibilities, separating those responsibilities becomes much more useful.&lt;/p&gt;

&lt;p&gt;This project helped me start thinking in terms of objects, responsibilities, and relationships instead of only thinking about individual lines of code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I built the Student Course Registration System while I was learning Java OOP because I wanted to practice the concepts in an actual application rather than learning them only through small examples.&lt;/p&gt;

&lt;p&gt;The project gave me a practical way to work with inheritance, encapsulation, abstraction, polymorphism, and exception handling.&lt;/p&gt;

&lt;p&gt;The most important part for me was abstraction.&lt;/p&gt;

&lt;p&gt;Initially, I understood the syntax of abstract classes, but I wasn't sure why I needed them. Building the &lt;code&gt;User&lt;/code&gt; and &lt;code&gt;Admin&lt;/code&gt; classes helped me understand abstraction as a design concept: common structure can be defined in a parent class while specific behavior is left for subclasses.&lt;/p&gt;

&lt;p&gt;The project also showed me that OOP design takes practice. Some of the decisions I made were appropriate for a small learning project, while others are areas I would change today, such as replacing fixed-size arrays with &lt;code&gt;ArrayList&lt;/code&gt; and reconsidering how courses are represented.&lt;/p&gt;

&lt;p&gt;I don't consider that a weakness of the project. For me, it is part of the learning process.&lt;/p&gt;

&lt;p&gt;Building something once gives me the opportunity to look back at the code later and understand what I would do differently.&lt;/p&gt;

&lt;p&gt;That is one of the main reasons I enjoy building projects while learning a technology: the code becomes more than an exercise. It becomes a record of how my understanding developed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Repository
&lt;/h2&gt;

&lt;p&gt;The complete source code for this project is available on GitHub:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Student Course Registration System — Java OOP&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Hamadullah-Odho/StudentCourseRegistrationSystem-JAVA-OOP" rel="noopener noreferrer"&gt;https://github.com/Hamadullah-Odho/StudentCourseRegistrationSystem-JAVA-OOP&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How I Built a Java Hotel Reservation System with JDBC and MySQL</title>
      <dc:creator>HAMAD ULLAH</dc:creator>
      <pubDate>Sun, 27 Sep 2026 05:30:19 +0000</pubDate>
      <link>https://dev.to/hamad_19/how-i-built-a-java-hotel-reservation-system-with-jdbc-and-mysql-fl6</link>
      <guid>https://dev.to/hamad_19/how-i-built-a-java-hotel-reservation-system-with-jdbc-and-mysql-fl6</guid>
      <description>&lt;h1&gt;
  
  
  How I Built a Java Hotel Reservation System with JDBC and MySQL
&lt;/h1&gt;

&lt;p&gt;When I first started learning JDBC, one of the things I struggled with was understanding how a Java application actually communicates with a database.&lt;/p&gt;

&lt;p&gt;I already understood the basics of Java and SQL separately, but connecting them together felt different. I wanted to move beyond simple Java exercises and build something where I had to store information, retrieve it, update it, and delete it from a real database.&lt;/p&gt;

&lt;p&gt;That led me to build a console-based &lt;strong&gt;Hotel Reservation System using Java, JDBC, and MySQL&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The project started as a learning exercise, but I also wanted to use it to practice writing Java code in a more organized way. Instead of putting all the database logic inside one class, I separated the application into different components for the model, service logic, database operations, and connection handling.&lt;/p&gt;

&lt;p&gt;In this article, I'll walk through how the project is structured, how Java communicates with MySQL through JDBC, how I implemented CRUD operations, and some of the problems I encountered while building it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Built This Project
&lt;/h2&gt;

&lt;p&gt;At the time I built this project, I was relatively new to JDBC.&lt;/p&gt;

&lt;p&gt;I wanted to practice database connectivity with a Java application, so I decided to give myself a practical challenge instead of only reading about JDBC concepts.&lt;/p&gt;

&lt;p&gt;One of my biggest questions was simple:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does JDBC actually talk to the database?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I understood that Java could execute SQL queries, but I wanted to understand the complete process. A Java program needs to establish a connection, send a SQL statement to the database, receive the result, and then work with that result inside the application.&lt;/p&gt;

&lt;p&gt;Building a reservation system gave me a reason to go through that process repeatedly.&lt;/p&gt;

&lt;p&gt;I chose a hotel reservation system because it resembles a real-world application. A reservation system needs to store customer information and allow that information to be created, viewed, modified, and removed.&lt;/p&gt;

&lt;p&gt;That made it a good project for practicing CRUD operations while learning JDBC.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Overview
&lt;/h2&gt;

&lt;p&gt;The application is a console-based Java program.&lt;/p&gt;

&lt;p&gt;A user can interact with the application through the console and perform operations such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating a hotel reservation&lt;/li&gt;
&lt;li&gt;Viewing existing reservations&lt;/li&gt;
&lt;li&gt;Updating reservation information&lt;/li&gt;
&lt;li&gt;Deleting a reservation&lt;/li&gt;
&lt;li&gt;Working with reservation dates and times&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The application stores the reservation information in a MySQL database.&lt;/p&gt;

&lt;p&gt;The main technologies I used were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Java&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JDBC&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MySQL&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Java OOP&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Java Date and Time API&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The database contains a &lt;code&gt;reservations&lt;/code&gt; table with information such as the customer's name, room number, email, phone number, reservation date, and reservation time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Structure
&lt;/h2&gt;

&lt;p&gt;One thing I wanted to improve while building the project was the organization of the code.&lt;/p&gt;

&lt;p&gt;Instead of putting everything into &lt;code&gt;Main.java&lt;/code&gt;, I separated different responsibilities into different packages and classes.&lt;/p&gt;

&lt;p&gt;The project has this general structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
├── app/
│   └── Main.java
│
├── model/
│   └── Reservation.java
│
├── services/
│   └── HotelReservationService.java
│
├── dao/
│   └── HotelReservationDB.java
│
├── connection/
│   └── DBConnection.java
│
└── util/
    └── DateAndTime.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each component has a specific responsibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;Main&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Main.java&lt;/code&gt; is the entry point of the application. It handles the application flow and user interaction.&lt;/p&gt;

&lt;p&gt;I did not want this class to contain all of the database code because that would make it difficult to maintain as the project grew.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;Reservation&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Reservation&lt;/code&gt; class represents a reservation in the application.&lt;/p&gt;

&lt;p&gt;It contains information such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customer name&lt;/li&gt;
&lt;li&gt;Phone number&lt;/li&gt;
&lt;li&gt;Room number&lt;/li&gt;
&lt;li&gt;Email&lt;/li&gt;
&lt;li&gt;Reservation date&lt;/li&gt;
&lt;li&gt;Reservation time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This gives the database record a corresponding Java object that the rest of the application can work with.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;HotelReservationService&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The service class handles the application's reservation-related operations.&lt;/p&gt;

&lt;p&gt;This creates a separation between the user interface and the lower-level database operations.&lt;/p&gt;

&lt;p&gt;For example, the application can request that a reservation be created without needing the main application flow to know exactly how the SQL &lt;code&gt;INSERT&lt;/code&gt; statement is constructed.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;HotelReservationDB&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This class is responsible for database operations.&lt;/p&gt;

&lt;p&gt;It contains the JDBC code used to execute SQL queries against the &lt;code&gt;reservations&lt;/code&gt; table.&lt;/p&gt;

&lt;p&gt;Keeping this code separate made the project easier for me to understand because I could identify exactly where database-related operations belonged.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;DBConnection&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The database connection class is responsible for establishing the connection between the Java application and MySQL.&lt;/p&gt;

&lt;p&gt;This is where JDBC becomes the bridge between my Java code and the relational database.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;DateAndTime&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;I also separated date and time handling into its own utility class.&lt;/p&gt;

&lt;p&gt;This became useful because handling dates and times was one of the areas that initially caused me problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  How JDBC Connects Java to MySQL
&lt;/h2&gt;

&lt;p&gt;The part I was most interested in learning was the communication between Java and MySQL.&lt;/p&gt;

&lt;p&gt;JDBC, or Java Database Connectivity, provides the API that Java applications can use to work with relational databases.&lt;/p&gt;

&lt;p&gt;The basic flow in my project is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Main
  ↓
HotelReservationService
  ↓
HotelReservationDB
  ↓
DBConnection
  ↓
JDBC
  ↓
MySQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the application needs to perform a database operation, the request eventually reaches the database layer.&lt;/p&gt;

&lt;p&gt;The database connection is established using JDBC, and SQL statements are then executed through JDBC classes such as &lt;code&gt;PreparedStatement&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Conceptually, the process looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Java Application
       |
       | JDBC
       ↓
Database Connection
       |
       | SQL Query
       ↓
     MySQL
       |
       | Result
       ↓
Java Application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding this flow was one of the main reasons I built the project.&lt;/p&gt;

&lt;p&gt;Before working on it, I knew that JDBC was used for database connectivity, but building the application helped me understand what that actually meant in practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Designing the Reservation Table
&lt;/h2&gt;

&lt;p&gt;The database side of the project is intentionally simple because the main purpose was to practice Java-to-database communication.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;reservations&lt;/code&gt; table contains fields such as:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Column&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Identifies the reservation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores the customer's name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;room&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores the room number&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;email&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores the customer's email&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;phone&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores the customer's phone number&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;date&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores the reservation date&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;time&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores the reservation time&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This structure gives the Java application enough information to perform the basic operations required by the reservation system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Reservation
&lt;/h2&gt;

&lt;p&gt;The first major database operation is creating a reservation.&lt;/p&gt;

&lt;p&gt;The application collects the reservation information and sends it to the database using an SQL &lt;code&gt;INSERT&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;The query follows this pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;reservations&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The question marks are parameters that are supplied through &lt;code&gt;PreparedStatement&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This approach is different from building an SQL query by concatenating user input directly into the SQL string.&lt;/p&gt;

&lt;p&gt;For example, rather than constructing a query by joining strings together, the application creates a prepared statement and assigns values to its parameters.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PreparedStatement&lt;/span&gt; &lt;span class="n"&gt;statement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;prepareStatement&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;statement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;statement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;statement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;statement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact parameter types depend on the data being sent to MySQL.&lt;/p&gt;

&lt;p&gt;This was one of the JDBC concepts that became much clearer after actually using it in a project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading Reservations
&lt;/h2&gt;

&lt;p&gt;Creating data is only one part of a database application.&lt;/p&gt;

&lt;p&gt;The application also needs to retrieve existing reservations.&lt;/p&gt;

&lt;p&gt;For this, I used a SQL &lt;code&gt;SELECT&lt;/code&gt; query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;reservations&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JDBC returns the query results through a &lt;code&gt;ResultSet&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The basic idea is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Execute SELECT query
        ↓
Receive ResultSet
        ↓
Read each record
        ↓
Display/process the information
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;ResultSet&lt;/code&gt; allows the Java application to move through the returned records and retrieve individual column values.&lt;/p&gt;

&lt;p&gt;This helped me understand an important part of JDBC: the database doesn't simply return a Java object. The application has to read the returned result and work with the data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Updating Reservation Information
&lt;/h2&gt;

&lt;p&gt;The application also supports updating reservation information.&lt;/p&gt;

&lt;p&gt;For example, one of the operations updates a customer's name based on their phone number.&lt;/p&gt;

&lt;p&gt;The SQL operation follows this pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;reservations&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another update operation changes the room associated with a reservation.&lt;/p&gt;

&lt;p&gt;This is where having a separate database class became useful. The SQL statements are kept in the database layer instead of being scattered throughout the application's main flow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deleting a Reservation
&lt;/h2&gt;

&lt;p&gt;The application also supports deleting reservations.&lt;/p&gt;

&lt;p&gt;The delete operation identifies the reservation using information such as the customer's name and phone number.&lt;/p&gt;

&lt;p&gt;The SQL follows this general structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;reservations&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, I used &lt;code&gt;PreparedStatement&lt;/code&gt; to supply the values.&lt;/p&gt;

&lt;p&gt;At this point, the application supported the four basic CRUD operations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create  → INSERT
Read    → SELECT
Update  → UPDATE
Delete  → DELETE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Practicing all four operations in one application gave me a much better understanding of how Java applications interact with relational databases.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Date and Time Problem
&lt;/h2&gt;

&lt;p&gt;One of the problems I encountered while building the project involved dates and times.&lt;/p&gt;

&lt;p&gt;Sending date information to the database and retrieving it correctly was not immediately obvious to me.&lt;/p&gt;

&lt;p&gt;I was still learning JDBC at the time, so I had to look at documentation and experiment with the Java date and time APIs to understand how the values should be represented.&lt;/p&gt;

&lt;p&gt;I used Java's &lt;code&gt;LocalDate&lt;/code&gt; and &lt;code&gt;LocalTime&lt;/code&gt; for handling reservation dates and times.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;LocalTime&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also used &lt;code&gt;DateTimeFormatter&lt;/code&gt; where formatting was necessary.&lt;/p&gt;

&lt;p&gt;This was a useful lesson because database applications often require you to think about how a value is represented on both sides of the connection.&lt;/p&gt;

&lt;p&gt;The Java application has its own types, while MySQL has its own database types. JDBC provides the mechanism for working between them, but you still need to understand what type of data you are sending and receiving.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Used PreparedStatement
&lt;/h2&gt;

&lt;p&gt;Another important lesson from this project was &lt;code&gt;PreparedStatement&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When I first started learning JDBC, I mainly thought of it as a way to execute SQL queries from Java. I didn't initially understand why parameterized statements were important.&lt;/p&gt;

&lt;p&gt;As I worked on the project, I learned that &lt;code&gt;PreparedStatement&lt;/code&gt; provides a safer way to pass values into SQL queries and helps protect applications against &lt;strong&gt;SQL injection&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of constructing SQL statements by directly concatenating user-provided values, I could use parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;reservations&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then Java supplies the actual value separately.&lt;/p&gt;

&lt;p&gt;This separation between the SQL statement and its parameters is an important practice when building database applications.&lt;/p&gt;

&lt;p&gt;It was one of the concepts that made much more sense to me after implementing it rather than simply reading about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Separated the Application Into Layers
&lt;/h2&gt;

&lt;p&gt;Another goal of this project was to practice writing Java code in a more professional structure.&lt;/p&gt;

&lt;p&gt;I could have written the application as one large class containing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User input&lt;/li&gt;
&lt;li&gt;SQL queries&lt;/li&gt;
&lt;li&gt;Database connections&lt;/li&gt;
&lt;li&gt;Business logic&lt;/li&gt;
&lt;li&gt;Output&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That would probably have worked for a small exercise, but it would not have been the kind of structure I wanted to practice.&lt;/p&gt;

&lt;p&gt;Instead, I separated the application into different responsibilities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Main
  ↓
Service
  ↓
DAO / Database Layer
  ↓
Database Connection
  ↓
MySQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This separation makes it easier to identify where a particular piece of functionality belongs.&lt;/p&gt;

&lt;p&gt;For example, if I need to change a SQL query, I know that the database layer is the appropriate place to look.&lt;/p&gt;

&lt;p&gt;If I need to change how reservations are represented inside the Java application, I can work with the model.&lt;/p&gt;

&lt;p&gt;If I need to change the application's reservation-related operations, I can work with the service layer.&lt;/p&gt;

&lt;p&gt;This was part of my attempt to apply OOP principles instead of treating the project as only a collection of SQL statements.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learned From Building It
&lt;/h2&gt;

&lt;p&gt;The biggest benefit of this project was not simply getting a working reservation system.&lt;/p&gt;

&lt;p&gt;It helped me understand the connection between several concepts that I had previously learned separately.&lt;/p&gt;

&lt;p&gt;Before building the project, I could learn Java, SQL, and JDBC individually. While building it, I had to combine them.&lt;/p&gt;

&lt;p&gt;I learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How a Java application establishes a database connection&lt;/li&gt;
&lt;li&gt;How JDBC is used to execute SQL statements&lt;/li&gt;
&lt;li&gt;How &lt;code&gt;PreparedStatement&lt;/code&gt; works&lt;/li&gt;
&lt;li&gt;How to retrieve data using &lt;code&gt;ResultSet&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;How CRUD operations work from a Java application&lt;/li&gt;
&lt;li&gt;How Java date/time values can be handled in a database application&lt;/li&gt;
&lt;li&gt;Why separating responsibilities makes a project easier to organize&lt;/li&gt;
&lt;li&gt;How database code can be separated from application logic&lt;/li&gt;
&lt;li&gt;Why parameterized SQL queries are important for security&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I also learned something less technical: documentation becomes much more useful when you have a specific problem to solve.&lt;/p&gt;

&lt;p&gt;When I encountered problems with dates or database operations, I did not always know the answer immediately. Reading documentation with a specific question in mind made it easier to understand what I needed to change.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Would Improve
&lt;/h2&gt;

&lt;p&gt;This project was built primarily as a learning exercise, so there are several things I would improve if I continued developing it.&lt;/p&gt;

&lt;p&gt;The database design could be expanded beyond a single reservations table. For example, a larger hotel management application could have separate tables for rooms, customers, reservations, and payments.&lt;/p&gt;

&lt;p&gt;The application could also move from a console interface to a graphical or web interface.&lt;/p&gt;

&lt;p&gt;I would also consider adding stronger validation for user input, better error handling, configuration management for database credentials, and more comprehensive testing.&lt;/p&gt;

&lt;p&gt;Another natural step would be replacing some of the manual JDBC infrastructure with a framework such as Spring Boot and exploring how database access can be handled using technologies such as Spring Data JPA.&lt;/p&gt;

&lt;p&gt;However, I would not want to skip the JDBC experience. Learning what happens underneath higher-level frameworks gave me a better understanding of what those frameworks are abstracting away.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I originally built this hotel reservation system because I wanted to practice connecting a Java application to a database while I was still learning JDBC.&lt;/p&gt;

&lt;p&gt;What started as a database connectivity exercise became an opportunity to practice much more: CRUD operations, &lt;code&gt;PreparedStatement&lt;/code&gt;, result handling, Java date and time APIs, OOP, and separating application responsibilities.&lt;/p&gt;

&lt;p&gt;The biggest lesson for me was that concepts become easier to understand when you have to use them to solve an actual problem. Reading about JDBC explained what it was, but building a project forced me to understand how the pieces worked together.&lt;/p&gt;

&lt;p&gt;The project is relatively simple compared with a production hotel management system, but that was not the point. It gave me a practical foundation in Java database development and helped me become more comfortable working with JDBC and relational databases.&lt;/p&gt;

&lt;p&gt;You can find the complete project and source code on my GitHub repository:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/Hamadullah-Odho/HotelReservationSystem-JDBC.git" rel="noopener noreferrer"&gt;https://github.com/Hamadullah-Odho/HotelReservationSystem-JDBC.git&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>jdbc</category>
      <category>java</category>
      <category>mysql</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
