{"id":26463930,"url":"https://github.com/dkoh2018/chatroom_java","last_synced_at":"2026-05-20T19:07:29.655Z","repository":{"id":261541764,"uuid":"866332843","full_name":"dkoh2018/Chatroom_Java","owner":"dkoh2018","description":"Command-line chatroom application for real-time communication with data structure implementations","archived":false,"fork":false,"pushed_at":"2024-11-12T22:54:02.000Z","size":173,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-19T07:17:48.133Z","etag":null,"topics":["arraylist","chatroom","command-line-app","data-structures","hashmap","java","multithreading"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dkoh2018.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-02T04:06:03.000Z","updated_at":"2024-11-12T22:54:06.000Z","dependencies_parsed_at":"2024-11-07T05:32:17.191Z","dependency_job_id":"94e6cef0-933a-4c7d-9701-346150810fdc","html_url":"https://github.com/dkoh2018/Chatroom_Java","commit_stats":null,"previous_names":["dkoh2018/chatroom_java"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dkoh2018/Chatroom_Java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkoh2018%2FChatroom_Java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkoh2018%2FChatroom_Java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkoh2018%2FChatroom_Java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkoh2018%2FChatroom_Java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dkoh2018","download_url":"https://codeload.github.com/dkoh2018/Chatroom_Java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkoh2018%2FChatroom_Java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33271544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-20T15:12:43.734Z","status":"ssl_error","status_checked_at":"2026-05-20T15:12:42.300Z","response_time":356,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arraylist","chatroom","command-line-app","data-structures","hashmap","java","multithreading"],"created_at":"2025-03-19T07:17:51.042Z","updated_at":"2026-05-20T19:07:29.614Z","avatar_url":"https://github.com/dkoh2018.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chatroom Java Project\n\nThis is a simple, command-line chat application I built for our Data Structures class project. It lets you chat with others in real-time, create your own chat rooms, and even have private conversations. I'm excited to share how I used different data structures to make this app work!\n\n## Table of Contents\n\n- [Features](#features)\n- [How to Run the App](#how-to-run-the-app)\n- [How to Use the Chat App](#how-to-use-the-chat-app)\n- [Data Structures Used](#data-structures-used)\n- [Notes](#notes)\n- [Conclusion](#conclusion)\n\n## Features\n\n- **User Registration**: Set your username upon starting the app.\n- **Public and Private Chat Rooms**: Create public chat rooms with passwords or initiate private, invite-only chats.\n- **Real-Time Messaging**: Engage in live conversations with peers in the same room.\n- **Private Chats**: Start one-on-one conversations with any online user.\n- **Online Users List**: View who else is online and available to chat.\n- **Multi-User Support**: The server can handle multiple clients concurrently.\n\n## How to Run the App\n\nBefore getting started, ensure that you have Java (JDK 17 or higher) and Maven installed on your machine.\n\n1. **Clone the Repository**\n\n   Download the project to your local machine:\n\n   ```bash\n   git clone https://github.com/dkoh2018/Chatroom_Java.git\n   ```\n\n2. **Navigate to the Project Directory**\n\n   Move into the project folder:\n\n   ```bash\n   cd Chatroom_Java\n   ```\n\n3. **Build the Project**\n\n   Use Maven to build the project:\n\n   ```bash\n   mvn clean package\n   ```\n\n   This command compiles the code and packages it into a JAR file located in the `target` directory.\n\n4. **Run the Application**\n\n   Start the chat application by running the JAR file:\n\n   ```bash\n   java -jar target/chatapplication-1.0-SNAPSHOT.jar\n   ```\n\n   If no server is running, the application will start one automatically; otherwise, it will connect as a client.\n\n## How to Use the Chat App\n\n1. **Enter Your Username**\n\n   Upon starting the app, you'll be prompted to enter a username. This will be your display name in the chat.\n\n2. **Main Menu**\n\n   After entering your username, the main menu will appear:\n\n   ```\n   ----------------------------\n             Main Menu\n   ----------------------------\n    1. Create a new chatroom\n    2. Join an existing chatroom\n    3. List online users\n    4. Start a private chat with a user\n   /exit - Exit the application\n   ----------------------------\n   Enter your choice:\n   ```\n\n3. **Creating a Chat Room**\n\n   - Select option `1` to create a new chat room.\n   - Provide a name for your chat room when prompted.\n   - Set a password for your chat room.\n   - The chat room will be created, and you will receive its unique ID.\n\n4. **Joining a Chat Room**\n\n   - Select option `2` to join an existing chat room.\n   - A list of available chat rooms will be displayed.\n   - Enter the chat room ID or name when prompted.\n   - If the chat room is password-protected, enter the password when asked.\n\n5. **Chatting**\n\n   - Inside a chat room, type your messages and press **Enter** to send.\n   - Use `/exit` to leave the chat room and return to the main menu.\n\n6. **Listing Online Users**\n\n   - Select option `3` to view the list of online users.\n\n7. **Starting a Private Chat**\n\n   - Select option `4` to initiate a private chat.\n   - Enter the username of the person you wish to chat with.\n   - An invitation will be sent to them for a private chat room.\n   - They can accept or decline your invitation.\n   - If accepted, both of you will enter a private chat room.\n\n8. **Accepting or Declining Invitations**\n\n   - If you receive an invitation for a private chat, you can accept it by typing `/accept username` or decline it by typing `/decline username` at any time.\n\n## Data Structures Used\n\nSince this is a Data Structures class project, I want to highlight how I utilized different data structures to build the application.\n\n### 1. **HashMap**\n\n- **Purpose**: To store and quickly access data using unique keys.\n- **Usage**:\n\n  - **Chat Rooms Management**:\n\n    ```java\n    Map\u003cString, ChatRoom\u003e chatRooms = new HashMap\u003c\u003e();\n    ```\n\n    - **Description**: Maintains a mapping of chat room IDs to `ChatRoom` objects, enabling quick retrieval of a chat room using its unique ID.\n\n  - **Chat Room IDs Mapping**:\n\n    ```java\n    Map\u003cChatRoom, String\u003e chatRoomIDs = new HashMap\u003c\u003e();\n    ```\n\n    - **Description**: Allows retrieval of a chat room's ID when only the `ChatRoom` object is available, useful for displaying the ID to users.\n\n  - **Online Users Tracking**:\n\n    ```java\n    Map\u003cString, ClientHandler\u003e onlineUsers = new HashMap\u003c\u003e();\n    ```\n\n    - **Description**: Keeps track of online users by mapping usernames to their respective `ClientHandler` instances, facilitating message routing.\n\n  - **Pending Invitations**:\n\n    ```java\n    Map\u003cString, String\u003e pendingInvitations = new HashMap\u003c\u003e();\n    ```\n\n    - **Description**: Stores pending chat invitations, mapping the inviter's username to the chat room name.\n\n### 2. **HashSet**\n\n- **Purpose**: To store a collection of unique items with fast lookup times.\n- **Usage**:\n\n  - **Allowed Users in Private Chat Rooms**:\n\n    ```java\n    Set\u003cString\u003e allowedUsers = new HashSet\u003c\u003e();\n    ```\n\n    - **Description**: For private chat rooms, this set maintains the usernames of users who are permitted to join, ensuring no duplicates and quick membership checks.\n\n### 3. **ArrayList**\n\n- **Purpose**: To maintain an ordered list of items where duplicates are allowed.\n- **Usage**:\n\n  - **Chat Room Members List**:\n\n    ```java\n    List\u003cClientHandler\u003e members = new ArrayList\u003c\u003e();\n    ```\n\n    - **Description**: Stores the list of clients currently in a chat room, allowing for message broadcasting to all members.\n\n### 4. **Random Number Generator**\n\n- **Purpose**: To generate unique identifiers.\n- **Usage**:\n\n  - **Generating Unique Chat Room IDs**:\n\n    ```java\n    Random random = new Random();\n    ```\n\n    - **Description**: Generates unique 6-digit IDs for chat rooms, ensuring each room can be uniquely identified.\n\n### 5. **Synchronized Methods**\n\n- **Purpose**: To manage concurrent access to shared resources in a multi-threaded environment.\n- **Usage**:\n\n  - **Managing Chat Room Members**:\n\n    - Methods like `addMember`, `removeMember`, and `broadcastMessage` in the `ChatRoom` class are synchronized to prevent concurrent modification issues when users join or leave.\n\n  - **Server Data Access**:\n\n    - In the `ChatServer` class, methods that modify or access shared data structures are synchronized to maintain data consistency during concurrent operations.\n\n### 6. **Message Handling System**\n\n- **Purpose**: To manage message storage, delivery, and processing.\n- **Usage**:\n\n  - **Message Queue**:\n\n    ```java\n    List\u003cClientHandler\u003e members = new ArrayList\u003c\u003e();\n    ```\n\n    - **Description**: This list stores the current members of a chat room, enabling O(n) broadcasting of messages to all participants. When a user sends a message, it is broadcasted to every member of the chat room.\n\n  - **Message Broadcasting**:\n\n    ```java\n    public synchronized void broadcastMessage(String message, ClientHandler sender) {\n        if (message == null) {\n            throw new NullPointerException(\"Message cannot be null\");\n        }\n        for (ClientHandler member : members) {\n            if (sender == null || member != sender) {\n                member.sendMessage(message);\n            }\n        }\n    }\n    ```\n\n    - **Description**: This synchronized method ensures that messages are delivered to all room members except the sender, in a thread-safe manner. This prevents concurrent modification issues during broadcasts and ensures consistency in message delivery. Broadcasting messages to all members takes O(n) time, where n is the number of members in the chat room.\n\n### 7. **Defensive Copies**\n\n- **Purpose**: To prevent external modification of internal data structures.\n- **Usage**:\n\n  - **Returning Data to Clients**:\n\n    - Methods like `listChatRooms` and `getOnlineUsers` return new copies of the data structures to prevent clients from modifying the server's internal state.\n\n## Notes\n\n- **Integrated Server and Client**: The application can act as both a server and a client. If no server is detected when the app starts, it will automatically start one.\n- **Testing**: To test the chat functionality, you can open multiple instances of the application on your computer.\n- **CLI Interface**: The application runs entirely in the terminal.\n- **Multithreading**: Each client connection is handled in its own thread, allowing multiple users to chat simultaneously without interference.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkoh2018%2Fchatroom_java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdkoh2018%2Fchatroom_java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkoh2018%2Fchatroom_java/lists"}