A Java-based client-server chat system built using Sockets and Threads, where multiple clients can connect to a central server and exchange messages in real time. Supports broadcasting, private messaging, and concurrency handling
1. 🎯 Overview
2. 📸 Screenshot
3. ✨ Features
12. 👥 Contributors
14. 📄 License
17. 🏆 Conclusion
The Multithreaded Chat Application is a scalable, full-stack Java web application that enables real-time communication between multiple users. It showcases advanced concepts including:
- Concurrent programming with Java thread pools
- Database integration using JDBC and DAO pattern
- Web development with Servlets and JSP
- Socket programming for real-time messaging
- Modern UI features including dark/light theme toggle
Built as a comprehensive demonstration of Java enterprise application development, this project is ideal for academic portfolios, coding assessments, and real-world deployment scenarios.
- ✅ Real-time Messaging - Instant message delivery using socket connections
- ✅ Broadcast Chat - Send messages to all connected users
- ✅ Private Messaging - Direct messages to specific users
- ✅ User Authentication - Secure login and registration system
- ✅ Session Management - HTTP session tracking for web users
- ✅ Persistent Storage - Messages and users stored in MySQL database
- 🌓 Dark/Light Theme - Toggle between themes with localStorage persistence
- 🔐 Password Security - Hashed password storage
- 📱 Responsive Design - Mobile-friendly web interface
- 🧪 Unit Testing - JUnit test cases for critical components
- 🔌 Dual Interface - Web UI and console-based client
- ⚡ Scalable Architecture - Thread pool handling 50+ concurrent connections
- Multithreading: ExecutorService with fixed thread pool
- Thread Safety: ConcurrentHashMap for client management
- Exception Handling: Comprehensive error handling and logging
- MVC Pattern: Clear separation of concerns
- DAO Pattern: Database abstraction layer
| Layer | Technology | Version | Purpose |
|---|---|---|---|
| Backend | Java | 11+ | Core application logic |
| Web Framework | Servlets | 4.0 | HTTP request handling |
| View Layer | JSP | 2.3 | Dynamic web pages |
| Database | MySQL | 8.0 | Data persistence |
| JDBC | MySQL Connector | 8.0.33 | Database connectivity |
| Build Tool | Maven | 3.6+ | Dependency management |
| Server | Apache Tomcat | 9.0 | Web application server |
| Testing | JUnit | 4.13 | Unit testing |
| Frontend | HTML5, CSS3, JavaScript | - | User interface |
Ensure you have the following installed:
-
Java JDK 11+ java -version
-
Apache Maven 3.6+ mvn -version
-
MySQL Server 8.0+ mysql --version
-
Apache Tomcat 9.0+
git clone https://github.com/Ayushsingh299/Multithreaded-Chat-Application.git cd Multithreaded-Chat-Application
Login to MySQL mysql -u root -p
Create database and tables source database/schema.sql
Or manually: CREATE DATABASE chatapp; USE chatapp; -- Paste contents of schema.sql
Edit src/main/java/com/chat/dao/ConnectionPool.java:
private static final String DB_URL = "jdbc:mysql://localhost:3306/chatapp"; private static final String DB_USER = "root"; private static final String DB_PASSWORD = "YOUR_PASSWORD_HERE"; // ⬅️ Change this!
mvn clean install
This will:
- ✅ Compile all Java files
- ✅ Run unit tests
- ✅ Package as WAR file
- ✅ Output:
target/multithreaded-chat-application.war
Option A: Manual cp target/multithreaded-chat-application.war $CATALINA_HOME/webapps/
Option B: Tomcat Manager
- Go to
http://localhost:8080/manager - Upload WAR file
Linux/Mac $CATALINA_HOME/bin/startup.sh
Windows %CATALINA_HOME%\bin\startup.bat
- Open browser and navigate to: http://localhost:8080/multithreaded-chat-application/
- Login with sample credentials:
- Username:
admin| Password:admin123 - Username:
demo| Password:demo123
- Or register a new account and start chatting!
Navigate to compiled classes cd target/classes
Start socket server java com.chat.server.ChatServer
Expected output: ✓ Chat Server started on port 9999 ✓ Waiting for connections...
In another terminal java com.chat.client.ChatClient
Commands:
- Type any message to broadcast to all
/private username message- Send private message/help- Show available commands/quit- Disconnect
- Click "Register here" on login page
- Fill in:
- Username (min 3 characters)
- Email (valid format)
- Password (min 6 characters)
- Full Name (optional)
- Click "Register"
- Redirected to login page on success
- Enter username and password
- Click "Login"
- On success, redirected to chat interface
- Session created (30 min timeout)
- Type message in input box at bottom
- Press Enter or click "Send"
- Messages appear in chat window:
- Your messages: Right side (green)
- Other users: Left side (blue)
- Real-time updates (simulated in demo)
- Click 🌙 moon icon → Switch to dark mode
- Click ☀️ sun icon → Switch to light mode
- Preference saved in browser localStorage
- Click "Logout" in chat header
- Session invalidated
- Redirected to login page
CREATE TABLE users ( user_id INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(50) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL, full_name VARCHAR(100), is_online BOOLEAN DEFAULT FALSE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, INDEX idx_username (username), INDEX idx_email (email) ) ENGINE=InnoDB;
CREATE TABLE messages ( message_id INT PRIMARY KEY AUTO_INCREMENT, sender_id INT NOT NULL, recipient_id INT NULL, -- NULL for broadcast content TEXT NOT NULL, sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (sender_id) REFERENCES users(user_id) ON DELETE CASCADE, INDEX idx_sender (sender_id), INDEX idx_sent_at (sent_at) ) ENGINE=InnoDB;
| Endpoint | Method | Parameters | Response | Description |
|---|---|---|---|---|
/login |
GET | - | login.jsp | Display login form |
/login |
POST | username, password |
Redirect to chat | Authenticate user |
/register |
GET | - | register.jsp | Display registration form |
/register |
This project was developed as part of a collaborative team effort for academic coursework, demonstrating full-stack Java development skills.
Ayush Singh Backend & Database 🔧 Socket Server | 💾 JDBC/DAO | 🧵 Multithreading |
Aayush Gaira Frontend & Web Integration 🌐 JSP/Servlets | 📱 Responsive UI | 🎨 HTML/CSS |
Rehan Chaudhary UI/UX Design & Testing 🎨 Theme Design | 🧪 Testing | 📝 Documentation |
| Contributor | Primary Responsibilities | Technologies |
|---|---|---|
| Ayush Singh | Socket server architecture, multithreading implementation, database schema design, JDBC integration, DAO pattern implementation | Java, MySQL, JDBC, Multithreading, Sockets |
| Aayush Gaira | Servlet development, JSP page creation, web application flow, session management, MVC implementation | Java Servlets, JSP, HTML, JavaScript |
| Rehan Chaudhary | CSS styling, dark/light theme, UI components, user experience design, documentation, testing | CSS3, JavaScript, UI/UX Design |
Java ████████████████████░░ 40% (Server, DAO, Models, Servlets)
JSP/HTML ██████████░░░░░░░░░░░ 25% (Web pages, UI templates)
CSS ██████░░░░░░░░░░░░░░ 15% (Styling, Layout, Themes)
JavaScript ██████░░░░░░░░░░░░░░ 15% (Client-side logic, UI actions)
SQL ██░░░░░░░░░░░░░░░░░ 5% (Database operations)
- WebSocket Integration - Real-time bidirectional communication
- File Sharing - Upload and share images, documents
- Emoji Picker - Enhanced messaging with emojis and reactions
- Group Chat Rooms - Create and join multiple chat rooms
- User Presence - Online/offline/away status indicators
- Message Notifications - Desktop and browser notifications
- Message History - Load and search previous messages
- User Profiles - Avatar, bio, status customization
- Voice/Video Calls - WebRTC integration
- Message Encryption - End-to-end encryption (E2EE)
- Mobile App - Android/iOS native applications
- Admin Dashboard - User management, analytics
- Read Receipts - Message delivery and read status
- Typing Indicators - Show when users are typing
- Implement BCrypt for password hashing
- Add Redis for session management and caching
- Implement connection pooling with HikariCP
- Add comprehensive logging (Log4j/SLF4J)
- Implement rate limiting and DDoS protection
- Add API documentation with Swagger
- Implement CI/CD pipeline (Jenkins/GitHub Actions)
- Add load testing (JMeter)
- Dockerize the application
- Deploy to cloud (AWS/Azure/GCP)
MIT License
Copyright (c) 2025 Ayush Singh, Aayush Gaira, Rehan Chaudhary
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Report Issues: GitHub Issues
- Pull Requests: Contribute
- Discussions: GitHub Discussions
- Ayush Singh - @Ayushsingh299
- Aayush Gaira - @Aayush-Gaira
- Rehan Chaudhary - @Rehan-Chaudhary
This project was developed as part of a Java Web Development course, demonstrating:
✅ Core Java Concepts
- Object-Oriented Programming (Encapsulation, Inheritance, Polymorphism)
- Collections Framework (ConcurrentHashMap, ArrayList)
- Exception Handling (try-catch-finally, custom exceptions)
- Multithreading (ExecutorService, Thread pools, Synchronization)
✅ Database Integration
- JDBC connectivity and connection management
- DAO (Data Access Object) pattern
- CRUD operations with PreparedStatements
- Transaction handling
- Database schema design and normalization
✅ Web Technologies
- Servlet API for request/response handling
- JSP for dynamic web pages
- Session management and cookies
- MVC architectural pattern
- HTTP protocol understanding
✅ Software Engineering Practices
- Version control with Git
- Unit testing with JUnit
- Code documentation
- Project structure and organization
- Collaborative development
| Criteria | Implementation | Score |
|---|---|---|
| Problem Understanding | Architecture diagrams, clear requirements | ⭐⭐⭐⭐⭐ |
| Core Java Concepts | OOP, Collections, Threading, Exception Handling | ⭐⭐⭐⭐⭐ |
| Database Integration | JDBC, DAO pattern, Schema design | ⭐⭐⭐⭐⭐ |
| Servlets & Web | Request/Response, Session management | ⭐⭐⭐⭐⭐ |
| Code Quality | Clean code, testing, documentation | ⭐⭐⭐⭐⭐ |
| Innovation | Theme toggle, dual interface, scalability | ⭐⭐⭐⭐⭐ |
The Multithreaded Chat Application successfully demonstrates a comprehensive understanding of enterprise Java development, showcasing:
- Scalable Architecture - Thread pool manages 50+ concurrent connections efficiently
- Database Integration - Robust JDBC implementation with DAO pattern
- Real-time Communication - Socket programming for instant messaging
- Modern Web Development - Servlets, JSP, and session management
- User Experience - Dark/light theme, responsive design
- Code Quality - Clean architecture, unit tests, comprehensive documentation
- ✅ Concurrency Handling: ExecutorService thread pool with proper synchronization
- ✅ Data Persistence: MySQL database with normalized schema
- ✅ Security: Session management, input validation, prepared statements
- ✅ Maintainability: MVC pattern, DAO abstraction, modular design
- ✅ Testability: JUnit tests, separation of concerns
This project serves as a solid foundation for:
- Enterprise chat applications
- Customer support systems
- Real-time collaboration tools
- Learning management systems
- Social networking platforms
Through this project, we gained hands-on experience with:
- Backend Development: Java, JDBC, Socket programming
- Frontend Development: JSP, HTML, CSS, JavaScript
- Database Design: MySQL, SQL, normalization
- Software Architecture: Design patterns, scalability
- Team Collaboration: Git, code reviews, documentation
Special thanks to:
- Course Instructors for guidance on Java enterprise development
- Open Source Community for tools and libraries (MySQL, Tomcat, Maven)
- Stack Overflow for troubleshooting and best practices
- GitHub for version control and collaboration platform
- Java SE 11 Documentation
- Servlet 4.0 Specification
- MySQL 8.0 Reference Manual
- Apache Tomcat 9 Documentation
Made with ☕ and 💻 by CS Students
© 2025 Multithreaded Chat Application. All Rights Reserved.



