Wednesday, June 27, 2012

Environment variables

Environment variables:

These are variables which controls the behavior of applications and various processes dynamically.
for example %TEMP% environment variable can be used by a processes to store temporary data used by it at the path provided by %TEMP% variable.
Environmental variables enhances the flexibility of applications in two ways: 
1. user can edit the environment variables an application uses to change its behavior,any time.
2. As the environmental variables are external to the applications they are loaded at run-time.So its possible to change the behavior of application without recompiling them.

Note: Environment variables can be provided only specific names which can be detected by the processes which use them.So it is not in our hands to decide the Environment Variable Name but We can change the paths to which Environment variables points.
For Example:     
%HOME% Environment Variable is used by various processes to locate the root user's home directory which is by default "C:\users\<user account>" in every windows operating system.
but we can change this path to any other say:  "d:\home"
but if we attempt to change variable name from %HOME% to any other say %MYHOME% then this Environment Variable is of no use to any process which are coded to use %HOME% Environment variable.

There are many standard Environment variables:

  • HOME (points to the user home directory) 
  • TEMP  or TMP (point to the path used for storing temporary data)
  • NUMBER_OF_PROCESSORS (no of processors deployed in your system)
  • OS (represents Operating System)
       classpath variable is used to locate class files used inside java 
       whenever a class is need to be loaded in a java application the JVM    
       searches for appropriate class file in all locations starting from first path 
       in the CLASSPATH variable.If the class file is present in the current 
       working directory and you dont want JVM to search through all path   
       locations in the CLASSPATH variable just add ".;" to the beginning of 
       your CLASSPATH variable. in ".;" the dot "." represents current working 
       directory and ";" is the separator.
  • path:
          path environment variable is used to provide paths to the executable  
          files and commands of the operating syatem or some other application 
       like Compilers and MySQL. We use path variables for individual 
       commands so that we are not required to provide full directory path 
       every time we execute the commands. 
       Example: we provide path "c:\program files\java\jdk1.6.0\bin" in the   
       path variable because we need to use javac and java commands to 
       compile and execute java applications from command prompt and these 
       executable commands are located inside the bin directory of our java 
       installation directory.after setting path variable we can directly use javac
       and java commands in command prompt like any other DOS command. 
  • USERNAME  (stores the username for admin account)     etc.

Most of the above Environment variables must have are already declared on your system if you will check for them,because these above Environment variables are Operating System oriented.

How to check Environment Variables:
there are two ways
1. Open command prompt
    give command:   set
    It will display all the variables on the console.  
    note:If you want to look at some specific variables for ex. if you want to
    display variables with names starting with character L 
    give command: set L
2. Open control panel
    select System > advance system settings > Environment variables

How to set Environment Variable:
there are two ways
1. Open command prompt
    give command: set <variable name>=<path>
2. Open control panel > system > advance system settings >Environment    
    variables > new
    then provide variable name and value in the fields provided.

How to delete  Environment variable
again there are two ways
1. Open command prompt
    give command: set <variable name to be deleted>=
    this way the value for the variable will be set to null value in other words   
    it will be removed.
2. Open  control panel > system > advance system settings >Environment
    variables  select variable and click on delete.

note: You may have seen environment variable names enclosed in %---%
this syntax is used with those Environment variables which are used in other paths like path=%JAVA_HOME%/bin;
this way %JAVA_HOME% will be automatically replaced with value of JAVA_HOME Environment variable.


No comments:

Post a Comment