Sunday, 25 June 2017

Get Java Installation Directory in Java ~ foundjava

Single statement to get the directory where Java is installed in your computer.

Java Installation Directory


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

java.home: It is the property for which the value is the java home, the directory where Java is installed in the PC in which this program is executed.

getProperty(): This is a method of java.lang.System class which takes property name and returns property values.

Sample Output


C:\Program Files\Java\jre7

No comments:

Post a Comment