The World of AI
Before using an AI coding tool well, you need a working picture of the engine inside it. This page builds that picture with no prior AI knowledge assumed: the terminology, what a language model really does, why it has a memory limit, and why it sometimes states false things confidently. It ends with a toy model you can run yourself.
Five Terms, Nested Like Russian Dolls
The words AI, machine learning, deep learning, generative AI and LLM are often used as if they meant the same thing. They do not: each one is a narrower kind of the one before it. Getting this ladder straight removes most of the confusion in later chapters.
| Term | Plain meaning | Software-engineering analogy |
|---|---|---|
| Artificial intelligence | Any software that performs a task we would associate with human judgement. | A rule engine that approves loans is already "AI" in the broad sense. |
| Machine learning | The program's behaviour is fitted to example data instead of being written as explicit rules. | Instead of coding every spam rule, you show it labelled mail and it derives the rules. |
| Deep learning | Machine learning using neural networks with many layers. | Layers of small functions whose parameters are tuned automatically. |
| Generative AI | Models whose output is new content rather than a label or score. | A compiler consumes code; a generative model produces code. |
| Large language model | A generative model trained on large amounts of text that predicts text one piece at a time. | Autocomplete at enormous scale, with far more context than the last word. |
An LLM Predicts the Next Token
A token is the unit of text a model reads and writes. It is often a word, part of a word, or a punctuation mark. Anthropic describes a model's context as the set of tokens it is given when it generates a response, so every piece of information the model receives is counted in tokens.
The model's one job is: given the tokens so far, choose a likely next token. It appends that token and repeats. A paragraph, a SQL query or a Java class all come out of this same loop.
The program below is not an LLM. It is a deliberately tiny stand-in that shows the same two phases: it learns which word tends to follow which from a small text, then generates new text one word at a time. A real LLM replaces the lookup table with a neural network that considers far more than the previous word, but the loop is the same shape.
BigramDemo.java (expand to read the source)
- Learning: after "the" the text contained cat twice and dog, fish, log, mat once each, so those counts are the model's whole "knowledge" of what follows "the".
- Generating: each new word was drawn at random in proportion to those counts. "cat" is the most probable next word after "the" but not the only one, which is why three runs differ.
- Fluent but shallow: the samples look grammatical because the training text was, yet "the dog sat on the cat sat on" means nothing. Looking only one word back is too little context; modern LLMs look at a very large window of preceding text.
Training vs. Inference
Every model lives through two very different phases. Training is the expensive, one-time (per model version) process in which the model's internal numbers are adjusted so its predictions match large amounts of text. Inference is what happens every time you use it: those numbers are now fixed, and the model simply generates a response to your input.
Two practical consequences follow directly:
- The model has a knowledge cutoff. Anthropic lists a "reliable knowledge cutoff" per model; the current Claude 5.5 models list June 2026 (see the model table in Source 1). Anything newer — a library release, an API change — is unknown unless you supply it.
- Using the model does not teach it your code. The model's numbers stay fixed during a session. Your project knowledge reaches it only through the text you give it, which is the subject of the next section.
The Context Window
The context window is everything the model can look at when it produces a reply. Anthropic's documentation calls it the model's "working memory": it holds the system prompt, every earlier message, tool results, attached files and the reply being generated.
As of the date at the top, the Claude models Fable 5.1, Opus 5.5, Sonnet 5.5 and Haiku 5.5 each list a 1M-token context window and up to 128K tokens of output (Source 1). Anthropic's note on its current tokenizer gives a feel for scale: 1M tokens is roughly 555 thousand words, whereas models before it fit about 750 thousand words in the same 1M tokens. The same text can cost a different number of tokens on a different model, so token counts are model-specific.
Anthropic states that as the token count grows, accuracy and recall degrade, a phenomenon it calls context rot, and that curating what is in the context matters as much as how much room exists (Source 2). Its engineering article describes this as a finite attention budget: each added token uses up some of it. The recommended goal is the smallest set of high-signal tokens that makes the desired result likely.
Why Models Hallucinate
A hallucination is output that is fluent and confident but factually wrong or inconsistent with the context you gave. Anthropic's guide says plainly that even the most advanced models, Claude included, can produce such text (Source 3).
The reason follows from the mechanism in Chapter 2. The model produces the most plausible continuation; it is not looking facts up in a database and checking them. A plausible-sounding method name or library flag is exactly what a text predictor is good at producing, whether or not it exists.
A question that presumes something exists invites an invented answer such as a plausible spring.cache.frobnicate.enabled.
Giving the model explicit permission to say "I don't know" is the first technique in Anthropic's guide.
| Technique (from Anthropic's guide) | What you do | Coding example |
|---|---|---|
| Allow "I don't know" | Tell the model it may admit uncertainty. | "If the API doesn't exist in this version, say so." |
| Ground in quotes | Have it pull exact text from the source first, then answer from that. | "Quote the relevant lines of the stack trace, then explain." |
| Verify with citations | Ask it to back each claim, and retract claims it cannot support. | "Point to the file and line that proves each statement." |
| Restrict knowledge | Tell it to use only the material you supplied. | "Use only the attached pom.xml for versions." |
Why LLMs Fit Software Development
Several properties of programming line up with what a language model does. These are explanations of fit, not performance claims; this page makes no benchmark claims.
- Code is text. Source files, build output, logs and commit messages are all sequences of tokens the model can read and write.
- Conventions are strong. Frameworks such as Spring Boot repeat patterns heavily, and predicting the next plausible line works well where the pattern is regular.
- Answers can be checked mechanically. A compiler, a linter or a test suite can reject a wrong guess immediately. That feedback is what turns a text generator into a useful agent in Chapter 3.
- Intent is expressed in words. Requirements, tickets and review comments are natural language, which is the model's native input.
The flip side is the same mechanism: where conventions are weak, requirements are ambiguous, or a fact is newer than the model's cutoff, plausible-but-wrong output becomes more likely. Your engineering judgement is still the final check.
Key Takeaways, Exercises and Sources
- LLMs sit inside generative AI, which sits inside deep learning, machine learning and AI.
- An LLM predicts the next token repeatedly; fluent output is not the same as true output.
- Training is separate from inference. Using a model does not change it, and its knowledge stops at a cutoff.
- The context window is finite working memory. Quality can degrade as it fills, so curate what goes in.
- Hallucinations are expected behaviour of the mechanism; reduce them with prompts and catch them with compilers and tests.
Exercise 1 Beginner
Run BigramDemo.java yourself. Then change the seed in new Random(42) and run it twice more.
Learning outcome: see that generation is probabilistic and that the same program can produce different text.
Exercise 2 Intermediate
Replace the corpus with five sentences about Spring Boot and generate text. Where does the output become fluent but meaningless? Write down why a one-word look-back causes that.
Learning outcome: connect context length to coherence.
Exercise 3 Advanced
Extend the program to condition on the previous two words (a trigram table). Compare samples with the one-word version and explain what improved and what still fails.
Learning outcome: understand why longer context helps and why it is still not understanding.
- Anthropic, Models overview — current model lineup, context window, max output, knowledge cutoffs, tokenizer note.
- Anthropic, Context windows, and Effective context engineering for AI agents — context as working memory, context rot, finite attention budget, tokens.
- Anthropic, Reduce hallucinations — definition of hallucination and mitigation techniques.
The definitions in Chapters 1 and 3 (AI, ML, deep learning, training vs. inference) are general explanations written for this guide, not drawn from a single source. Demo run: OpenJDK 21.0.2 (Temurin) on Linux, 2026-10-30.