Chapter 1 · Lesson 1 of 5
01. Your first Java program
What Java is, the parts every Java program has (class Main and the main method), and System.out.println to show words on the screen.
Java runs on billions of devices: Android apps, bank systems, online shops and huge websites are built with it. It's one of the most used languages in the world, and a favourite for learning how programs are put together.
Here's a whole Java program. It shows one line on the screen.
public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); }}It shows
Hello, World!
Every Java program lives in a class. Ours is called Main, and it's in a file called Main.java. Inside it, public static void main(String[] args) is the main method: where the program starts. Everything it does goes between its curly braces { }.
System.out.println(…) shows what's in the brackets on the screen, then ends the line. Words go in double quotes, and every instruction ends with a semicolon ;.
Your turn
1Steps
- 1Write a program that prints
I am learning Java!on its own line.
Write it in Main.java, in public class Main. If it reads input, put the answers in Program input, under the terminal.
Use: System.out.println
Starting code
The editor starts empty. Copy this into it to begin, or write your own from scratch.
public class Main { public static void main(String[] args) { // Print your line here
}}2Expected output
It should show
I am learning Java!
3Hints
Stuck? Open one hint at a time: each gives a bit more help.
Hint 1
It's one System.out.println line, inside the main method's curly braces.
Hint 2
The words go in double quotes inside the brackets, like System.out.println("…");
Hint 3
Check the capital S in System, the dots, and the ; at the end.