how to execute shell commands in java

how to execute shell commands in java
/**
 * @author lautturi.com
 * Java example: execute shell command / command line in java
 */

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

public class Lautturi {
	
	public static void main(String[] args)  {

		ProcessBuilder pb = new ProcessBuilder("ping", "localhost");
		pb.inheritIO();
		try {
		    Process p = pb.start();
		    int exitStatus = p.waitFor();
		    System.out.println(exitStatus);
		}
		catch (InterruptedException | IOException x) {
		    x.printStackTrace();
		}
	}
	
}
Source‮al.www:‬utturi.com
Created Time:2017-09-11 15:51:20  Author:lautturi