How to: Compile and run a .java file in Ubuntu and Debian from the Terminal

created by BasicSysAdmin

Tags: Linux, Ubuntu, Ubuntu 14.04, Ubuntu 16.04, Debian, Debian 7

Jul 09, 2016

Compiling and Running a .java file in Ubuntu

The first thing you will need to do is to open a Terminal Window. You can do this by following the images below.

Once you have opened terminal, you will need to navigate to the directory you have stored your .java file. You can use this by using the cd command showing in the screenshot below. You can then view everything in that directory by typing the ls command.

The final thing is to compile and run our program. The command for this is as follows
javac Classname.java

to run the program, we type in
java Classname

You can see a full example in the image below.