- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the purpose of Process class in Java?
The java.lang.Process is a subclass of Object class and it can describe the processes that are started by the exec() method of Runtime class. A Process object controls the process and gets information about it. The Process class is an abstract class, therefore, it cannot be instantiated. The important method s of the Process class are destroy(), exitValue(), getErrorStream(), waitFor(), getInputStream() and getOutputStream().
Syntax
public abstract class Process extends Object
Example
import java.util.concurrent.*; public class ProcessTest { public static void main(String[] args) throws Exception { Runtime runtime = Runtime.getRuntime(); System.out.println("Launching of Notepad Application"); Process process = runtime.exec("Notepad.exe"); // Launch a Notepad application System.out.println("Wait for 5 seconds"); p.waitFor(5, TimeUnit.SECONDS); System.out.println("Exit of Notepad Application"); process.destroy(); // destroy the application } }
In the above program, we are implementing a Process class. Whenever we can call the exec("Notepad.exe") method of Runtime class, it launches the notepad application and destroys the application after 5 seconds.
Output
Launching of Notepad Application Wait for 5 seconds Exit of Notepad Application
Advertisements