![]() |
VOOZH | about |
The System class is a final utility class available in the java.lang package. It provides access to standard input, output, and error streams, system properties, environment variables, memory management utilities, and various JVM-related operations. Since all its members are static, objects of the System class are not created.
| Field | Description |
|---|---|
| System.in | Standard input stream (keyboard input). |
| System.out | Standard output stream (console output). |
| System.err | Standard error stream for displaying errors. |
The methods of the System class can be grouped into different categories based on their functionality.
The arraycopy() method is used to copy elements from one array to another efficiently. It is faster than manually copying elements using loops.
Syntax:
System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length);
[10, 20, 1, 2, 50]
The currentTimeMillis() method returns the current time in milliseconds. It is commonly used for measuring execution time and timestamps.
Syntax
long time = System.currentTimeMillis();
1781169523689
The nanoTime() method returns the current value of the JVM's high-resolution timer in nanoseconds. It is useful for precise performance measurements.
Syntax:
long time = System.nanoTime();
Time Taken: 5940
The getProperty() method retrieves a system property using its key. It provides information about the operating system, Java version, user directory, and more.
Syntax:
String value = System.getProperty(String key);
26-ea
The setProperty() method sets or updates a system property. It returns the previous value associated with the specified key.
Syntax:
System.setProperty(String key, String value);
India
The clearProperty() method removes a system property identified by the given key. After removal, the property value becomes null.
Syntax:
System.clearProperty(String key);
null
The getenv() method returns environment variables of the operating system. It is commonly used to access PATH, JAVA_HOME, and other environment settings.
Syntax:
System.getenv();
/usr/java/openjdk-26/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
The gc() method requests the JVM to perform garbage collection. It helps reclaim memory occupied by unused objects.
Syntax:
System.gc();
Garbage Collection Requested
The exit() method terminates the currently running Java Virtual Machine (JVM). A status code of 0 indicates successful termination.
Syntax:
System.exit(int status);
Program Ends
The lineSeparator() method returns the platform-dependent line separator. It is useful when writing platform-independent applications.
Syntax:
String separator = System.lineSeparator();
Java Programming
The identityHashCode() method returns the default hash code of an object regardless of whether the class overrides hashCode().
Syntax:
System.identityHashCode(Object obj);
724542711
The console() method returns the system console associated with the JVM. It is mainly used for secure user input.
Syntax:
Console c = System.console();
No Console Available