How to Create, Compile and Run Java Program on Linux Mint

First install the required your favorite JDK on your computer such as Oracle Java, OpenJDK or IBM Java. If you don’t have any, please follow the below below link to install Oracle JDK 8 on Linux Mint.

In this tutorial we are going to work manually with Java programming without the use of an IDE.

Open Terminal. To open terminal click the Main Linux Mint Menu, then go to system tools and select Terminal or type terminal in the search field or click the Terminal icon in taskbar.

terminal

Create a new directory in your home folder name it as java to save your Java programs. To do it, in your terminal type the below command and hit enter.

mkdir java

Then type

cd java

This will change your current working directory into new java directory.Then type

xed MyFirstJava.java

It will open the default text editor xed on linux mint.And type the below jave code on it. Then save and exit it. You can also use any installed text editor to edit the code. like nano and gedit.

public class MyFirstJava
{
public static void main(String[] args) {
System.out.println("MyFirstJava on Linux Mint 18 - CONNECTwww.com");
}
}

java-program

After that to compile the MyFirstJava.java file into a Java class file type the command below.

javac MyFirstJava.java

Then to run or execute your Java class fileĀ  type the below command in terminal and hit enter.

java MyFirstJava

run-java-in-terminal

If you liked this article, please subscribe to our YouTube Channel. You can also stay connected with us on X (Twitter) and Facebook.



Also Read:  How to Install WildFly Application Server on Ubuntu

Leave a Reply