Learning better

Learn Java with ChatGPT without forgetting it all by the exam

Published on October 22, 20265 min read

You paste the task into ChatGPT, get finished code, and it runs. That feels great, until you sit in the exam and can't write a single line yourself. ChatGPT isn't a problem for learning Java in itself. What matters is how you use it. Here you get clear rules, prompts to copy and a test of whether you've really learned something.

Why finished solutions barely help you learn

Programming is like swimming. Watching helps a little, but you only learn in the water. When you read a finished solution, you usually understand it. That feels like being able to do it, but it's only recognition. In the exam you have to find the solution yourself: which loop? Which condition? Where does the variable go?

A finished answer makes exactly those decisions for you. On top of that, many tests at school and university are still written on paper, or on a computer without a chat and without autocomplete. Check how your own exam works.

What ChatGPT is genuinely good at

To be fair, ChatGPT does some things very well.

  • Explaining concepts: what's the difference between static and non-static? You can keep asking until it clicks, even at midnight.
  • Explaining other people's code line by line: for example an example from your lecture or class.
  • Translating error messages: the most important ones are also in the 10 most common Java error messages.
  • Making up extra exercises: on a topic you want to practise.

It also has weaknesses you should know about:

  • Answers can be wrong. They still sound confident.
  • Solutions often don't match your course. ChatGPT likes to use tools you haven't covered yet.
  • It can't see what happens on your machine. You copy code and errors back and forth and lose track along the way.

A typical example. The task: count the even numbers in an array. In class you've just covered loops in Java. ChatGPT might answer like this:

long count = Arrays.stream(numbers).filter(n -> n % 2 == 0).count();

That's correct, but it uses lambdas and streams, material from the end of a Java course. Your teacher probably expects something more like this:

int count = 0;for (int n : numbers) {    if (n % 2 == 0) {        count++;    }}

If you hand in the first version, you usually can't explain the second one. And that's exactly the one that shows up in the exam. In a case like this, ask ChatGPT: “Solve this with a for loop only and explain every line.” Then compare both versions and learn along the way that there's more than one correct solution.

Five rules so you actually learn

  1. Try it yourself first. At least 15 minutes before you ask. Write down where exactly you're stuck.
  2. Ask for hints, not code. Say explicitly that you don't want a solution.
  3. Never copy, always type it yourself. Even if you get code: type it out line by line and think about what each one does. Better still: close the window and write it from memory.
  4. Explain it back. Explain the solution in your own words. If you can't, you haven't understood it yet.
  5. Redo it the next day without help. Solve the same task again, without the chat. Only when that works has it stuck.

Prompts that give you hints instead of solutions

You can copy these and adapt them:

I'm learning Java and I'm practising for loops right now. Here is my
task and my code. Please don't give me the solution, just a hint
about which line I should think about.
Explain this error message in plain English. Tell me what it means
and where I should look, but don't fix my code.
Ask me three short questions to check whether I've understood return
values of methods. Only show the answers after I've replied.
Only use things that come up in a beginner course up to the chapter
on arrays: variables, if, loops, arrays. No streams, no lists.

The last prompt stops you from getting code that doesn't match your level. If you're working on methods and recursion right now, name exactly that as the limit.

One more point if you're at university or have graded assignments: whether and how you may use AI for coursework is up to your institution and your course. What to watch out for is in using AI for programming assignments.

Test yourself: can you do it without help?

An honest test after every study session. Without a chat and without a template, can you …

  • open an empty file and write the skeleton with main, as in the article on input and output?
  • solve a task of the same kind, just with different numbers?
  • explain why your loop runs exactly that many times?
  • predict what a short program prints before you run it?

The last point is a typical exam question. How to practise it on purpose is shown in “What does the program print?”. Every “no” tells you what to review tomorrow.

What Jario does differently

Jario also has an AI tutor, but with a different job. It knows the task, your code and the test result. You don't have to copy anything back and forth. It gives you hints in small steps and deliberately doesn't write a solution for you. You write the code yourself, in the editor right next to it.

Because the tutor knows the test result, it can refer to the case that is failing right now instead of guessing in general. Whether your code is correct isn't decided by the chat but by the tests: after “Check” you see, for example, “3 of 4 tests passed”. The tasks go from “Easy” through “Medium” to “Hard” and stay within the material of their chapter. A free account gives you 5 tutor questions per day. That's enough if you stick to rule 1. For general questions outside the tasks, ChatGPT remains a useful reference.

In short

ChatGPT is a good explainer and a bad teacher if you let it write your code. Ask for explanations and hints, type everything yourself and redo every task once without help. Then you'll be able to do in the exam what you practised.