How do I get user home directory name?

package org.kodejava.example.lang;

public class UserHomeExample {
    public static void main(String[] args) {
        // This is the key that we used to obtain user home directory
        // in the operating system
        String userHome = "user.home";

        // We get the path by getting the system property with the 
        // defined key above.
        String path = System.getProperty(userHome);

        // We print your home path here
        System.out.println("Your Home Path: " + path);

On my machine it print something like:

Your Home Path: C:\Users\wsaryada


Your Home Path: /Users/wsaryada

How do I get operating system name and version?

package org.kodejava.example.lang;

public class OperatingSystemInfo {
    public static void main(String[] args) {
        // The key for getting operating system name
        String name = "";
        // The key for getting operating system version
        String version = "os.version";
        // The key for getting operating system architecture
        String architecture = "os.arch";

        System.out.println("Name   : " + System.getProperty(name));
        System.out.println("Version: " + System.getProperty(version));
        System.out.println("Arch   : " + System.getProperty(architecture));

Below is the example result of our program, of course it could be different from what you’ll see in your machine because it depends on the operating system that you use.

Name   : Windows XP
Version: 5.1
Arch   : x86


Name   : Mac OS X
Version: 10.12.6
Arch   : x86_64

How do I get operating system temporary directory / folder?

To get the location of temporary directory we can use the System.getProperty(String) method and pass a property key "" as the argument to the method.

package org.kodejava.example.lang;

public class TempDirExample {
    public static void main(String[] args) {
        // This is the property name for accessing OS temporary directory
        // or folder.
        String property = "";

        // Get the temporary directory and print it.
        String tempDir = System.getProperty(property);
        System.out.println("OS temporary directory is " + tempDir);

How do I get Java Runtime Environment (JRE) version?

This code snippet show you how to get Java / JRE version by reading the java.version from the system properties. We use the System.getProperty(String key) method to get the value of the property and it will be returned as a string value.

package org.kodejava.example.lang;

public class JavaVersion {
    public static void main(String[] args) {
        // You can get the version of Java Runtime Environment
        // running on your machine by reading the "java.version"
        // property value from the system.
        String version = System.getProperty("java.version");

        // Just show to the world your JRE version :)
        System.out.println("Java Version = " + version);

In my computer it print the following output:

Java Version = 1.8.0_121