Java Mini Project Tutorial: Build a Simple Student Management System

Java Mini Project Tutorial: Build a Simple Student Management System

Author: Gursehbaj Singh | Blog: DevMode

In this tutorial, we will build a simple Student Management System using Java. This project helps you understand classes, objects, arrays, methods, loops, and basic exception handling. By the end, you'll have a working console-based system to manage students.

Project Overview

Our Student Management System will allow you to:

  • Add new students
  • View all students
  • Search student by ID
  • Delete a student
  • Update student information

Step 1: Create Student Class


class Student {
    int id;
    String name;
    int age;
    
    Student(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }
    
    void display() {
        System.out.println("ID: " + id + ", Name: " + name + ", Age: " + age);
    }
}

Step 2: Main Class & Menu


import java.util.Scanner;
import java.util.ArrayList;

public class StudentManagement {
    static ArrayList students = new ArrayList<>();
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        while(true) {
            System.out.println("\n=== Student Management System ===");
            System.out.println("1. Add Student");
            System.out.println("2. View All Students");
            System.out.println("3. Search Student");
            System.out.println("4. Update Student");
            System.out.println("5. Delete Student");
            System.out.println("6. Exit");
            System.out.print("Enter your choice: ");
            int choice = sc.nextInt();
            
            switch(choice) {
                case 1: addStudent(); break;
                case 2: viewStudents(); break;
                case 3: searchStudent(); break;
                case 4: updateStudent(); break;
                case 5: deleteStudent(); break;
                case 6: System.exit(0);
                default: System.out.println("Invalid choice!"); 
            }
        }
    }

Step 3: Add Student Method


static void addStudent() {
    System.out.print("Enter ID: ");
    int id = sc.nextInt();
    sc.nextLine(); // consume newline
    System.out.print("Enter Name: ");
    String name = sc.nextLine();
    System.out.print("Enter Age: ");
    int age = sc.nextInt();
    
    Student s = new Student(id, name, age);
    students.add(s);
    System.out.println("Student added successfully!");
}

Step 4: View All Students Method


static void viewStudents() {
    if(students.isEmpty()) {
        System.out.println("No students found.");
        return;
    }
    for(Student s : students) {
        s.display();
    }
}

Step 5: Search Student Method


static void searchStudent() {
    System.out.print("Enter Student ID to search: ");
    int id = sc.nextInt();
    for(Student s : students) {
        if(s.id == id) {
            s.display();
            return;
        }
    }
    System.out.println("Student not found!");
}

Step 6: Update Student Method


static void updateStudent() {
    System.out.print("Enter Student ID to update: ");
    int id = sc.nextInt();
    sc.nextLine();
    
    for(Student s : students) {
        if(s.id == id) {
            System.out.print("Enter new Name: ");
            s.name = sc.nextLine();
            System.out.print("Enter new Age: ");
            s.age = sc.nextInt();
            System.out.println("Student updated successfully!");
            return;
        }
    }
    System.out.println("Student not found!");
}

Step 7: Delete Student Method


static void deleteStudent() {
    System.out.print("Enter Student ID to delete: ");
    int id = sc.nextInt();
    
    for(int i = 0; i < students.size(); i++) {
        if(students.get(i).id == id) {
            students.remove(i);
            System.out.println("Student deleted successfully!");
            return;
        }
    }
    System.out.println("Student not found!");
}

Step 8: Run and Test

Compile and run the program. Test adding, viewing, searching, updating, and deleting students. The console menu should guide you.

Step 9: Best Practices

  • Use ArrayList for dynamic storage
  • Use methods to organize code
  • Validate user input to avoid errors
  • Add exception handling if needed

Conclusion

This mini project teaches you how to apply Java basics like classes, objects, arrays, loops, methods, and exception handling in a practical way. You can expand it by adding file storage, GUI, or more features. Practicing mini projects like this will make you a confident Java programmer!

Comments

Popular posts from this blog

Graph Data Structure – Complete Beginner to Advanced Guide with BFS, DFS and Examples

Top Coding Mistakes Beginners Make (And How to Fix Them the Right Way)

Top 10 Free Coding Websites Every Beginner Should Use in 2026