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:If JRE is installed it will show the version information similar to following:
java -versionIf you do not have installed JRE, install JRE using: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)sudo apt-get install openjdk-8-jre - Check if Java compiler is installed in machine:If Java compiler is installed it will show the version information similar to following:
javac -versionIf you do not have installed Java compiler, install it using:javac 1.8.0_232sudo apt-get install openjdk-8-jdk - Go to any directory and create a demo Java program. For example, we are going to create
Student.javaas 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:You will see the output like below:
java StudentHello from Student class

Reference:
Advertisement

