Question:
How to find out what environment variables are set?
Answer:
By using System.getenv() which returns an unmodifiable string map view of the current system environment.
Code:
import java.util.Map; public class EnvironmentTest { public static void main (String[] args) { Map<String, String> env = System.getenv(); for (String envName : env.keySet()) { System.out.println(envName + "=" + env.get(envName)); } } }
Output:
$ java EnvironmentTest TERM:xterm GNOME_KEYRING_CONTROL:/tmp/keyring-1HTIOT XDG_SESSION_PATH:/org/freedesktop/DisplayManager/Session0 SSH_AGENT_PID:1748 SHLVL:1 XFILESEARCHPATH:/usr/dt/app-defaults/%L/Dt SESSION_MANAGER:local/pats:@/tmp/.ICE-unix/1767,unix/pats:/tmp/.ICE-unix/1767 COLORTERM:Terminal XDG_SESSION_COOKIE:9f54a81594c5266e4a0ed3cd00000012-1406048016.654947-1739155940 GDMSESSION:xubuntu