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 … Read more…

Java-Destroy

Destroy The destroy( ) abstract method defined by Process class. This method is used to terminate the process. Program Program Source public class Javaapp { public static void main(String[] args) { Runtime rt = Runtime.getRuntime(); Process pr = null; try { pr = rt.exec(“mspaint”); try{ Thread.sleep(5000); }catch(InterruptedException ie) { System.out.println(“Thread Interrupted”); } pr.destroy(); }catch (Exception … Read more…

Java-WaitFor and ExitValue

WaitFor and ExitValue The waitFor( ) method return the exit code returned by the process. This method does not return until the process from which it is called terminates. The exitValue( ) method return an exit code obtained from a subprocess. In the following program, an object of the Runtime class is first obtained by invoking … Read more…

Java-ProcessBuilder

ProcessBuilder ProcessBuilder provides another way to start and manage processes. ProcessBuilder offers more control over the processes. To create a process using ProcessBuilder, simply create an instance of ProcessBuilder, specifying the name of the program and any needed arguments. To begin execution of the program, call start( ) on that instance. Here is an example … Read more…

Java-Process with Specific File

Process with Specific File ProcessBuilder offers more control over the processes. For example, you can set the current working directory. Here is an example that executes the Windows paint editor. Notice that it specifies the location and specifies the name of the file to edit as an argument. Program Program Source import java.io.File; public class Javaapp … Read more…