Claude · 01 · Part 1

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.

5
Nested terms
1
Runnable demo
3
Exercises
Information current as of: 2026-10-30
01
Chapter One · Terminology

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.

Each term is a subset of the one around it
Artificial Intelligence software doing tasks that normally need human judgement Machine Learning behaviour learned from examples, not hand-coded rules Deep Learning learning with many-layered neural networks Generative AI models that produce new text, images, code… Large Language Models
TermPlain meaningSoftware-engineering analogy
Artificial intelligenceAny 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 learningThe 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 learningMachine learning using neural networks with many layers.Layers of small functions whose parameters are tuned automatically.
Generative AIModels whose output is new content rather than a label or score.A compiler consumes code; a generative model produces code.
Large language modelA 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.
Why this matters for you: Claude is a family of large language models. Everything you will later do with Claude Code sits on top of that one ability: given some text, produce the next piece of text.
02
Chapter Two · The Core Mechanism

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.

Generation is a loop, one token at a time
Text so far "public static" LLM likely next tokens void (high) int (medium) … pick one, append it, repeat illustrative example — real models score many thousands of candidates
See the mechanism in 40 lines of Java

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)
Java 21 · single-file program
import java.util.*; public class BigramDemo { public static void main(String[] args) { String corpus = "the cat sat on the mat . the cat ate the fish . the dog sat on the log ."; String[] words = corpus.split(" "); // "Training": count which word follows which. Map<String, Map<String, Integer>> counts = new TreeMap<>(); for (int i = 0; i < words.length - 1; i++) { counts.computeIfAbsent(words[i], k -> new TreeMap<>()).merge(words[i + 1], 1, Integer::sum); } System.out.println("After \"the\": " + counts.get("the")); System.out.println("After \"cat\": " + counts.get("cat")); // "Inference": generate one token at a time from the learned counts. Random rnd = new Random(42); for (int run = 1; run <= 3; run++) { StringBuilder out = new StringBuilder("the"); String cur = "the"; for (int n = 0; n < 7; n++) { Map<String, Integer> next = counts.get(cur); if (next == null) break; int total = next.values().stream().mapToInt(Integer::intValue).sum(); int pick = rnd.nextInt(total); for (var e : next.entrySet()) { pick -= e.getValue(); if (pick < 0) { cur = e.getKey(); break; } } out.append(' ').append(cur); } System.out.println("sample " + run + ": " + out); } } }
Prerequisites: JDK 21 (single-file source launch). Save the file as BigramDemo.java.
$ java BigramDemo.java
Actual output · executed 2026-10-30 · OpenJDK 21.0.2 (Temurin), Linux
After "the": {cat=2, dog=1, fish=1, log=1, mat=1} After "cat": {ate=1, sat=1} sample 1: the dog sat on the cat sat on sample 2: the dog sat on the dog sat on sample 3: the dog sat on the cat sat on
What happened
  • 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.
Randomness is a feature. Real LLM tools also choose among likely tokens rather than always taking the top one, which is why asking the same question twice can give different answers. This is one reason you verify generated code instead of assuming it will match last time's output.
03
Chapter Three · Two Phases

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.

What changes in each phase
TRAINING done before you ever see the model text data model numbers inside the model are updated to predict better knowledge is frozen at a cutoff INFERENCE every time you send a prompt your prompt fixed model model is not changed; only your text steers the output new facts must be put in the prompt

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.
04
Chapter Four · Working Memory

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.

What competes for the same window
system your files conversation tool output free one finite budget, measured in tokens the fuller it gets, the less reliably older details are recalled segment sizes are illustrative, not measured
How big is it?

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.

Bigger is not automatically better

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.

Coding-agent preview: when Claude Code reads a large file or prints a long test log, those tokens enter this window. Later chapters show how to keep the window lean — project instructions, subagents, and clearing context between tasks.
05
Chapter Five · Limits

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.

Hallucination risk
Which Spring Boot property turns on the frobnicate cache?

A question that presumes something exists invites an invented answer such as a plausible spring.cache.frobnicate.enabled.

Safer prompt
Which Spring Boot property controls cache type? If you are not sure a property exists, say so.

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 doCoding 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 quotesHave it pull exact text from the source first, then answer from that."Quote the relevant lines of the stack trace, then explain."
Verify with citationsAsk it to back each claim, and retract claims it cannot support."Point to the file and line that proves each statement."
Restrict knowledgeTell it to use only the material you supplied."Use only the attached pom.xml for versions."
These reduce hallucination; they do not remove it. Anthropic's own guide says the techniques do not eliminate hallucinations entirely and advises validating critical information. For code, the strongest check is cheap and external: compile it, run the tests, read the diff.
06
Chapter Six · Why Software

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.

07
Chapter Seven · Summary

Key Takeaways, Exercises and Sources

∑ The World of AI — what to remember
  • 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.
Exercises

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.

Sources (all read on 2026-10-30; paraphrased)
  1. Anthropic, Models overview — current model lineup, context window, max output, knowledge cutoffs, tokenizer note.
  2. Anthropic, Context windows, and Effective context engineering for AI agents — context as working memory, context rot, finite attention budget, tokens.
  3. 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.