How to run system commands Java (Linux environment)

In Python, we use

import os

os.system(‘sudo vncserver stop’)


What about in Java. Below is one example.

public class java_system_call {
    public static void main(String args[]) {
        String s = null;
        try {
        // run the Unix "ps -ef" command
            // using the Runtime exec method:
            Process p = Runtime.getRuntime().exec("ps -ef");
            BufferedReader stdInput = new BufferedReader(new
            BufferedReader stdError = new BufferedReader(new
            // read the output from the command
            System.out.println("Here is the standard output of the command:\n");
            while ((s = stdInput.readLine()) != null) {
            // read any errors from the attempted command
            System.out.println("Here is the standard error of the command (if any):\n");
            while ((s = stdError.readLine()) != null) {
        catch (IOException e) {
            System.out.println("exception happened - here's what I know: ");