Run Java Program in Ubuntu 18.04. The program will be run using Oracle's OpenJDK JDK 8.

  • Check if Java Runtime Environment(JRE) is installed in machine:

    java -version
    

    If JRE is installed it will show the version information similar to following:

    openjdk 11.0.5 2019-10-15
    OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04)
    OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04, mixed mode)
    

    If you do not have installed JRE, install JRE using:

    sudo apt-get install openjdk-8-jre
    
  • Check if Java compiler is installed in machine:

    javac -version
    

    If Java compiler is installed it will show the version information similar to following:

    javac 1.8.0_232
    

    If you do not have installed Java compiler, install it using:

    sudo apt-get install openjdk-8-jdk
    
  • Go to any directory and create a demo Java program. For example, we are going to create Student.java as following:

    class Student{
    	public static void main(String[] args){
    		System.out.println("Hello from Student class");
    	}
    }
    
  • Compile the Java class using:

    javac Student.java
    
  • Run the compiled program using:

    java Student
    

    You will see the output like below:

    Hello from Student class
    

alt Run Java Program in Ubuntu 18.04

Reference:

Advertisement

Citation

Click to select citation style

Shovon, A. R. (2020, January 28). Run Java Program in Ubuntu 18.04. Ahmedur Rahman Shovon. Retrieved June 22, 2024, from https://arshovon.com/blog/run-java-program-ubuntu-18-04/

Shovon, Ahmedur Rahman. “Run Java Program in Ubuntu 18.04.” Ahmedur Rahman Shovon, 28 Jan. 2020. Web. 22 Jun. 2024. https://arshovon.com/blog/run-java-program-ubuntu-18-04/.

@misc{ shovon_2020,
    author = "Shovon, Ahmedur Rahman",
    title = "Run Java Program in Ubuntu 18.04",
    year = "2020",
    url = "https://arshovon.com/blog/run-java-program-ubuntu-18-04/",
    note = "[Online; accessed 22-June-2024]"
}
Run Java Program in Ubuntu 18.04