Introduction🎯
Java is a powerful programming language that helps develop mobile apps, web apps, games, etc. It offers multiple functions, and one such function is Java System getenv.

In this article, we will explore how the Java system getenv works.
Also read, Duck Number in Java and Hashcode Method in Java
Java System getenv
Java System.getenv()🔶
Syntax:
getenv()
System.getenv() is provided in the Java System class. The environment variable value set in the current system can be obtained using this function. Java system getenv function returns an unchangeable string map view in the form of Map<String,String> of the current system environment.
To better understand, let’s look at an example of how the Java system getenv works.
Example1
Now let’s look at another example to get the Map view of the System Environment.
import java.util.Map;
public class Example1 {
public static void main(String[] args) {
Map<String, String> env = System.getenv();
for (String name : env.keySet()) {
System.out.format("%s = %s%n", name, env.get(name));
}
}
}
Output

Note: The output may vary depending on the environment variables that you have configured on your PC.
Java System.getenv(String key)🔶
Syntax :
System.getenv(String key)
where key denotes the environment variable whose values the user wants. Let’s look at the examples of how the getenv function with parameters works.
Example2
Let’s look at a Java program to get the value of a specific environment variable.
public class Example2 {
public static void main(String[] args)
{
// Get the value of the environment variable TEMP
System.out.println(System.getenv("TEMP"));
// Get the value of the environment variable OS
System.out.println(System.getenv("OS"));
// Get the value of the environment variable PROCESSOR_ARCHITECTURE
System.out.println(System.getenv("PROCESSOR_ARCHITECTURE"));
}
}
Output

Note: The output may vary depending on the environment variables that you have configured on your PC. You can try by yourself on java online compiler.
We hope you have learned everything about the Java system getenv. 🙌
Check out this article - Upcasting and Downcasting in Java
Must Read: Java System Out Println