java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to get Java Home directory?

To get Java Home directory we can obtain it from system properties using the java.home key.

package com.javacoderanch.example.lang;

public class JavaHomeDirectory {
    public static void main(String[] args) {
        String javaHome = System.getProperty("java.home");
        System.out.println("javaHome = " + javaHome);
    }
}