Package java.lang

Class System


  • public final class System
    extends Object
    Provides access to system-related information and resources including standard input and output. Enables clients to dynamically load native libraries. All methods of this class are accessed in a static way and the class itself can not be instantiated.
    See Also:
    Runtime
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void arraycopy​(boolean[] src, int srcPos, boolean[] dst, int dstPos, int length)
      The boolean[] specialized version of arraycopy().
      static void arraycopy​(byte[] src, int srcPos, byte[] dst, int dstPos, int length)
      The byte[] specialized version of arraycopy().
      static void arraycopy​(char[] src, int srcPos, char[] dst, int dstPos, int length)
      The char[] specialized version of arraycopy().
      static void arraycopy​(double[] src, int srcPos, double[] dst, int dstPos, int length)
      The double[] specialized version of arraycopy().
      static void arraycopy​(float[] src, int srcPos, float[] dst, int dstPos, int length)
      The float[] specialized version of arraycopy().
      static void arraycopy​(int[] src, int srcPos, int[] dst, int dstPos, int length)
      The int[] specialized version of arraycopy().
      static void arraycopy​(long[] src, int srcPos, long[] dst, int dstPos, int length)
      The long[] specialized version of arraycopy().
      static void arraycopy​(short[] src, int srcPos, short[] dst, int dstPos, int length)
      The short[] specialized version of arraycopy().
      static void arraycopy​(Object src, int srcPos, Object dst, int dstPos, int length)
      Copies length elements from the array src, starting at offset srcPos, into the array dst, starting at offset dstPos.
      static String clearProperty​(String name)
      Removes a specific system property.
      static Console console()
      Returns the Console associated with this VM, or null.
      static long currentTimeMillis()
      Returns the current time in milliseconds since January 1, 1970 00:00:00.0 UTC.
      static void exit​(int code)
      Causes the VM to stop running and the program to exit with the given exit status.
      static void gc()
      Indicates to the VM that it would be a good time to run the garbage collector.
      static Map<String,​String> getenv()
      Returns an unmodifiable map of all environment variables to their values.
      static String getenv​(String name)
      Returns the value of the environment variable with the given name, or null if no such variable exists.
      static Properties getProperties()
      Returns the system properties.
      static String getProperty​(String propertyName)
      Returns the value of a particular system property or null if no such property exists.
      static String getProperty​(String name, String defaultValue)
      Returns the value of a particular system property.
      static SecurityManager getSecurityManager()
      Returns null.
      static int identityHashCode​(Object anObject)
      Returns an integer hash code for the parameter.
      static Channel inheritedChannel()
      Returns the inherited channel from the creator of the current virtual machine.
      static String lineSeparator()
      Returns the system's line separator.
      static void load​(String pathName)
      static void loadLibrary​(String libName)
      static void logE​(String message)  
      static void logE​(String message, Throwable th)  
      static void logI​(String message)  
      static void logI​(String message, Throwable th)  
      static void logW​(String message)  
      static void logW​(String message, Throwable th)  
      static String mapLibraryName​(String nickname)
      Returns the platform specific file name format for the shared library named by the argument.
      static long nanoTime()
      Returns the current timestamp of the most precise timer available on the local system, in nanoseconds.
      static void runFinalization()
      Provides a hint to the VM that it would be useful to attempt to perform any outstanding object finalization.
      static void runFinalizersOnExit​(boolean flag)
      Deprecated.
      This method is unsafe.
      static void setErr​(PrintStream newErr)
      Sets the standard error output stream to the given user defined output stream.
      static void setIn​(InputStream newIn)
      Sets the standard input stream to the given user defined input stream.
      static void setOut​(PrintStream newOut)
      Sets the standard output stream to the given user defined output stream.
      static void setProperties​(Properties p)
      Attempts to set all system properties.
      static String setProperty​(String name, String value)
      Sets the value of a particular system property.
      static void setSecurityManager​(SecurityManager sm)
      Throws SecurityException.
      static void setUnchangeableSystemProperty​(String name, String value)
      Inits an unchangeable system property with the given value.
    • Field Detail

      • in

        public static final InputStream in
        Default input stream.
      • out

        public static final PrintStream out
        Default output stream.
      • err

        public static final PrintStream err
        Default error output stream.
    • Method Detail

      • setIn

        public static void setIn​(InputStream newIn)
        Sets the standard input stream to the given user defined input stream.
        Parameters:
        newIn - the user defined input stream to set as the standard input stream.
      • setOut

        public static void setOut​(PrintStream newOut)
        Sets the standard output stream to the given user defined output stream.
        Parameters:
        newOut - the user defined output stream to set as the standard output stream.
      • setErr

        public static void setErr​(PrintStream newErr)
        Sets the standard error output stream to the given user defined output stream.
        Parameters:
        newErr - the user defined output stream to set as the standard error output stream.
      • arraycopy

        public static void arraycopy​(Object src,
                                     int srcPos,
                                     Object dst,
                                     int dstPos,
                                     int length)
        Copies length elements from the array src, starting at offset srcPos, into the array dst, starting at offset dstPos.

        The source and destination arrays can be the same array, in which case copying is performed as if the source elements are first copied into a temporary array and then into the destination array.

        Parameters:
        src - the source array to copy the content.
        srcPos - the starting index of the content in src.
        dst - the destination array to copy the data into.
        dstPos - the starting index for the copied content in dst.
        length - the number of elements to be copied.
      • arraycopy

        public static void arraycopy​(char[] src,
                                     int srcPos,
                                     char[] dst,
                                     int dstPos,
                                     int length)
        The char[] specialized version of arraycopy().
      • arraycopy

        public static void arraycopy​(byte[] src,
                                     int srcPos,
                                     byte[] dst,
                                     int dstPos,
                                     int length)
        The byte[] specialized version of arraycopy().
      • arraycopy

        public static void arraycopy​(short[] src,
                                     int srcPos,
                                     short[] dst,
                                     int dstPos,
                                     int length)
        The short[] specialized version of arraycopy().
      • arraycopy

        public static void arraycopy​(int[] src,
                                     int srcPos,
                                     int[] dst,
                                     int dstPos,
                                     int length)
        The int[] specialized version of arraycopy().
      • arraycopy

        public static void arraycopy​(long[] src,
                                     int srcPos,
                                     long[] dst,
                                     int dstPos,
                                     int length)
        The long[] specialized version of arraycopy().
      • arraycopy

        public static void arraycopy​(float[] src,
                                     int srcPos,
                                     float[] dst,
                                     int dstPos,
                                     int length)
        The float[] specialized version of arraycopy().
      • arraycopy

        public static void arraycopy​(double[] src,
                                     int srcPos,
                                     double[] dst,
                                     int dstPos,
                                     int length)
        The double[] specialized version of arraycopy().
      • arraycopy

        public static void arraycopy​(boolean[] src,
                                     int srcPos,
                                     boolean[] dst,
                                     int dstPos,
                                     int length)
        The boolean[] specialized version of arraycopy().
      • currentTimeMillis

        public static long currentTimeMillis()
        Returns the current time in milliseconds since January 1, 1970 00:00:00.0 UTC.

        This method always returns UTC times, regardless of the system's time zone. This is often called "Unix time" or "epoch time". Use a DateFormat instance to format this time for display to a human.

        This method shouldn't be used for measuring timeouts or other elapsed time measurements, as changing the system time can affect the results. Use nanoTime() for that.

      • nanoTime

        public static long nanoTime()
        Returns the current timestamp of the most precise timer available on the local system, in nanoseconds. Equivalent to Linux's CLOCK_MONOTONIC.

        This timestamp should only be used to measure a duration by comparing it against another timestamp on the same device. Values returned by this method do not have a defined correspondence to wall clock times; the zero value is typically whenever the device last booted. Use currentTimeMillis() if you want to know what time it is.

      • exit

        public static void exit​(int code)
        Causes the VM to stop running and the program to exit with the given exit status. If runFinalizersOnExit(boolean) has been previously invoked with a true argument, then all objects will be properly garbage-collected and finalized first.
      • gc

        public static void gc()
        Indicates to the VM that it would be a good time to run the garbage collector. Note that this is a hint only. There is no guarantee that the garbage collector will actually be run.
      • getenv

        public static String getenv​(String name)
        Returns the value of the environment variable with the given name, or null if no such variable exists.
      • getenv

        public static Map<String,​String> getenv()
        Returns an unmodifiable map of all environment variables to their values.
      • getProperties

        public static Properties getProperties()
        Returns the system properties. Note that this is not a copy, so that changes made to the returned Properties object will be reflected in subsequent calls to getProperty and getProperties.
        Returns:
        the system properties.
      • setUnchangeableSystemProperty

        public static void setUnchangeableSystemProperty​(String name,
                                                         String value)
        Inits an unchangeable system property with the given value. This is called from native code when the environment needs to change under native bridge emulation.
      • getProperty

        public static String getProperty​(String propertyName)
        Returns the value of a particular system property or null if no such property exists.

        The following properties are always provided by the Dalvik VM:

        Name Meaning Example
        file.separator File.separator /
        java.class.path System class path .
        java.class.version (Not useful on Android) 50.0
        java.compiler (Not useful on Android) Empty
        java.ext.dirs (Not useful on Android) Empty
        java.home Location of the VM on the file system /system
        java.io.tmpdir See File.createTempFile(java.lang.String, java.lang.String) /sdcard
        java.library.path Search path for JNI libraries /vendor/lib:/system/lib
        java.vendor Human-readable VM vendor The Android Project
        java.vendor.url URL for VM vendor's web site http://www.android.com/
        java.version (Not useful on Android) 0
        java.specification.version VM libraries version 0.9
        java.specification.vendor VM libraries vendor The Android Project
        java.specification.name VM libraries name Dalvik Core Library
        java.vm.version VM implementation version 1.2.0
        java.vm.vendor VM implementation vendor The Android Project
        java.vm.name VM implementation name Dalvik
        java.vm.specification.version VM specification version 0.9
        java.vm.specification.vendor VM specification vendor The Android Project
        java.vm.specification.name VM specification name Dalvik Virtual Machine Specification
        line.separator The system line separator \n
        os.arch OS architecture armv7l
        os.name OS (kernel) name Linux
        os.version OS (kernel) version 2.6.32.9-g103d848
        path.separator See File.pathSeparator :
        user.dir Base of non-absolute paths /
        user.home (Not useful on Android) Empty
        user.name (Not useful on Android) Empty

        All of the above properties except for user.home and java.io.tmpdir cannot be modified. Any attempt to change them will be a no-op.

        Parameters:
        propertyName - the name of the system property to look up.
        Returns:
        the value of the specified system property or null if the property doesn't exist.
      • getProperty

        public static String getProperty​(String name,
                                         String defaultValue)
        Returns the value of a particular system property. The defaultValue will be returned if no such property has been found.
      • setProperty

        public static String setProperty​(String name,
                                         String value)
        Sets the value of a particular system property. Most system properties are read only and cannot be cleared or modified. See getProperty(java.lang.String) for a list of such properties.
        Returns:
        the old value of the property or null if the property didn't exist.
      • console

        public static Console console()
        Returns the Console associated with this VM, or null. Not all VMs will have an associated console. A console is typically only available for programs run from the command line.
        Since:
        1.6
      • getSecurityManager

        public static SecurityManager getSecurityManager()
        Returns null. Android does not use SecurityManager. This method is only provided for source compatibility.
        Returns:
        null
      • identityHashCode

        public static int identityHashCode​(Object anObject)
        Returns an integer hash code for the parameter. The hash code returned is the same one that would be returned by the method java.lang.Object.hashCode(), whether or not the object's class has overridden hashCode(). The hash code for null is 0.
        Parameters:
        anObject - the object to calculate the hash code.
        Returns:
        the hash code for the given object.
        See Also:
        Object.hashCode()
      • lineSeparator

        public static String lineSeparator()
        Returns the system's line separator. On Android, this is "\n". The value comes from the value of the line.separator system property.

        On Android versions before Lollipop the line.separator system property can be modified but this method continues to return the original value. The system property cannot be modified on later versions of Android.

        Since:
        1.7
      • logE

        public static void logE​(String message)
      • logI

        public static void logI​(String message)
      • logW

        public static void logW​(String message)
      • runFinalization

        public static void runFinalization()
        Provides a hint to the VM that it would be useful to attempt to perform any outstanding object finalization.
      • runFinalizersOnExit

        @Deprecated
        public static void runFinalizersOnExit​(boolean flag)
        Deprecated.
        This method is unsafe.
        Ensures that, when the VM is about to exit, all objects are finalized. Note that all finalization which occurs when the system is exiting is performed after all running threads have been terminated.
        Parameters:
        flag - the flag determines if finalization on exit is enabled.
      • setProperties

        public static void setProperties​(Properties p)
        Attempts to set all system properties. Copies all properties from p and discards system properties that are read only and cannot be modified. See getProperty(java.lang.String) for a list of such properties.
      • setSecurityManager

        public static void setSecurityManager​(SecurityManager sm)
        Throws SecurityException.

        Security managers do not provide a secure environment for executing untrusted code and are unsupported on Android. Untrusted code cannot be safely isolated within a single VM on Android, so this method always throws a SecurityException.

        Parameters:
        sm - a security manager
        Throws:
        SecurityException - always
      • mapLibraryName

        public static String mapLibraryName​(String nickname)
        Returns the platform specific file name format for the shared library named by the argument. On Android, this would turn "MyLibrary" into "libMyLibrary.so".