All About Class Runtime in Java

0
209
Spread the love
  • 29
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    138
    Shares

Class Runtime in Java

Every Java application has a single instance of class Runtime. Runtime class allows the application to interact with the environment in which the application is running. The current runtime can be obtained from the getRuntime() method as an application can not create its own instance of this class.

Runtime class encapsulates a number of platform-dependent system functions. The static method getRuntime() returns the Runtime object for the current platform, and this object can be used to perform system functions in a platform-independent way.

exec() starts a new process running externally to the interpreter.

exit() causes the Java interpreter to exit and return a specified return code.

freeMemory() returns the approximate amount of free memory.

totalMemory() returns the total amount of memory available to the Java interpreter.

gc() forces the garbage collector to run synchronously, which may free up more memory.

runFinalization() forces the finalize() methods of unreferenced objects to be run immediately. This may free up system resources that those objects were holding.

load() loads a dynamic library with a fully-specified pathname.

loadLibrary() loads a dynamic library with only the library name specified; it looks in platform-dependent locations for the specified library. These libraries generally contain native code definitions for native methods.

traceInstructions() and traceMethodCalls() enable and disable tracing by the interpreter.

Note

  • some of the Runtime methods are more commonly called via the static methods of the System class.
  • Any processes run outside of Java may be system-dependent.

The structure of the class-Runtime is as follows :

public class java.lang.Runtime extends java.lang.Object{
//methods:
public Process exec(String command) throws IOException;;
public Process exec(String command,String exp[]) throws IOException;;
public Process exec(String commandArray[])throws IOException;;
public Process exec(String commandArray[],String exp[])throws IOException;;
public void exit(int status);
public native long freeMemory();
public native void gc();
public InputStream getLocalizedInputStream(InputStream in);
public OutputStream getLocalizedOutputStream(OutputStream out);
public static Runtime getRuntime();
public synchronized void load(String fileName);
public synchronized void loadLibrary(String libName);
public native void runFinalization();
public native long totalMemory();
public native void traceInstruction(boolean on);
public native void traceMethodCalls(boolean on);
public static void runFinalizersOnExit(boolean value);
}
 
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 29
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    138
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here