How to Run Java from Command-line in Linux


Java is the world’s popular software development platform that James Gosling develops. It is designed to support multiple platforms like Linux, macOS and Windows. Mobile and Desktop applications can also be developed using Java language.

Java language is one of the most popular high-level object-oriented programming languages. It comes with a simple syntax and easily understandable for beginners, as it is very secure and economical to use. Java is the platform-independent software, and it also provides an auto garbage collection facility.

How to Run Java through Command-line

To run the java program in Linux, we need to verify if Java Development Kit (JDK) is available in the system and its version.

To confirm it, type the following command:

(Javac command-line tool is used for the compilation of java programs)

The Javac command tool is not available in my system. We have multiple commands to download it, as mentioned in the above image.

Let’s go with the default-jdk command to get it:

$ sudo apt install default-jdk

To verify the installation of javac, type:

Now, write a Java program in the text file and save it with .java extension.

Suppose I created a file named “” and write a simple program in it:

(Keep in mind that your class name should be the same as the file name)

Compile the file on the terminal using the javac command:

Now, execute the Java program by calling its class name in the terminal:


Java is the high-level language of the modern era supported by the Java Development Kit (JDK). JDK is a package that helps to run java and is used for the development of software packages.

Java language comes with a simple syntax that is easy to get for beginners, and it is one of the most usable object-oriented programming languages.

We have seen in this article that how to install and run Java applications on the terminal.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More