← Latest papers
💬 NLP

Simulating Students' Java Programming Errors with Large Language Models

This paper demonstrates that large language models, particularly Claude Sonnet 4, can effectively simulate diverse and realistic Java programming errors from students, offering a scalable alternative to collecting authentic submissions for educational research and intelligent tutoring systems.

Original authors: Ali Keramati, Jie Cao, Iman Mohammadi, Mark Warschauer, Yang Shi

Published 2026-06-15
📖 5 min read🧠 Deep dive

Original authors: Ali Keramati, Jie Cao, Iman Mohammadi, Mark Warschauer, Yang Shi

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are a teacher trying to prepare for a big programming class. You know your students will make mistakes, but you can't predict exactly what those mistakes will be until you actually teach the class and collect their homework. This is a slow, expensive process.

This paper asks a simple question: Can we use a super-smart AI (a Large Language Model, or LLM) to pretend to be a confused student and generate those mistakes for us ahead of time?

Here is the breakdown of their experiment, explained with everyday analogies.

The Goal: The "Fake Student" Test

The researchers wanted to see if an AI could write Java code that looks exactly like a beginner student wrote it—specifically, code that has logical errors.

  • Logical errors are like writing a recipe that says "add salt to taste" but forgetting to actually add the salt. The computer runs the code, but the result is wrong because the thinking was flawed.
  • The Challenge: If you just ask an AI to "write code," it usually writes perfect code. If you ask it to "break the code," it often makes random, silly mistakes (like putting a comma where a period should be) that real students don't actually make. The goal was to make the AI make realistic mistakes.

The Experiment: The "Taste Test"

The researchers took 37 different programming problems from a real classroom (CodeWorkout). They had five different AI models try to solve these problems, but they used three different "instruction styles" (prompts) to try to force the AI to make mistakes:

  1. Direct Order (IO): "Here is the problem, give me a wrong answer."
  2. Thinking Aloud (CoT): "Think through the steps, decide where you might slip up, and then write the wrong code."
  3. Self-Correction Loop (Self-Refine): "Write a wrong answer, then critique it, then fix it slightly to make it a different kind of wrong answer."

They then compared the AI's "fake mistakes" against 74,000 real mistakes made by actual students.

The Two Main Rules for a Good Fake

To be useful, the AI's fake mistakes had to pass two tests:

  1. Diversity (The Variety Test): Did the AI make many different kinds of mistakes, or did it just repeat the same error over and over? (Imagine a chef trying to make 10 different burnt cookies. If they all look exactly the same, that's not very diverse).
  2. Alignment (The "Realness" Test): Did the AI's mistakes look like something a human would actually do? (If the AI writes code that is wrong in a way a human would never think of, it's not a good simulation).

What They Found

1. The AI Can Make Mistakes, But Not All AIs Are Equal
All the AI models could generate a variety of errors. However, some were better at it than others.

  • Gemini 2.5 Pro was like a chaotic artist: it made a huge variety of mistakes (high diversity), but many of them were weird and didn't look like real student errors.
  • GPT-4o was like a cautious student: it made very similar mistakes over and over (low diversity).
  • Claude Sonnet 4 was the Goldilocks of the group. It found the best balance. It made enough different kinds of mistakes, but they were also very close to what real students actually write.

2. The "Thinking Aloud" Trick Helped
When the researchers told the AI to "think step-by-step" before writing the code (Chain-of-Thought), the mistakes became more realistic. It was as if the AI was simulating the process of a student getting confused, rather than just randomly breaking the code.

3. The "Hardness" Factor
The researchers looked at how "struggling" a problem was (based on how many times students tried to solve it).

  • Easy Problems: The AI did a great job mimicking students.
  • Hard Problems: As the problems got harder, the AI's mistakes became more diverse (it tried many different wrong paths), but they became less like real students. It's like a novice actor trying to play a complex scene; they might try many different interpretations, but none of them quite capture the nuance of a real human performance.

4. The "Blind Taste Test" (Human Experts)
The researchers hired human experts to look at a mix of real student code and AI-generated code. They didn't know which was which.

  • The Result: The experts were fooled 83.7% of the time. They thought the AI's code was written by a human.
  • The Twist: The experts actually rated the AI's mistakes as more plausible (more realistic) than the real students' mistakes. Why? Because the AI made "clean" mistakes (like a classic textbook error), while real students often make messy, complicated mistakes with multiple errors at once. The AI was like an "idealized" confused student, while real students are messier.

The Bottom Line

This paper proves that AI can act as a "stand-in" for students to generate realistic programming errors.

  • Claude Sonnet 4 is currently the best "student simulator."
  • Harder problems make the AI more creative but less accurate to real human behavior.
  • The Trade-off: You can have an AI that makes a huge variety of mistakes, or one that makes very realistic mistakes, but it's hard to get both perfectly at the same time.

The researchers suggest this is a powerful tool for teachers and educational software developers. Instead of waiting years to collect thousands of real student mistakes to train their systems, they can use these "fake" mistakes to build better tutoring tools and help teachers anticipate where students might get stuck.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →