java – How to run a program given a source file


I wrote a simple Hello World program in notepad and saved it as it should.

What to do next to get a program out of it?


on the gnu/linux operating system, with the javac and java programs installed, this is the file:

class helloworld {
    public static void main(String[] args) {
        System.out.println("hello world!");

saved in the current directory as can be compiled with the command:

$ javac

and run the resulting helloworld.class file with the command:

$ java helloworld


hello world!

You can install the javac and java programs in different ways, the simplest and most logical one is from the repository of your distribution. for example, on debian -major distributions, this can be done with the command:

$ sudo apt install default-jdk
Scroll to Top