Java How to – Get Environment Variables

Published on February 18, 2016 by Senthil Kumar

Filed under Java

Last modified February 17, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 8178 times

Problem Statement

You need to programmatically get the values of the environment variables from your java program.


Use java.lang.System.getenv method to get the environment variables from your java program from Java JDK 1.5 and higher version. You can pass the "PATH" as parameter to the method to retreive the path from the environment variable.

public class Main {

public static void main(String[] args) {

    System.out.println("Environment Path = " + System.getenv("PATH"));



When no arguments are passed, it returns all the environment variables.

Leave a Comment


You might be Interested in these Posts

Video - Angular Router - Brian Ford

Video - Angular Router - Brian Ford ...

Video - An Angular2 Todo App: First look at App Development in Angular2

In this screencast , David East , one of the core contributor of the Angular provides a glimpse of A...

Video - Getting started with Angular 2

In this screencast , Alex Eagle , developer on the Angular team talks about Angular 2 developer prev...