Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML

Search:
   Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML Facing Programming Problem? Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
Get Environment Variable Java
In this example we are getting environment variable. To get the environment variable we use getenv() method.
 
 

Get Environment Variable Java

                         

In this example we are getting environment variable. To get the environment variable we use getenv() method.

Map is an interface that stores the objects in the form of key/value pairs. Map interface does not allow duplicate keys. Set is also an interface that  extends the Collection interface and like the Map it also does not allow the duplicate elements.

Methods used:

getenv(): The method getenv() is an static method of the System class and gets the information about environment variable.

get(key): This method is used to get the key values from a map class.

The code of the program is given below:

import java.util.Map;
import java.util.Set;
import java.util.Iterator;
 
public class EnvironmentInformation{
    public static void main(String[] args){
    Map map = System.getenv();
    Set keys = map.keySet();
    Iterator iterator = keys.iterator();
    System.out.println("Variable Name \t Variable Values");
    while (iterator.hasNext()){
      String key = (Stringiterator.next();
      String value = (Stringmap.get(key);
      System.out.println(key + "     " + value);
      }
  }
}

The output of the program is given below:

C:\rajesh\kodejava>javac EnvironmentInformation.java
C:\rajesh\kodejava>java EnvironmentInformation
Variable Name    Variable Values
USERPROFILE     C:\Documents and Settings\Administrator
PATHEXT     .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
=ExitCode     00000000
TEMP     C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
SystemDrive     C:
ProgramFiles     C:\Program Files
Path     C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;
C:\jdk1.6.0\bi
HOMEDRIVE     C:
PROCESSOR_REVISION     0409
=C:     C:\rajesh\kodejava
USERDOMAIN     DEMO1
ALLUSERSPROFILE     C:\Documents and Settings\All Users
PROCESSOR_IDENTIFIER     x86 Family 15 Model 4 Stepping 9,
 GenuineIntel
Os2LibPath     C:\WINNT\system32\os2\dll;
TMP     C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
LOGONSERVER     \\DEMO1
CommonProgramFiles     C:\Program Files\Common Files
=::     ::\
PROCESSOR_ARCHITECTURE     x86
OS     Windows_NT
HOMEPATH     \
PROMPT     $P$G
PROCESSOR_LEVEL     15
classpath     C:\apache-tomcat-5.5.23\common\lib;
COMPUTERNAME     DEMO1
windir     C:\WINNT
SystemRoot     C:\WINNT
NUMBER_OF_PROCESSORS     2
USERNAME     Administrator
ComSpec     C:\WINNT\system32\cmd.exe
APPDATA     C:\Documents and Settings\Administratorion Data

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

Hi sree,
I think you are using the jdk4 version of java. So, this error will occur because System.getenv() method is not lying in the that version of jdk. You can user jdk5 or latest version of jdk. This is the solution.

Thanks & Regards
Chandan Kumar Verma
Roseindia Team Member.

Posted by Chandan Kumar Verma on Thursday, 07.12.07 @ 12:42pm | #21133

I am tying but couldn't solve the error.Can any one please help me to solve the error.
EnvironmentInformation.java:10: getenv(java.lang.String) in java.lang.System can
not be applied to ()
Map map = System.getenv();
^
1 error

Posted by sree on Thursday, 07.12.07 @ 11:15am | #21128

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.