Showing posts with label Java Code for Notepad. Show all posts
Showing posts with label Java Code for Notepad. Show all posts

Monday, 25 January 2016

Java Program to open a Notepad window

Notepad window open program using Java Code

How to open Notepad using Java


We can open the Windows Notepad using Java code. The below Java program shows how to open a Notepad Window in Java


Program


//A small java program to open Notepad window on the screen.

import java.util.*;
import java.io.*; 
class Notepad 
{
  public static void main(String[] args) 
  {
      Runtime rs = Runtime.getRuntime();
       try
        {
              rs.exec("notepad");
        }
       catch (IOException e)
       {
             System.out.println(e);
       }   
  }
}

Output















Notes: 

Runtime : Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.

getRuntime : Returns the runtime object associated with the current Java application. Most of the methods of class Runtime are instance methods and must be invoked with respect to the current runtime object.