0Pricing
Java Academy · Lesson

Writing First Program

Create a minimal Java application with a main method, print output, then compile and run.

Writing First Program is a free Java Academy lesson on CoddyKit — lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Lesson Goals

Goal: write, compile, and run your first Java program.

  • Create a source file and a class.
  • Add the main method.
  • Print a short message.
  • Compile with javac and run with java.

Class and File

Class and file

  • Create a folder for your project.
  • Create a file named Main.java.
  • Each Java file typically defines one public class.
  • The file name must match the public class name.

Main Method

The entry point is the main method:

public static void main(String[] args)
  • public: callable by the JVM.
  • static: runs without creating an object first.
  • void: no return value.
  • String[] args: command-line arguments.

Printing Output

Printing uses System.out.println to write a line to the console.

System.out.println("Hello, Java!");

Text in quotes is a string literal. Keep lines short to read well on mobile screens.

Compile and Run

Save, compile, run

  • Save the file: Main.java
  • Compile: javac Main.java
  • Run: java Main

If the compiler reports errors, read the line number and fix the code.

First Program

Try it: Create Main.java with the code below and run it. You should see the greeting in the console.

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello, Java!");
  }
}

Filename Rule

Quick check: Which filename correctly matches a public class named HelloWorld?

Recap and Next

Recap: You created Main.java, added main, printed a message, then compiled and ran the program.

Next: Explore variables and data types to store and manipulate values.

Frequently asked questions

Is the “Writing First Program” lesson free?

Yes — the full text of “Writing First Program” is free to read here on the web, and the Java Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.

What will I learn in “Writing First Program”?

Create a minimal Java application with a main method, print output, then compile and run. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Writing First Program” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Introduction to Programming
  2. Installing JDK & IDE
  3. Writing First Program
← Back to Java Academy