...

/

Prompting AI as Your Coding Assistant

Prompting AI as Your Coding Assistant

Practice asking an AI for Java code, refine prompts to shape the output, and use it to explore, compare, and debug.

What is prompting?

Learning Java isn’t something you do alone. You’ve got a partner: an AI that can write code, explain, and help you debug.

However, how you phrase your request matters, just as it does when learning a new language. Think of prompting as giving instructions to a very fast and patient helper.

By the end of this lesson, you’ll know how to:

  • Ask the AI for code.

  • Refine your request.

  • Use the AI to explore and experiment, not just copy answers.

First prompt

Try asking the AI:

Write Java code that prints the text “2 + 3” on the screen.

Powered by AI
5 Prompts Remaining
Prompt AI WidgetOur tool is designed to help you to understand concepts and ask any follow up questions. Ask a question to get started.
AI buddy

You’ll get a small snippet of code. Run it. That’s somewhat similar to what you created in the previous lesson; however, the AI executed the task this time as intended.

Java 21
// Write your code here

Food for thought:

  • What did the AI give you?

  • Was it exactly what you asked for?

  • Did it add extras (like comments or explanations)?

Refining your prompt

Now revise your prompt within the same AI assistant interface where you previously entered it.

Change it to print the result of “2 + 3,” not just the text.

Run it. Observe the output. Did the code change? Did it match your expectations?

If not, adjust your words. Try the prompt given below.

“Make it print the result with a message: The answer for 2+3 is 5.”

Notice how adding or changing just a few words makes the AI adapt.

Why this matters to you

As you move through this course, you’ll:

  • Write your own code first.

  • Use prompting as a learning supplement: to compare, experiment, or overcome any hurdles along the way.

Now, you’ve effectively learned how to talk to your coding assistant.

  • Next, we will return to Java fundamentals with your very first building block: built-in methods and System.out.println().

  • In each chapter, you will build a cool new project in Java. Let’s begin.