Every programming journey starts with Hello World. Let’s write our first Java program.
The Code
Create a file named HelloWorld.java:
| |
Understanding the Code
public class HelloWorld- Defines a public class. In Java, the filename must match the class name.public static void main(String[] args)- The entry point of every Java application.System.out.println()- Prints text to the console followed by a newline.
Running with Docker
The easiest way to run this without installing Java locally:
| |
Running Locally
If you have Java installed (JDK 11+):
| |
Expected Output
Hello, World!
Key Concepts
- Java is compiled - Source code (
.java) is compiled to bytecode (.class) - Bytecode runs on the JVM - Java Virtual Machine executes the bytecode
- Class names matter - The filename must match the public class name
- main() is special - This is where program execution begins
Next Steps
Continue to Variables and Data Types to learn about storing and manipulating data in Java.