Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Simple Address Book in Java with Source Code - Simple Address Book in Java

Simple Address Book in Java with Source Code

Posted on October 11, 2024October 11, 2024 By Rishabh saini No Comments on Simple Address Book in Java with Source Code

Simple Address Book in Java

Creating an address book application is a fantastic project for beginner Java developers. It introduces core programming concepts like data structures, user input handling, and file I/O. In this blog post, we’ll walk through building a simple address book application that allows users to add, view, and delete contacts.

Project Overview

Our address book will consist of the following features:

  • Add a new contact:A name, phone number, and email can be entered by users.
  • View contacts: Users can see all the contacts stored in the address book.
  • Delete a contact: Users can remove a contact by specifying the name.
  • Save and load contacts: The application will save contacts to a file and load them when started.

Download New Real Time Projects :-Click here

Setting Up the Project

  1. Create a new Java project: Any IDE, such as Eclipse or IntelliJ IDEA, or even a basic text editor, will do.
  2. Create a new Java class named AddressBook.

https://updategadh.com/category/php-project

AddressBook Class Implementation

Here’s a simple implementation of the AddressBook class:

import java.io.*;
import java.util.*;

class Contact {
    String name;
    String phone;
    String email;

    Contact(String name, String phone, String email) {
        this.name = name;
        this.phone = phone;
        this.email = email;
    }

    @Override
    public String toString() {
        return "Name: " + name + ", Phone: " + phone + ", Email: " + email;
    }
}

public class AddressBook {
    private List<Contact> contacts;
    private static final String FILE_NAME = "contacts.txt";

    public AddressBook() {
        contacts = new ArrayList<>();
        loadContacts();
    }

    public void addContact(String name, String phone, String email) {
        contacts.add(new Contact(name, phone, email));
        saveContacts();
    }

    public void viewContacts() {
        if (contacts.isEmpty()) {
            System.out.println("No contacts found.");
            return;
        }
        for (Contact contact : contacts) {
            System.out.println(contact);
        }
    }

    public void deleteContact(String name) {
        Iterator<Contact> iterator = contacts.iterator();
        boolean found = false;
        while (iterator.hasNext()) {
            Contact contact = iterator.next();
            if (contact.name.equalsIgnoreCase(name)) {
                iterator.remove();
                found = true;
                break;
            }
        }
        if (found) {
            saveContacts();
            System.out.println("Contact deleted: " + name);
        } else {
            System.out.println("Contact not found: " + name);
        }
    }

    private void saveContacts() {
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(FILE_NAME))) {
            for (Contact contact : contacts) {
                writer.write(contact.name + "," + contact.phone + "," + contact.email);
                writer.newLine();
            }
        } catch (IOException e) {
            System.out.println("Error saving contacts: " + e.getMessage());
        }
    }

    private void loadContacts() {
        try (BufferedReader reader = new BufferedReader(new FileReader(FILE_NAME))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(",");
                if (parts.length == 3) {
                    contacts.add(new Contact(parts[0], parts[1], parts[2]));
                }
            }
        } catch (IOException e) {
            System.out.println("Error loading contacts: " + e.getMessage());
        }
    }

    public static void main(String[] args) {
        AddressBook addressBook = new AddressBook();
        Scanner scanner = new Scanner(System.in);
        String choice;

        do {
            System.out.println("\nAddress Book Menu:");
            System.out.println("1. Add Contact");
            System.out.println("2. View Contacts");
            System.out.println("3. Delete Contact");
            System.out.println("4. Exit");
            System.out.print("Enter your choice: ");
            choice = scanner.nextLine();

            switch (choice) {
                case "1":
                    System.out.print("Enter name: ");
                    String name = scanner.nextLine();
                    System.out.print("Enter phone: ");
                    String phone = scanner.nextLine();
                    System.out.print("Enter email: ");
                    String email = scanner.nextLine();
                    addressBook.addContact(name, phone, email);
                    break;
                case "2":
                    addressBook.viewContacts();
                    break;
                case "3":
                    System.out.print("Enter name to delete: ");
                    String deleteName = scanner.nextLine();
                    addressBook.deleteContact(deleteName);
                    break;
                case "4":
                    System.out.println("Exiting...");
                    break;
                default:
                    System.out.println("Invalid choice. Please try again.");
            }
        } while (!choice.equals("4"));

        scanner.close();
    }
}
Project Ideas for Java Students
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java
Simple Address Book in Java

Explanation of the Code

  • Contact Class: This class holds the details of a contact—name, phone number, and email.
  • AddressBook Class:
  • List of Contacts: It maintains a list of Contact objects.
  • Methods:
    • addContact(): Adds a new contact and saves the updated list.
    • viewContacts(): Displays all contacts.
    • deleteContact(): Removes a contact and updates the file.
    • saveContacts(): Saves contacts to a text file.
    • loadContacts(): Loads contacts from the text file at startup.
  • Main Method: Gives users the ability to interact with the address book using a straightforward command-line interface.

Running the Program

To run the program, compile the Java file and execute the main method. Follow the prompts to add, view, or delete contacts.

Post Views: 705
code Snippets Tags:address book, address book (software genre), address book application java, address book program in java, address book project in java, address book project in javascript, gui-based address book in java, gui-based address book project in java, how to create an address book in java, java address book, java address book app, java address book application, java address book project, simple address software

Post navigation

Previous Post: The Top 10 Interview Questions with Answers for Placement in the IT Sector
Next Post: Top 15 AI Project Ideas with Java for Aspiring Developers

More Related Articles

Online Food Ordering System in Python with Source Code - How To Online Food Ordering System in Python with Source Code code Snippets
Telegram Bot with Python Using the Telegram API - Telegram Bot with Python Using the Telegram API Telegram Bot with Python Using the Telegram API code Snippets
Simple Library Menu in Java with Source Code - Simple Library Menu in Java Simple Library Menu in Java with Source Code code Snippets

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. Supply Chain Management PHP and CSS
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. F1 Race Road Game in Python Free Source Code
  4. Supplier Management System in Java with Free Code
  5. Create Address Book in Python with Source Code
  6. Contact Management in Python with Source Code

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,613)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,212)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,866)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme