Zero-Shot vs Few-Shot vs Chain-of-Thought Prompting — When to Use Each
Fast recall
Quick revision
Core answer
Whether the candidate can pick the right prompting strategy for a given task and understands the cost/quality tradeoff
Applying CoT everywhere — it's expensive in tokens and adds latency. Zero-shot is fine for simple classification.
Mention self-consistency CoT (sample multiple reasoning paths, take the majority answer), ReAct (reason + act pattern for tool-using agents), and how few-shot examples in PromptTemplate can be injected via variables
Interview-ready guide
Interview answer
Zero-shot: no examples in the prompt — just the instruction. Fast and cheap; works for simple tasks the model has seen in training. Few-shot: include 2–5 worked examples of input→output pairs. Dramatically improves format consistency and domain accuracy without fine-tuning. Chain-of-thought (CoT): instruct the model to reason step by step before giving the final answer. Use for multi-step logic, math, or any task where correctness depends on intermediate reasoning. Cost increases with output tokens. For Java teams: zero-shot for simple extraction, few-shot for consistent JSON output, CoT for complex domain reasoning.
Zero-Shot vs Few-Shot vs Chain-of-Thought Prompting — When to Use Each
Direct Answer
Zero-shot: no examples in the prompt — just the instruction. Fast and cheap; works for simple tasks the model has seen in training. Few-shot: include 2–5 worked examples of input→output pairs. Dramatically improves format consistency and domain accuracy without fine-tuning. Chain-of-thought (CoT): instruct the model to reason step by step before giving the final answer. Use for multi-step logic, math, or any task where correctness depends on intermediate reasoning. Cost increases with output tokens. For Java teams: zero-shot for simple extraction, few-shot for consistent JSON output, CoT for complex domain reasoning.
Deep Dive & Architecture
Zero-shot: no examples in the prompt — just the instruction.
Fast and cheap; works for simple tasks the model has seen in training. Few-shot: include 2–5 worked examples of input→output pairs.
Dramatically improves format consistency and domain accuracy without fine-tuning. Chain-of-thought (CoT): instruct the model to reason step by step before giving the final answer. Use for multi-step logic, math, or any task where correctness depends on intermediate reasoning. Cost increases with output tokens. For Java teams: zero-shot for simple extraction, few-shot for consistent JSON output, CoT for complex domain reasoning.
Treating prompts as static strings hardcoded in Java — missing variable injection, system vs user role separation, and testability
Common Mistakes & Pitfalls
Applying CoT everywhere — it's expensive in tokens and adds latency. Zero-shot is fine for simple classification.
Check your understanding
Answer these without looking back at the article.
- What is prompt engineering and why does it matter for Java teams building LLM features?
- How do you use `PromptTemplate` in Spring AI to inject variables into prompts?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.