Java Programming Tutorials

Java programming tutorials with many code examples!

Java “Hello world!”


How to write “Hello, world!” in Java?


  1. Create a package for a class:
    mkdir -p com/farenda/solved
  2. Create a file com/farenda/solved/ with content:
    package com.farenda.solved;
    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello, world!");
  3. Create directory for compiled classes:
    mkdir classes
  4. Compile source:
    javac src/com/farenda/solved/ -d classes
  5. Run compiled code:
    java -cp classes com.farenda.solved.HelloWorld


Hello, world!
Was it helpful? Share!