
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
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
- Related Articles
- What is the purpose of System class in Java?
- What is the purpose of Runtime class in Java?
- What is the purpose of the flush() method of the BufferedWriter class in java?
- What is the purpose of the StringBuilder class in C#?
- What is the purpose of a process control block (PCB)?
- What is the purpose of interfaces in java?
- What is the purpose of private constructor in Java?
- What is the purpose of a constructor in java?
- What is the purpose of using JLink in Java 9?
- What is the purpose of a default constructor in Java?
- What is the purpose of using a dumpStack() method in Java?
- What is the purpose of using Optional.ifPresentOrElse() method in Java 9?
- What is the purpose of overriding a finalize() method in Java?
- What is the class "class" in Java?
- What is the super class of every class in Java?

Advertisements