Home Java Java-get-example Java example program to get the environment variable
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Java example program to get the environment variable

Advertisement
The getenv() method of the java.lang.System provide us the functionality to get the environment variable value.

Java example program to get the environment variable

     

java get environment variable

The getenv() method of the java.lang.System provide us the functionality to get the environment variable value. To get the single environment variables value we have to call the getenv("environment variable") method where environment variable is a value that we want to evaluate. Here is the simple example of getting environment variable "WINDIR". 

Here is the full code of GetEnvironmentVariable.java as follows:

GetEnvironmentVariable.java

import java.util.*;
import java.lang.*;

public class GetEnvironmentVariable
{
  public static void main(String args[]) {
  try{
  String environmentVariable = System.getenv("WINDIR");
  System.out.print("Environment Variable are =>"+environmentVariable);
  }catch (Exception e){
  System.out.println("Exception caught ="+e.getMessage());
  }
  }
}

Output:

C:\javaexamples>javac GetEnvironmentVariable.java

C:\javaexamples>java GetEnvironmentVariable
Environment Variable are =>C:\WINNT

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 24, 2008

Related Tutorials

Ask Questions?    Discuss: Java example program to get the environment variable  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com