Java for AI Engineers
The Java skills you need to work with LLMs and build AI agents. Start with how models behave and a plain HttpClient call, then grow into Spring AI, LangChain4j, tools, MCP, RAG and agents. No Python, no maths.
Modern Java from the language up to the services you deploy, with code you can run. One idea per topic.
A series walks you through one subject in order, part by part. Every part is also a topic on the map below, so you can read any of them on its own.
The Java skills you need to work with LLMs and build AI agents. Start with how models behave and a plain HttpClient call, then grow into Spring AI, LangChain4j, tools, MCP, RAG and agents. No Python, no maths.
Rusty before a Java coding round? Solve 50 classic interview problems in an order that builds on itself: arrays, strings, collections, HashMap, Comparator, stacks and queues, then streams and the tricky stream puzzles interviewers love. Every problem has plain-English steps, clean code and the follow-up questions you will hear.
Learn Python fast by building on the Java you already know. Each part takes one Python idea, gives you one quick Java comparison to anchor it, then teaches it in plain Python, with the traps a Java mind falls into. Short, practical, and aimed at the Python you meet in real AI code.
You don't need to learn Python from zero. You already know loops, classes, collections and exceptions. Here are the ten things that actually change when a Java developer moves to Python, each with side-by-side code.
No types on variables, None instead of null, == that means equals(), and an if that accepts a list. Here is how Python variables really work, explained from the Java side, with the traps that catch every Java developer once.
Python has no for (int i = 0; i < n; i++). Every for loop walks over items, and three small helpers, range, enumerate and zip, cover every counting loop you used to write in Java. Plus if/elif, the ternary, and match as Python's switch.
Python's collections are built into the language, with their own literal syntax. Here is every ArrayList, HashMap and HashSet method you use daily, mapped to its Python form, plus slicing, tuples and the list-of-dicts shape that carries all JSON and AI data.
Python has no method overloading and almost no builders, and it doesn't miss them. Default values and keyword arguments do the same job in one function. Here is how def, *args, **kwargs and lambda work, compared with the Java you know.
A Python class is a Java class with less typing: __init__ is the constructor, self is this, and there's no new. Then come the two shortcuts you'll see everywhere: @dataclass, Python's record, and Pydantic, a record that validates its data.
Same model as Java, new words: catch becomes except, throw becomes raise, and nothing is checked. Here is how Python error handling works, which built-in errors map to which Java exceptions, how to read a traceback, and the Pythonic habit of asking forgiveness.
A list comprehension does the work of stream().filter().map().toList() in one readable line. Here is how to read one, how every common stream operation maps to Python, and when a plain loop is the better choice.
Python lets you write types, and modern code does. But Python itself never checks them when your program runs. Here is the type hint syntax mapped to Java, how to get compiler-like checking with mypy or pyright, and why AI libraries turn hints into real behaviour.
@app.get("/health") looks exactly like Spring's @GetMapping. It isn't the same thing. A Java annotation is metadata a framework reads later; a Python decorator is a function that runs right away and wraps or registers yours. Here is how they work, and how to read the ones you'll meet.
with is Python's try-with-resources, and yield turns a plain function into a lazy iterator. Together they power file handling, database connections and the word-by-word streaming of LLM answers. Here is how both work, compared with the Java you know.
LLM calls are slow and mostly waiting. Python's async lets one thread wait on many of them at once, pausing at every await. Here is how async def, await and asyncio.gather compare with CompletableFuture and virtual threads, and the rules that keep async code from freezing.
No pom.xml, no ~/.m2, no classpath. Python has modules and packages, installs dependencies into a virtual environment per project, and now has uv to do Maven's job in one fast tool. Here is how a Python project is laid out and run, mapped to the Maven world you know.
For years, getting the last element of a List meant list.get(list.size() - 1), and a LinkedHashSet couldn't do it at all. Java 21 adds one shared set of methods to every ordered collection. Here is what's new, which classes have it, and the traps to avoid.
You open LeetCode, pick a random problem, get stuck in ten minutes and close the tab. The problem isn't you, it's the order. Here is a study plan of 50 classic Java interview problems, grouped into eight short phases, where each one quietly prepares you for the next.
Four string problems that come up in almost every Java coding round: check two anagrams, find the first non-repeating character, find the first repeating character, and count each character. They all come down to one skill: counting things.
Remove duplicates from a list, find the common elements of two lists, take their union, and sort a list both ways. Four short problems that are really one question in disguise: do you know which collection to pick, and why?
Three HashMap problems, from easy to a true interview favourite: count the words in a sentence, find the element that appears most often, and group anagrams together. Along the way you'll learn getOrDefault, merge, entrySet and computeIfAbsent for good.
Sorting numbers is easy. Interviewers want to see you sort objects: employees by salary, highest first, with ties broken by age. Then the classic follow-up, sort a HashMap by its values. Here is Comparator from the first line to the last, in plain English.
A stack hands back the last thing you put in. A queue hands back the first. Three classic problems show when each one is the right tool, and why modern Java code uses ArrayDeque for both instead of the old Stack class.
"Here's a list of employees. Using streams, give me..." Seven questions that open countless Java interviews: filter by salary, get the names, sort, top 3, average, group by department and the highest salary in each. Each one explained step by step.
Second highest salary. Duplicates in a list. First non-repeating character. Average salary per department. The toMap duplicate-key trap. These are the stream questions that separate "I've used streams" from "I know streams". Each one built from pieces you already know.
Max and min, reverse, second largest, remove duplicates, move zeros, rotate by K and find the missing number. Seven small array problems that teach the moves behind half of all coding interviews: loops, two pointers, swaps and a little arithmetic.
Java 21 is the long-term-support release that made virtual threads, record patterns, pattern matching for switch and sequenced collections standard. Here is every important feature, what each one does in a line of code, which were only previews, and what to watch when you upgrade from Java 17.
For more than two decades every Java thread was glued to an operating-system thread, and a thread waiting on a database held that OS thread hostage. Virtual threads cut the glue. Here is the old model, the problem it caused, and exactly what virtual threads fix.
One line replaces a 40-line data class. Here is what a Java record gives you for free, how to add validation and methods, where records fit, where they don't, and what Java 21's record patterns add.
var lets the compiler work out a local variable's type from the value you assign. It is still strongly typed Java, not JavaScript. Here is how it works, where you can and can't use it, and the traps worth knowing.
A sealed class says exactly which classes may extend it, and the compiler enforces the list. Here is why that matters, the rules for permits, final, sealed and non-sealed, and how sealed types plus records give you switch statements the compiler can check.
Java 21 lets switch match on types, not just constants. Here is how it replaces the old if-instanceof-cast ladder, how when guards and case null work, the dominance and exhaustiveness rules, and how record patterns unpack data right in the case label.
Text blocks let you write JSON, SQL, HTML and LLM prompts in Java exactly as they look, without escaped quotes or \n on every line. Here is the syntax, how Java decides what indentation to keep, the two escapes worth knowing, and how to fill in values.
LLM code has three hard parts: messy JSON, replies that come in many shapes, and calls that take seconds. Modern Java has a feature for each. Here is how records, sealed types, pattern matching, text blocks and virtual threads fit AI work.
Python trains the models. But most AI work today is building the app around a model, and that is the kind of work Java has done well for decades. Here is an honest map of who does what.
You don't need the maths. You do need to know why the model forgets everything, why long chats cost more, and which temperature to use. Here is how an LLM works, explained for the Java code you will write.
No framework, no SDK. Just java.net.http.HttpClient, a few records and Jackson. One small client that talks to a local model or a cloud API by changing three settings, with error handling, retries and streaming.
The HTTP call from part 3, now done the Spring way. Set up Spring AI 2.0 with a local model, talk to it with ChatClient, use prompt templates, get Java records back, stream, remember the conversation, and switch providers without changing code.
A complete MCP setup is a host, a client and a server. We build the server and the client in plain Java with the MCP Java SDK, talk over STDIO, and see the only three spots you change for your own tools.
From the AI notebook