JaJava · Lesson 1 of 9
Hello, World!
The famous Java Hello World. Note: it requires a class. And the class name must match the file name. And everything is public static void. Java is very thorough.
In Java, all code must be inside a class. The entry point is a static method called main. The full signature — public static void main(String[] args) — is required exactly. Welcome to Java.
Compile with javac HelloWorld.java, then run with java HelloWorld. Java 11+ added the ability to run single-file programs directly: java HelloWorld.java. The JVM (Java Virtual Machine) runs the compiled bytecode — this is the "run anywhere" part.
◆ Note
Java file names must exactly match the public class name, including case. HelloWorld.java must contain public class HelloWorld. This is a compile-time error if they don't match.
Java file names must exactly match the public class name, including case. HelloWorld.java must contain public class HelloWorld. This is a compile-time error if they don't match.