×

Java Programs

Java Practice

Java program to run an application - Run Exe using Java program

This program will open (run) applications (Notepad, Calculator) using Java program. To open/run application we are using instance of Runtime.getRuntime() and method exec().

Run an application using Java program

//Java program to run an application.

import java.util.*;

class OpenNotepad {
  public static void main(String[] args) {
    Runtime app = Runtime.getRuntime();
    try {
      //open notepad
      app.exec("notepad");
      //open calculator
      app.exec("calc");
    } catch (Exception Ex) {
      System.out.println("Error: " + Ex.toString());
    }
  }
}

Output

    
    Notepad and Calculator will be opened.

Core Java Example Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.