Java by Example: Hello World

Our first program will print the classic “hello world” message. Here’s the full source code.

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

To run the program, put the code in HelloWorld.java and use javac to compile and java to run.

/
$ javac HelloWorld.java
$ java HelloWorld
Hello, World!

Now that we can compile and run basic Java programs, let’s learn more about the language.

Next example: Values.