Name

Runtime

Synopsis

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

exit( ) causes the Java interpreter to exit and return a specified return code. This method is usually invoked through System.exit( ). In Java 1.3, addShutdownHook( ) registers an unstarted Thread object that is run when the virtual machine shuts down, either through a call to exit( ) or through a user interrupt (a CTRL-C, for example). The purpose of a shutdown hook is to perform necessary cleanup, such as shutting down network connections, deleting temporary files, and so on. Any number of hooks can be registered with addShutdownHook( ). Before the interpreter exits, it starts all registered shutdown-hook threads and lets them run concurrently. Any hooks you write should perform their cleanup operation and exit promptly so they do not delay the shutdown process. To remove a shutdown hook before it is run, call removeShutdownHook( ). To force an immediate exit that does not invoke the shutdown hooks, call halt( ).

exec( ) starts a new process running externally to the interpreter. Note that any processes run outside of Java may be system-dependent.

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

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.