Setup and Program Structure
Install a JDK (Java Development Kit), save code in a file named after its public class (Main.java), compile with javac Main.java and run with java Main. Since Java 11 you can also run a single file with java Main.java.
Every program starts in the main method. Each statement ends with a semicolon, and code blocks use curly braces.
Example
public class Main {
public static void main(String[] args) {
System.out.println("Line one");
System.out.println("Line two");
}
}Result
Line one Line two
Exercise
Which method does a Java program start in?
public static void (String[] args)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.