You will understand what tokens are, why LLMs count them instead of characters or words, and how that knowledge directly shapes decisions you make when building with AI in Java and Spring Boot.
Picture your first week working on EngineerPrep's AI tutor feature. You wire up a Spring Boot service that sends a learner's question to Claude via Amazon Bedrock. Everything works. Then you check the bill. Bedrock charges per token — not per request, not per word. And when a learner pastes a long Java stack trace into the chat, the cost spikes in a way you didn't expect. You try to guess: "I'll just count the words and multiply by some factor." It's close, but it's wrong enough to cause budget surprises in production. EngineerPrep uses Capstead — the team's own Spring Boot starter that tracks AI cost and token usage across every Bedrock call — to catch exactly this kind of surprise. But Capstead can only report accurate numbers if you understand what a token actually is.…
Think about how you read a word like "unbelievable" . You don't read it one letter at a time. You also don't read it as one giant blob. Your brain breaks it into familiar chunks: "un" + "believ" + "able" . Each chunk is something you've seen before. Together they carry meaning. A token is exactly that — a familiar chunk of text. It might be a whole word, part of a word, a punctuation mark, or even a single letter. The exact chunks depend on the language model and its tokenizer vocabulary. An LLM (Large Language Model — an AI trained on large amounts of text to predict and generate language) doesn't read raw letters. It reads tokens. Every piece of text you send it gets chopped into tokens first. That chopping process is called tokenization . Why tokens instead of letters or words? Two reasons. First, common words become one token each, which is efficient.…
Take this sentence a learner might type into EngineerPrep: "HashMap resizes itself automatically." Imagine a small machine that reads left to right and stamps each chunk it recognises. Step 1 — The machine looks at "Hash". It recognises "Hash" as a common chunk it has seen many times. Stamp. Token 1: Hash . Step 2 — It looks at "Map". Another familiar chunk immediately after. Stamp. Token 2: Map . Notice: the single word HashMap became two tokens because the tokenizer stores chunks based on frequency in training data, and "HashMap" as a unit may not meet that threshold. Step 3 — It looks at " resizes". The space before the word is included in the token — that's normal for many tokenizers. Stamp. Token 3: resizes . Step 4 — It looks at " itself". Common English word. Stamp. Token 4: itself . Step 5 — It looks at " automatically". Stamp. Token 5: automatically . Step 6…