Module java.base
Package java.lang

Class System

java.lang.Object
java.lang.System

public final class System extends Object
Class System provides a standard place for programs to find system related information. All System API is static.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Logger logs messages that will be routed to the underlying logging framework that LoggerFinder uses.
    static class 
    The LoggerFinder service creates, manages and configures loggers to the underlying framework it uses.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final PrintStream
    Default error output stream
    static final InputStream
    Default input stream
    static final PrintStream
    Default output stream
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    arraycopy(Object array1, int start1, Object array2, int start2, int length)
    Copies the contents of array1 starting at offset start1 into array2 starting at offset start2 for length elements.
    static String
    Removes the property.
    static Console
    Return the Console or null.
    static long
    Answers the current time expressed as milliseconds since the time 00:00:00 UTC on January 1, 1970.
    static void
    exit(int code)
    Causes the virtual machine to stop running, and the program to exit.
    static void
    gc()
    Indicate to the virtual machine that it would be a good time to collect available memory.
    static Map<String,String>
    Returns all of the system environment variables in an unmodifiable Map.
    static String
    Returns an environment variable.
    getLogger(String loggerName)
    Return an instance of Logger.
    getLogger(String loggerName, ResourceBundle bundle)
    Return an instance of Logger that is localized based on the ResourceBundle.
    static Properties
    Answers the system properties.
    static String
    Answers the value of a particular system property.
    static String
    getProperty(String prop, String defaultValue)
    Answers the value of a particular system property.
    Deprecated, for removal: This API element is subject to removal in a future version.
    static int
    Answers an integer hash code for the parameter.
    static Channel
    Return the channel inherited by the invocation of the running vm.
    static String
    Return platform specific line separator character(s).
    static void
    load(String pathName)
    Loads the specified file as a dynamic library.
    static void
    Loads and links the library specified by the argument.
    static String
    mapLibraryName(String userLibName)
    Answers the platform-specific filename for the shared library named by the argument.
    static long
    Returns the current tick count in nanoseconds.
    static void
    Provides a hint to the virtual machine that it would be useful to attempt to perform any outstanding object finalizations.
    static void
    Sets the value of the static slot "err" in the receiver to the passed in argument.
    static void
    Sets the value of the static slot "in" in the receiver to the passed in argument.
    static void
    Sets the value of the static slot "out" in the receiver to the passed in argument.
    static void
    Sets the system properties.
    static String
    setProperty(String prop, String value)
    Sets the value of a particular system property.
    static void
    Deprecated, for removal: This API element is subject to removal in a future version.

    Methods declared in class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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 Details

    • setIn

      public static void setIn(InputStream newIn)
      Sets the value of the static slot "in" in the receiver to the passed in argument.
      Parameters:
      newIn - the new value for in.
    • setOut

      public static void setOut(PrintStream newOut)
      Sets the value of the static slot "out" in the receiver to the passed in argument.
      Parameters:
      newOut - the new value for out.
    • setErr

      public static void setErr(PrintStream newErr)
      Sets the value of the static slot "err" in the receiver to the passed in argument.
      Parameters:
      newErr - the new value for err.
    • arraycopy

      public static void arraycopy(Object array1, int start1, Object array2, int start2, int length)
      Copies the contents of array1 starting at offset start1 into array2 starting at offset start2 for length elements.
      Parameters:
      array1 - the array to copy out of
      start1 - the starting index in array1
      array2 - the array to copy into
      start2 - the starting index in array2
      length - the number of elements in the array to copy
    • currentTimeMillis

      public static long currentTimeMillis()
      Answers the current time expressed as milliseconds since the time 00:00:00 UTC on January 1, 1970.
      Returns:
      the time in milliseconds.
    • exit

      public static void exit(int code)
      Causes the virtual machine to stop running, and the program to exit. If runFinalizersOnExit(true) has been invoked, then all finalizers will be run first.
      Parameters:
      code - the return code.
      Throws:
      SecurityException - if the running thread is not allowed to cause the vm to exit.
      See Also:
    • gc

      public static void gc()
      Indicate to the virtual machine that it would be a good time to collect available memory. Note that, this is a hint only.
    • getenv

      public static String getenv(String var)
      Returns an environment variable.
      Parameters:
      var - the name of the environment variable
      Returns:
      the value of the specified environment variable
    • getProperties

      public static Properties getProperties()
      Answers 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().

      Security managers should restrict access to this API if possible.

      Returns:
      the system properties
    • getProperty

      public static String getProperty(String prop)
      Answers the value of a particular system property. Answers null if no such property exists.

      The properties currently provided by the virtual machine are:

           file.separator
           java.class.path
           java.class.version
           java.home
           java.version
           line.separator
           os.arch
           os.name
           os.version
           path.separator
           user.dir
           user.home
           user.name
           user.timezone
       
      Parameters:
      prop - 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 prop, String defaultValue)
      Answers the value of a particular system property. If no such property is found, answers the defaultValue.
      Parameters:
      prop - the system property to look up
      defaultValue - return value if system property is not found
      Returns:
      the value of the specified system property, or defaultValue if the property doesn't exist
    • setProperty

      public static String setProperty(String prop, String value)
      Sets the value of a particular system property.
      Parameters:
      prop - the system property to change
      value - the value to associate with prop
      Returns:
      the old value of the property, or null
    • getSecurityManager

      @Deprecated(since="17", forRemoval=true) public static SecurityManager getSecurityManager()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Answers the active security manager.
      Returns:
      the system security manager object.
    • identityHashCode

      public static int identityHashCode(Object anObject)
      Answers an integer hash code for the parameter. The hash code returned is the same one that would be returned by 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
      Returns:
      the hash code for the object
      See Also:
    • load

      public static void load(String pathName)
      Loads the specified file as a dynamic library.
      Parameters:
      pathName - the path of the file to be loaded
    • loadLibrary

      public static void loadLibrary(String libName)
      Loads and links the library specified by the argument.
      Parameters:
      libName - the name of the library to load
      Throws:
      UnsatisfiedLinkError - if the library could not be loaded
      SecurityException - if the library was not allowed to be loaded
    • runFinalization

      public static void runFinalization()
      Provides a hint to the virtual machine that it would be useful to attempt to perform any outstanding object finalizations.
    • setProperties

      public static void setProperties(Properties p)
      Sets the system properties. Note that the object which is passed in is not copied, so that subsequent changes made to it will be reflected in calls to getProperty() and getProperties().

      Security managers should restrict access to this API if possible.

      Parameters:
      p - the properties to set
    • setSecurityManager

      @Deprecated(since="17", forRemoval=true) public static void setSecurityManager(SecurityManager s)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the active security manager. Note that once the security manager has been set, it can not be changed. Attempts to do so will cause a security exception.
      Parameters:
      s - the new security manager
      Throws:
      SecurityException - if the security manager has already been set and its checkPermission method doesn't allow it to be replaced.
      UnsupportedOperationException - if s is non-null and a special token "disallow" has been set for system property "java.security.manager" which indicates that a security manager is not allowed to be set dynamically.
    • mapLibraryName

      public static String mapLibraryName(String userLibName)
      Answers the platform-specific filename for the shared library named by the argument.
      Parameters:
      userLibName - the name of the library to look up.
      Returns:
      the platform-specific filename for the library
    • inheritedChannel

      public static Channel inheritedChannel() throws IOException
      Return the channel inherited by the invocation of the running vm. The channel is obtained by calling SelectorProvider.inheritedChannel().
      Returns:
      the inherited channel or null
      Throws:
      IOException - if an IO error occurs getting the inherited channel
    • nanoTime

      public static long nanoTime()
      Returns the current tick count in nanoseconds. The tick count only reflects elapsed time.
      Returns:
      the current nanosecond tick count, which may be negative
    • clearProperty

      public static String clearProperty(String prop)
      Removes the property.
      Parameters:
      prop - the name of the property to remove
      Returns:
      the value of the property removed
    • getenv

      public static Map<String,String> getenv()
      Returns all of the system environment variables in an unmodifiable Map.
      Returns:
      an unmodifiable Map containing all of the system environment variables.
    • console

      public static Console console()
      Return the Console or null.
      Returns:
      the Console or null
    • lineSeparator

      public static String lineSeparator()
      Return platform specific line separator character(s). Unix is \n while Windows is \r\n as per the prop set by the VM.
      Returns:
      platform specific line separator string
    • getLogger

      public static System.Logger getLogger(String loggerName)
      Return an instance of Logger.
      Parameters:
      loggerName - The name of the logger to return
      Returns:
      An instance of the logger.
      Throws:
      NullPointerException - if the loggerName is null
    • getLogger

      public static System.Logger getLogger(String loggerName, ResourceBundle bundle)
      Return an instance of Logger that is localized based on the ResourceBundle.
      Parameters:
      loggerName - The name of the logger to return
      bundle - The ResourceBundle to use for localization
      Returns:
      An instance of the logger localized to 'bundle'
      Throws:
      NullPointerException - if the loggerName or bundle is null