Java Tutorial
'System.getenv' getenv method of System class is used to get the system environment variables.
Need to pass environment variable name as argument to get the system environment variable value in java program.
This java program is used to get the operating system family.
If Windows_NT is a family of operating systems which includes Windows XP, Windows Vista, Windows 7, Windows 8 and Windows 10 etc..
public class GetEnvTest { public static void main(String[] args){ String operatingSystem = System.getenv("OS"); System.out.println("Operating System: "+ operatingSystem); } }Output:
D:\Java_Programs>javac GetEnvTest.java D:\Java_Programs>java GetEnvTest Operating System: Windows_NT
This java program is used to get the system path environment variable.
public class GetEnvTest { public static void main(String[] args){ String pathEnv = System.getenv("PATH"); System.out.println("PATH Set on Environment: "+ pathEnv); } }Output:
D:\Java_Programs>javac GetEnvTest.java D:\Java_Programs>java GetEnvTest PATH Set on Environment: C:/Program Files/Java/jre1.8.0_181/bin/server; C:/Program Files/Java/jre1.8.0_181/bin; C:/Program Files/Java/jre1.8.0_181/lib/amd64; C:\Program Files (x86)\Common Files\Oracle\Java\javapath; C:\Program Files (x86)\Intel\iCLS Client\; C:\Program Files\Intel\iCLS Client\;C:\Windows\system32; C:\Windows;C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\;
This java program is used to get windows directory location on system and gets from system environment variable.
public class GetOSTest { public static void main(String[] args){ String windir = System.getenv("windir"); System.out.println("windir on Environment: "+ windir); } }Output:
D:\Java_Programs>javac GetEnvTest.java D:\Java_Programs>java GetEnvTest windir on Environment: C:\WINDOWS
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page