Get Java Home Directory


Use the System.getProperty() method in Java to get the Java Home Directory.

It’s syntax is −

String getProperty(String key)

Above, the key is the name of the system property. Since, we want the Java Home Directory name, therefore we will add the key as −

java.home

The following is an example −

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      System.out.println("Get Java Home Directory = " + System.getProperty("java.home"));
      System.out.print("Java Specification Version: ");
      System.out.println(System.getProperty("java.specification.version"));
      System.out.print("java Runtime Environment (JRE) version: ");
      System.out.println(System.getProperty("java.version"));
   }
}

Output

Get Java Home Directory = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.fc26.x86_64/jre
Java Specification Version: 1.8
java Runtime Environment (JRE) version: 1.8.0_141

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

654 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements