What is the Difference between Runtime and RunTime java API's?

Questions by rasaya

Showing Answers 1 - 9 of 9 Answers

Arun K. Rajput

  • Nov 22nd, 2006
 

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. 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.

Runtime r=Runtime.getRuntime();
 Process p=r.exec("notepad.exe");
 try
 {
  Thread.sleep(1000);
  p.destroy();
  System.out.println("notepad destroyed....");
 }catch(Exception e){
  e.printStackTrace();
  
 }

  Was this answer useful?  Yes

santh kumar

  • Dec 13th, 2006
 

Runtime is one of classes in Java and it's super class remains same as we know(java.lang.Object). A java Programme can have only a single instance of this class "Runtime". that means, Runtime rt = Runtime.getRuntime(); Runtime rt1 = Runtime.getRuntime(); // U can't create more than one instance like this. An application cant create its own instance of this class. For example, class Test { Runtime rt = new Test(); // U cant instantiate like this. } by using this object of Runtime, u can find how many processors are running in JVM, how is totalMemory,freeMemory,maxMemory like this. There is no RunTime phrase in the JavaWorld.It's just a litigate question.with regards,santh

  Was this answer useful?  Yes

Vibs

  • May 17th, 2007
 

You can write

public static void main(String a[])

{
Runtime rt = Runtime.getRuntime();
System.out.println("result::"+rt);

try
{rt.exec(
"notepad.exe");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Runtime rtq = Runtime.getRuntime();
System.out.println("result::"+rtq);

try
{rtq.exec(
"calc.exe");

} catch (IOException e) {

// TODO Auto-generated catch block
e.printStackTrace();
}
}

output will be


result::java.lang.Runtime @10b62c9 
result::java.lang.Runtime @10b62c9

Notepad and calculator will be opened.
So in short Runtime.getRuntime() returns same instance..but it does not mean that u cant write Runtime rt = Runtime.getRuntime() and Runtime rt1 = Runtime.getRuntime(). U can always have 2 object reference..it points to single instance.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions