Java and JVM (Java Virtual Machine) are required for many types of popular software, including Tomcat, Jetty, Glassfish, Cassandra and Jenkins.
check if Java is already installed:
java -version
First, update the package lists:
sudo apt update
Install OpenJRE:
sudo apt install default-jre
Type y (yes) and press Enter to resume installation.
Confirm Java version:
java -version
You may need the Java Development Kit (JDK) in addition to the JRE in order to compile and run some specific Java-based software. To install the JDK, execute the following command, which will also install the JRE:
sudo apt install default-jdk
Verify that the JDK is installed by checking the version of javac, the Java compiler:
javac -version