Java System Class

The System class of java contains several useful class fields and methods. It also provides facilities like standard input, standard output, and error output Streams. It can't be instantiated.

The Java System class comes in the module of "java.base" & in the package of "java.lang".

In Java System Class, we have 3 different types of field and 28 different types of method.

Java System Class consists of following fields:-

SNModifier and TypeFieldDescription
1static PrintStreanerrThe "standard" error output stream.
2static InputStreaminThe "standard" input stream.
3static PrintStreamoutThe "standard" output stream.

Java System class Methods:

Java System Class consists of following methods:-

SNMethodDescription
1arraycopy(object src, int srcPos, object dest, int destPos, int length)This method copies subsequence components of a specified source array to the specified destination array.
2clearProperty(String key)This method removes the system property indicated by the specified key.
3console()This method returns the Console object only if any Console object is associated with the java virtual machine.
4currentTimeMillis()This method returns the current time in the format of a millisecond. Millisecond will be returned as a unit of time.
5exit(int status)This method terminates the current Java virtual machine running on the system. This method takes the status code as an argument.
6gc()This method runs the garbage collector
7getenv()This method returns a string map view of the current system environment. Here string map is unmodifiable, and the environment is system dependent.
8getLogger(String name, RecourseBundle bundleThis method returns the localizable instance of a logger. Further, this instance can be used for caller's use.
9getLogger(String name)This method returns an instance of a logger. Further, this instance can be used for caller's use.
10getenv(String name)This method returns the value of environment variable which is specified and system dependent external named value.
11getProperties()This method returns the properties of the current system. Here properties are the properties that our JVM gets from our operating system
12getProperty(String key)This method returns the property of a system which is indicated by a specified key.
13getProperty(String key,String def)This method returns the property of a system which is indicated by a specified key.
14getSecurityManager()This method returns an interface of System Security.
15identityHashCode(Object x)This method returns hash code for the specified object. It is returned by the default method hashCode().
16inheritedChannel() throws IOExceptionThis method returns channel inherited from an entity that created this Java virtual machine.
17lineSeparator()This method returns line separator string which is system dependent. It returns the same value every time.
18load(String filename)This method loads file specified by the filename argument. Here argument must be an absolute path name.
19mapLibraryName(String libname)This method maps a library name into the platform-specific string which represents a native library.
20nanoTime()This method returns high-resolution time source in nanoseconds of running Java virtual machine. It returns the current value of JVM.
21runFinalizersOnExit(boolean value)This method runs finalization methods which can be of any objects pending finalization.
22runFinalization()This method runs finalization methods which can be of any objects pending finalization.
23setErr(PrintStream err)This method reassigns the "standard" error output stream.
24setIn(PrintStream in)This method reassigns the "standard" input stream.
25setOut(PrintStream out)This method reassigns the standard output stream.
26setSecurityManager(SecurityManager s)This method sets the system security.
27setProperties(Properties props)This method sets the properties of the system to the argument of properties.
28setProperty(String key, String value )This method sets the property of a system which is indicated by a key.

Example 1

Output:

Source array:ABBHAM
Destination array:SHUNUL
Source Position:2
Destination Position:3
Length:4
Destination array after use of arraycopy()
SHUBHAMJADON

Example 2

Output:

Current time in millisecond
1532262046724

Example 3

Output:

Shubham
Jadon

Example 4

Output:

Current time in nanoseconds = 1316893720017448

Example 5

Output:

identity hash code of object a = 843730481
identity hash code of object b = 743673026

Example 6

Output:

Your System property for user
shubham
C:\Users\Shubham Jadon
C:\Users\Shubham Jadon\eclipse-workspace\tpoint

Example 7

Output:

my name : Shubham Jadon

Example 8

Output:

map library for OS's name = os.name.dll
map library for OS's architecture = os.arch.dll
map library for OS's version = os.version.dll