Create your first program in Java 11 on Ubuntu 22.04 or Debian 11

Atualizado em 2026-10-24 19:01:28 13 visitas

Java is one of the most widely used programming languages thanks to its great versatility, portability, and its ability to create robust and scalable applications. It is an object-oriented language with a large number of libraries and tools that facilitate the development of applications, whether they are for desktop, web, or mobile.

In this manual, we will teach you how to create your first program using Java 11 in Ubuntu 22.04 or Debian 11, where we will display the text 'Hello World!' via our Operating System's console.

The first step will be to install the OpenJDK 11 development environment to be able to compile and run our applications made in Java.

sudo apt install openjdk-11-jdk-headless -y

Once the installation is finished, you must create the file where we will write the program's code. In our case, we will call it HelloWorld.java. You can create the file with the following command:

touch HelloWorld.java

The next step will be to open the file with your preferred editor. We will do it with the nano editor:

nano HelloWorld.java

The program's code will be the following:

// Your first program in Java 11
class HelloWorld {
    public static void main(String[] args) {
        System.out.println('Hello World!');
    }
}

ATTENTION It is very important that the class name (line 2 of the program code) be the same as the filename (without the '.java' extension).

Once the file is saved, we must compile our program with the following command:

javac HelloWorld.java

And finally, we can run it:

java HelloWorld

We will see how the text Hello World! appears on our console screen. This means that the program has been executed correctly.