DEV Community

Cover image for Java By Example: Hello World
Alan
Alan

Posted on

Java By Example: Hello World

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

class Helloworld {
  public static void main(String[] args) {
    System.out.println("Hello world!");
  }
}
Enter fullscreen mode Exit fullscreen mode

To run the program, we need to build our programs into Byte Code.
We can do this using javac Helloworld.java.
We can then execute the built java .class file directly.

javac Helloworld.java
ls
# Helloworld.java Helloworld.class

java Helloworld
# Hello world!
Enter fullscreen mode Exit fullscreen mode

Top comments (0)