Mastering Conversations: A Guide to Building and Using a Java-Based Chat (StarChat) with IRIS Cloud SQL.
Tags: jdbc, sql, cloud, java
Published: 2024-04-24 16:37:00

<h3>Intro</h3>
<p>In a fast-paced digital era, effective communication is crucial. This article introduces a Java-based chat project, combining the strength of IRIS database and ChatGPT intelligence. Built on Java, it goes beyond real-time messaging, leveraging IRIS and ChatGPT for an enhanced chat experience. Also, the name of the project references the cultural classic - Star Wars.</p>
<h3>Building Application</h3>
<p>Building our dynamic chat application involves a seamless integration of key components and technologies. Java serves as the heart that&nbsp;drives server-side logic and business operations. Complementing it is Spring WebSocket, facilitating real-time messaging with configured endpoints. JQuery and HTML collaborate for an engaging user interface, with JQuery simplifying client-side scripting. IRIS Cloud SQL&nbsp;takes center stage as the database, ensuring reliable storage of critical data.</p>
<h3>Running Application</h3>
<p>To launch the dynamic chat application, configure essential environment variables for the IRIS database connection. You can use both IRIS Cloud SQL or local.&nbsp;If IRIS is&nbsp;local, utilize the provided <code>docker-compose.yaml</code>. &nbsp;If you are using the local storage - Liquibase will handle database migrations, but in case&nbsp;of Cloud SQL - run migration manually using the .sql provided inside the project. Start the application and access the chat platform on port 3000 (customizable in&nbsp;<code>application.properties</code>&nbsp;file) by navigating to <code>http://localhost:3000</code>&nbsp;your web browser.</p>
<h3>Using StarChat</h3>
<p>As with almost all software products, StarChat requires signing up:</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hok6wjc0lsdblyaeg4ae.png) 
<span>&nbsp;</span><br><br>and authorization:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bpqvx8dmqmjrxncrk93c.png)

<p><br>After successful login, the user will be redirected to the main page of the chat. There&nbsp;the user will be able to create new chat rooms and chat with friends.</p>
<p><strong>Key Features</strong></p>
<p><strong>Creating a chat room with another user</strong><br>For the current moment, there is a possibility to create a chat room with 2 people. To create it there is a need to specify the chat room`s topic and email of the signed-up user:<br>&nbsp;<span>&nbsp;</span></p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b663116fa9ur9kroimk1.png) 

<p><strong>Real-time messaging with friends</strong><br>When your friends log in, the chat application prioritizes their experience by displaying the most recently updated chat at the top of the list. This&nbsp;design ensures that users are immediately connected to the latest conversations:</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dq64hy8kw89zqsd0jh9p.png)

<p><strong>AI integration</strong><br>Also, there was added the capability to interact with ChatGPT directly within the chat. Seamlessly pose questions, seek information, or simply enjoy a chat powered by the intelligence of ChatGPT. To get the answer from ChatGPT, there is a need to write a question in a format like&nbsp;'/chatgpt + space + your question':</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vfr4k1b6n7vefo4362e7.png)

<p><strong>Uploading files to the chat</strong><br>Additionally, there is a possibility to upload&nbsp;the multimedia of a different type. The security features include forbidding double and dangerous extensions, preventing potential security risks associated with certain file types:</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xw1zylk1zfzp8qmqeych.png)
<h3>Conclusion</h3>
<p>We've reached the end of our journey with this Java-based chat application! We've integrated advanced technologies to enable real-time messaging, secure data handling, and user-friendly features.</p>
<p>You may explore the application in more detail&nbsp;<a href="https://github.com/anndiak/StarChat" target="_blank">here</a>.</p>