Your first class and the main method
◈ 3 cardsThe entry point every Java program needs.
The shape of a program
Every line of Java lives inside a class. Execution starts at a special method called main, which the JVM looks for and calls. Its signature is fixed — memorise it:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Reading it piece by piece:
public class Hello— declares a class namedHello. A public class must live in a file of the same name:Hello.java.public static void main(String[] args)— the entry point.publicso the JVM can call it,staticso it runs without creating an object,voidbecause it returns nothing, andString[] argsreceives command-line arguments.System.out.println(...)— prints a line to standard output.
Every statement ends with a semicolon; blocks are wrapped in { }.