SPEC SHEET · EPISODE CODESTATUS: STABLEPART OF: ZERO TO AI AGENT · EP 3FIRST PUSHED: 7 Nov 2026

Talking to an LLM

Episode 3 lab: your first LLM call in Java with Ollama, then a system prompt, a terminal chatbot and structured JSON output.

kagitha-dev /Java
Talking to an LLM
ep3-talking-to-llm
LANGUAGE
Java
STACK
Java · Ollama
LAST PUSH
7 Nov 2026
STARS
★ 0

Java 17+, Maven, and Ollama running qwen3.5:4b locally.

Before you run

ollama pull qwen3.5:4b

Ollama must be running (it runs in the background after install). Check with:

curl http://localhost:11434

Run each step (from this folder)

mvn -q compile
mvn -q exec:java -Dexec.mainClass=airadar.Step1_FirstCall
mvn -q exec:java -Dexec.mainClass=airadar.Step2_Stateless
mvn -q exec:java -Dexec.mainClass=airadar.Step3_SystemPrompt
mvn -q exec:java -Dexec.mainClass=airadar.Step4_TerminalChatbot
mvn -q exec:java -Dexec.mainClass=airadar.Step5_StructuredOutput

Or open the folder in IntelliJ and press Run on any StepN class.

Step File What it shows
1 Step1_FirstCall Calling an AI is just sending JSON to a URL (raw JSON back)
2 Step2_Stateless The API forgets between calls; resending history fixes it
3 Step3_SystemPrompt Same question, with and without a system prompt
4 Step4_TerminalChatbot A chatbot whose "memory" is a Java list, with token counts
5 Step5_StructuredOutput AI Radar classifies feed.json and writes flashcards as JSON

Ollama.java is a small helper used by steps 2–5. It does exactly what Step 1 does. Every call sends "think": false, temperature 0 and a fixed seed, so retakes give the same output.

PART OF A SERIES
Zero to AI Agent

Build AI agents in Java from scratch. LLMs, Ollama, tool calling, MCP, RAG and LangChain4j, with slides and hands-on labs for every episode.

See the series →

More from this series & the lab

Everything in the lab →