Java Program to Shutdown Computer

« Previous Program Java Tutorial »

Shutdown Computer

To shutdown computer in Java programming, you have to use the command shutdown -s -t. You can also specify the time after which you want to make your computer turn off or shutdown.

Java Programming Code to Shutdown Computer

Following Java program ask to the user to enter the number of seconds to make your computer shutdown after the specified number of seconds :

/* Java Program Example - Shutdown Computer */

public class JavaProgram
    public static void main(String args[]) throws IOException
        Runtime runtime = Runtime.getRuntime();
        BufferedReader br=new BufferedReader(new InputStreamReader(;
        System.out.print("Enter No. of Seconds after which You want your Computer to Shutdown :");
        long a=Long.parseLong(br.readLine());
        Process proc = runtime.exec("shutdown -s -t " +a);

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Java Online Test

« Previous Program Java Tutorial »

© Copyright 2021. All Rights Reserved.