No history yet

Java Basics

The Rules of the Road

Every language has rules. In English, we use grammar and punctuation to make sense. In Java, we use syntax. It’s the set of rules that defines how a Java program is written and interpreted. If you get the syntax wrong, the computer won't understand what you want it to do.

Let's start with the classic first program everyone writes: "Hello, World!". It's a simple program that just prints that phrase to the screen.

public class HelloWorld {
    public static void main(String[] args) {
        // This line prints text to the screen
        System.out.println("Hello, World!");
    }
}

Let's break that down. Don't worry about memorizing everything right now; just get a feel for the structure.

  • public class HelloWorld { ... }: Every Java program needs at least one class, which acts as a container for your code. We've named ours HelloWorld.
  • public static void main(String[] args) { ... }: This is the starting point of your program. When you run the code, Java looks for this exact main method and begins executing whatever is inside its curly braces {}.
  • `System.out.println(