Java Reference
In-Depth Information
System.out.println("No such environment
variable exists");
}
} else {
Map<String, String> vars = System.getenv();
for(String var : vars.keySet()){
System.out.println(var + " = "
+ vars.get(var));
}
}
}
}
How It Works
The System class contains many different utilities that can aid in application develop-
ment. One of those is the getenv() method, which will return a value for a given
system environment variable.
You can also return the values from all variables, in which case those values are
stored in a map . A map is a collection of name/value pairs. Chapter 7 provides addi-
tional information about maps, including a recipe showing in detail how to iterate over
them.
The method invoked to obtain environment variable values in Listings 1-9 and 1-10
is the same. It's been overloaded to handle both cases shown in the solution. Pass the
name of a variable as a string if you want to obtain just that variable's value. Pass no
argument at all to get back the names and values of all variables that are currently set.
Summary
This chapter included recipes that allow you to get started working with Java quickly. It
covered installation of the JDK, to installation and use of the NetBeans IDE. The
chapter also covered basics such as declaring variables, compiling code, and document-
ation. The rest of this topic dives deeper into each of the different areas of the Java lan-
guage, covering a variety of topics from beginner to expert. Refer to this chapter for
configuration specifics as you work through the examples in the rest of the topic.
Search WWH ::




Custom Search