Java FAQ: How to print system environment variables

Java FAQ: How do I print system environment variables from a Java application?

Here's a source code example that shows how to print system environment variables from a Java program:

package com.devdaily.javasamples;

import java.util.Map;

/**
 * Demonstrates how to print system environment variables 
 * from a Java application.
 * Created by Alvin Alexander, http://devdaily.com.
 */
public class JavaSystemEnvironmentVariables
{
  
  public static void main(String[] args)
  {

    // get the system environment variables
    System.out.println("Environment Variables");
    Map

System environment variables output

Here's the output from this sample program, showing the system environment variables:

Environment Variables
SECURITYSESSIONID = 2790d870
USER = al
HOME = /Users/al
APP_ICON_22269 = ../Resources/Eclipse.icns
JAVA_JVM_VERSION = 1.5.0
__CF_USER_TEXT_ENCODING = 0x1F5:0:0
PATH = /usr/bin:/bin:/usr/sbin:/sbin
SHELL = /bin/bash
JAVA_MAIN_CLASS_22331 = com.devdaily.javasamples.JavaSystemEnvironmentVariables

As you can tell from that output, I created this example program on a Mac OS X computer.