Codiqo

Learn Java · lesson 1 of 61 · about 5 minutes

Hello, Java

Open your own cinema ticket desk: print its welcome screen with System.out.println, and fix your first compiler error.

What you'll learn

  • Write a class with a main method
  • Print with System.out.println and print
  • Read a compiler error and find the line

Open the box office

Java runs the back-ends of banks, shops and booking sites, and Android apps too. It's made for big programs that keep running for years, so it's strict: every piece of code lives in a class, and the compiler checks everything before anything runs.

In this unit you'll build a ticket desk for a cinema, the kind of system Java runs every day. A Java program starts in the main method: public static void main(String[] args). For now, read that line as "the program starts here".

The ticket desk opens

public class Main {
    public static void main(String[] args) {
        System.out.println("=== Ticket Desk ===");
        System.out.println("Now showing: Space Pirates");
    }
}

Output

=== Ticket Desk ===
Now showing: Space Pirates

println and print

  • System.out.println(...) prints and then starts a new line
  • System.out.print(...) prints without starting a new line
  • Text goes in double quotes, and every statement ends with ;
  • Java is case-sensitive: system.out.println won't compile

print stays on the same line

public class Main {
    public static void main(String[] args) {
        System.out.print("Loading");
        System.out.print("...");
        System.out.println(" done");
        System.out.println("Ready");
    }
}

Output

Loading... done
Ready

Now try it yourself

This lesson is free in Codiqo, with 7 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.