Reading Environment Variables - Java Object Oriented Design

Java examples for Object Oriented Design:main method

Description

Reading Environment Variables

Demo Code

public class Main { 
    public static void main(String[] args) { 
        if (args.length > 0) { 
            String value = System.getenv(args[0]); 
            if (value != null) { 
                System.out.println(args[0].toUpperCase() + " = " + value); 
            } else { 
                System.out.println("No such environment variable exists"); 
            } //from ww w  . j  a v a 2 s. c  om
        } else { 
            System.out.println("No arguments passed"); 
        } 
    } 
}

Result


Related Tutorials