Home » Java programming language

Java ProcessBuilder environment() method with example

ProcessBuilder Class environment() method: Here, we are going to learn about the environment() method of ProcessBuilder Class with its syntax and example.
Submitted by Preeti Jain, on December 13, 2019

ProcessBuilder Class environment() method

  • environment() method is available in java.lang package.
  • environment() method is used to return Map interfaces of this process builder environment.
  • environment() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • environment() method may throw an exception at the time of returning map interfaces.
    SecurityException: This exception may throw when the calling thread does not have the right to access the process builder environment when the security manager exists.

Syntax:

    public Map environment();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is Map, it returns this process builder environment.

Example:

// Java program to demonstrate the example 
// of Map environment() method of ProcessBuilder 


import java.io.*;
import java.util.*;

public class Environment {
    public static void main(String[] args) throws Exception {
        // Instantiating ProcessBuilder object
        ProcessBuilder pr_bu = new ProcessBuilder();

        // By using environment() method is to retrieve the
        // environment of this pr_bu object
        Map m = pr_bu.environment();

        // Display the environment variable value
        System.out.println(m.get("PATH"));
    }
}

Output

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/isCOBOL2019R1/bin:/opt/cs/artifacts/Release/bin


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.