ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.