user12511: I wanted to make a 1 player chess game.
The idea is:

The move made by the player would be displayed on the GUI.
It is sent to the Chess Engine in its own specific understood form.
Then the result of the Chess engine would be taken and then made visible on the GUI.

Currently I have made no progress on it and am on a dead end. My current program on Java lets 2 players play with each other. The program manages the rules that have to be followed and which moves are illegal. But for a single player game I wanted an AI for my game that can take inputs and give outputs. I searched online for various open source chess engines like Stockfish. But found nothing about using it in my program.
I tried to work on to create my own engine but it was quite a challenge for me. Hence connecting it with an external AI is the only solution I think there is.

user825: Let's break it down:

You have a working Java chess board that you can use to move pieces
You want a chess engine (engine is a more precise term than AI)
You want to download Stockfish and use it
You want to invent a new protocol or technology to communicate your chess board with the Stockfish engine

To me, your question is really:

How to connect an external chess engine such as Stockfish within my own chess GUI in Java?

Useful old posts in this site:

Chess Engine API
What is the optimal way to use Stockfish programmatically?

Basically, what you need to do is:

You shouldn't invent your own technology, you should study the UCI protocol. http://wbec-ridderkerk.nl/html/UCIProtocol.html is a useful reference. I can get you started, do this:

Download Stockfish
Open Stockfish in a console/terminal, don't double-click on it with your mouse
Type ucinewgame and then go movetime 1000. Do you see Stockfish's move?
Read the protocol specification and learn how to analyze a position, and the output format.

Write a UCI output parser. Parse whatever information you want.
Use the information to make a move on your chess board.

The only technical difficulty I can see here is to establish a "connection" between your GUI with the engine. This is done by creating a new process, running the engine.

https://stackoverflow.com/questions/2006035/how-to-create-a-process-in-java has information on how to do it.

Once you have the new process, you can establish a simple standard input/output pipeline. https://stackoverflow.com/questions/27081918/java-how-to-send-a-value-to-child-process-using-outputstream has the details. Ask on Stackoverflow if you're not sure.

12511: <p>I wanted to make a 1 player chess game.</p>

<p>The idea is:</p>

<ul>
<li>The move made by the player would be displayed on the GUI.</li>
<li>It is sent to the Chess Engine in its own specific understood form.</li>
<li>Then the result of the Chess engine would be taken and then made visible on the GUI.</li>
</ul>

<p>Currently I have made no progress on it and am on a dead end. My current program on Java lets 2 players play with each other. The program manages the rules that have to be followed and which moves are illegal. But for a single player game I wanted an AI for my game that can take inputs and give outputs. I searched online for various open source chess engines like Stockfish. But found nothing about using it in my program.</p>

<p>I tried to work on to create my own engine but it was quite a challenge for me. Hence connecting it with an external AI is the only solution I think there is.</p>
 825: <p>Let's break it down:</p>

<ul>
<li>You have a working Java chess board that you can use to move pieces</li>
<li>You want a chess engine (<strong>engine</strong> is a more precise term than <strong>AI</strong>)</li>
<li>You want to download Stockfish and use it</li>
<li>You want to invent a new protocol or technology to communicate your chess board with the Stockfish engine</li>
</ul>

<p>To me, your question is really:</p>

<ul>
<li>How to connect an external chess engine such as Stockfish within my own chess GUI in Java?</li>
</ul>

<p>Useful old posts in this site:</p>

<ul>
<li><a href="https://chess.stackexchange.com/questions/9632/chess-engine-api/9633#9633">Chess Engine API</a></li>
<li><a href="https://chess.stackexchange.com/questions/15704/what-is-the-optimal-way-to-use-stockfish-programmatically/15707#15707">What is the optimal way to use Stockfish programmatically?</a></li>
</ul>

<p>Basically, what you need to do is:</p>

<ol>
<li><p>You shouldn't invent your own technology, you should study the UCI protocol. <a href="http://wbec-ridderkerk.nl/html/UCIProtocol.html" rel="noreferrer">http://wbec-ridderkerk.nl/html/UCIProtocol.html</a> is a useful reference. I can get you started, do this:</p>

<ol>
<li>Download Stockfish</li>
<li>Open Stockfish in a console/terminal, don't double-click on it with your mouse</li>
<li>Type <code>ucinewgame</code> and then <code>go movetime 1000</code>. Do you see Stockfish's move?</li>
<li>Read the protocol specification and learn how to analyze a position, and the output format.</li>
</ol></li>
<li><p>Write a UCI output parser. Parse whatever information you want.</p></li>
<li>Use the information to make a move on your chess board.</li>
</ol>

<p>The only technical difficulty I can see here is to establish a "connection" between your GUI with the engine. This is done by creating a new process, running the engine.</p>

<blockquote>
  <p><a href="https://stackoverflow.com/questions/2006035/how-to-create-a-process-in-java">https://stackoverflow.com/questions/2006035/how-to-create-a-process-in-java</a> has information on how to do it.</p>
</blockquote>

<p>Once you have the new process, you can establish a simple standard input/output pipeline. <a href="https://stackoverflow.com/questions/27081918/java-how-to-send-a-value-to-child-process-using-outputstream">https://stackoverflow.com/questions/27081918/java-how-to-send-a-value-to-child-process-using-outputstream</a> has the details. Ask on Stackoverflow if you're not sure.</p>
