This class defines a platform-independent interface to system facilities, including system properties and system input and output streams. All methods and variables of this class are static, and the class cannot be instantiated . Because the methods defined by this class are low-level system methods, most require special permissions and cannot be executed by untrusted code. getProperty( ) looks up a named property on the system properties list, returning the optionally specified default value if no property definition is found. getProperties( ) returns the entire properties list. setProperties( ) sets a Properties object on the properties list. In Java 1.2 and later, setProperty( ) sets the value of a system property. In Java 5.0, you can clear a property setting with clearProperty( ) . The following table lists system properties that are always defined. Untrusted code may be unable to read some or all of these properties. Additional properties can be defined using the -D option when invoking the Java interpreter.
The in , out , and err fields hold the standard input, output, and error streams for the system. These fields are frequently used in calls such as System.out.println( ) . In Java 1.1, setIn( ) , setOut( ) , and setErr( ) allow these streams to be redirected. System also defines various other useful static methods. exit( ) causes the Java VM to exit. arraycopy( ) efficiently copies an array or a portion of an array into a destination array. currentTimeMillis( ) returns the current time in milliseconds since midnight GMT, January 1, 1970 GMT. In Java 5.0, nanoTime( ) returns a time in nanoseconds. Unlike currentTimeMillis( ) this time is not relative to any fixed point and so is useful only for elapsed time computations . getenv( ) returns the value of a platform-dependent environment variable, or (in Java 5.0) returns a Map of all environment variables. The one-argument version of getenv( ) was previously deprecated but has been restored in Java 5.0. identityHashCode( ) computes the hashcode for an object in the same way that the default Object.hashCode( ) method does. It does this regardless of whether or how the hashCode( ) method has been overridden. In Java 5.0, inheritedChannel( ) returns a java.nio.channels.Channel object that represents a network connection passed to the Java process by the invoking process. This allows Java programs to be used with the Unix inetd daemon, for example. load( ) and loadLibrary( ) can read libraries of native code into the system. mapLibraryName( ) converts a system-independent library name into a system-dependent library filename. Finally, getSecurityManager( ) and setSecurityManager( ) get and set the system SecurityManager object responsible for the system security policy. See also Runtime , which defines several other methods that provide low-level access to system facilities. public final class System { // No Constructor // Public Constants public static final java.io.PrintStream err ; public static final java.io.InputStream in ; public static final java.io.PrintStream out ; // Public Class Methods public static void arraycopy (Object src , int srcPos , Object dest , int destPos , int length ); native 5.0 public static String clearProperty (String key ); public static long currentTimeMillis ( ); native public static void exit (int status ); public static void gc ( ); 5.0 public static java.util.Map<String,String> getenv ( ); public static String getenv (String name ); public static java.util.Properties getProperties ( ); public static String getProperty (String key ); public static String getProperty (String key , String def ); public static SecurityManager getSecurityManager ( ); 1.1 public static int identityHashCode (Object x ); native 5.0 public static java.nio.channels.Channel inheritedChannel ( ) throws java.io.IOException; public static void load (String filename ); public static void loadLibrary (String libname ); 1.2 public static String mapLibraryName (String libname ); native 5.0 public static long nanoTime ( ); native public static void runFinalization ( ); 1.1 public static void setErr (java.io.PrintStream err ); 1.1 public static void setIn (java.io.InputStream in ); 1.1 public static void setOut (java.io.PrintStream out ); public static void setProperties (java.util.Properties props ); 1.2 public static String setProperty (String key , String value ); public static void setSecurityManager (SecurityManager s ); // Deprecated Public Methods 1.1# public static void runFinalizersOnExit (boolean value ); } |