Java-Get Runtime Environment

Get Runtime Environment

The Runtime class encapsulates the run-time environment. We get a reference to the Runtime object by invoking the getRuntime( ) method, which is a static method in the Runtime class. The methods in this class control the state and behavior of the Java Virtual Machine. The exec( ) method is an important method in the Runtime class. It will create an object of type Process. The Process class is an abstract class. It encapsulates an executing program.

In the following program, an object of the Runtime class is first obtained by invoking the static method getRuntime( ). An object of the Process class is also created. Subsequently, the in-built mspaint is started.

Program

0

Program Source

public class Javaapp {
  
    public static void main(String[] args) {
        
        Runtime rt = Runtime.getRuntime();
        Process pr = null;
        try {
            pr = rt.exec("mspaint");
        }catch (Exception e)
        {
            System.out.println("Error Executing Programs");
        }
    }
}

Leave a Comment