Your First Java Program
Every Java program needs a class, and execution starts in a specific method inside it: public static void main(String[] args). The class name has to match the file name — this page always uses Main, matching Main.java. System.out.println comes from Java's standard library and needs no import to use.
Compiling happens first
When you hit run, the compiler (javac) checks your entire file and compiles it to bytecode before a single line runs. If there's a type error or a syntax mistake anywhere, nothing runs at all — you get a compile error instead of output.
Comments
Comments work like in most C-family languages: anything after // on a line is ignored completely, existing purely so humans reading the code later understand why something is written the way it is.
Run it yourself
Here's a small program with a comment and two println calls. This was actually executed to get the output shown below — try changing the text and running it yourself using the button under the example.
// This is a comment - Java ignores it
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
System.out.println("Welcome to Java.");
}
}Hello, World! Welcome to Java.
Next: variables and types — the primitive types, var type inference, and String.
Practice exercise
Add a comment above your code, then print "Learning Java one step at a time."