Java System Methods

About This Index
This page is the Java System Methods index: every static method of the java.lang.System class, each with a full guide covering syntax, all overloads, parameters, return value, exceptions, three runnable examples, and FAQs. The examples only print values that are the same on every computer (true/false checks, lengths, and text the program creates itself), so the output shown is the output you get.
Learn what the System class is on the System hub. Use this page when you need a specific method such as arraycopy(), getProperty(), or nanoTime(). Examples compile on Java 8 and later, except where a page says it needs a newer version (for example getLogger(), which needs Java 9).
Many results depend on the computer: the clock, the operating system, environment variables, or how the program was started. Each guide explains which part is fixed and which part can differ.
How to Call a System Method
Every method here is static and java.lang needs no import: write the class name, a dot, and the method:
long start = System.nanoTime(); // timer start
String home = System.getProperty("user.home"); // a system property
String path = System.getenv("PATH"); // an environment variable
System.arraycopy(src, 0, dest, 0, src.length); // copy an array
System.exit(0); // end the program Java System Methods Table
All method guides in this Java tutorial series (25 tutorials), grouped by purpose.
Copy, time, and memory
6 methodsCopy parts of arrays quickly, read the clock, measure how long code takes, and work with object identity and garbage collection.
| Method | Description | Tutorial |
|---|---|---|
arraycopy() | Copy a range of elements from one array into another, or shift elements inside the same array. | Try it |
currentTimeMillis() | The current wall-clock time in milliseconds since January 1, 1970 UTC. | Try it |
nanoTime() | A high-resolution timer value in nanoseconds for measuring elapsed time. | Try it |
identityHashCode() | The default, identity-based hash code of an object, even if hashCode() is overridden. | Try it |
gc() | Suggest that the JVM runs the garbage collector now. Only a hint. | Try it |
runFinalization() | Ask the JVM to run finalize() methods of discarded objects. Deprecated for removal since Java 18. | Try it |
Program end and text
2 methodsEnd a program with an exit status code, and write line breaks that match the operating system.
| Method | Description | Tutorial |
|---|---|---|
exit() | Stop the JVM with an exit status code: 0 for success, nonzero for an error. | Try it |
lineSeparator() | The line break of the current platform: "\n" on Linux and macOS, "\r\n" on Windows. | Try it |
System properties and environment
6 methodsRead and change Java system properties (key and value settings inside the JVM) and read environment variables from the operating system.
| Method | Description | Tutorial |
|---|---|---|
getProperty() | Read one system property, optionally with a default value. | Try it |
setProperty() | Set a system property and get back its previous value. | Try it |
clearProperty() | Remove a system property and get back the value it had. | Try it |
getProperties() | Get all system properties as one live Properties object. | Try it |
setProperties() | Replace the whole set of system properties, or reset it with null. | Try it |
getenv() | Read one environment variable, or all of them as a read-only Map. | Try it |
Streams and console
5 methodsSwap the standard input, output, and error streams, get the interactive console, and pick up an inherited network channel.
| Method | Description | Tutorial |
|---|---|---|
setIn() | Replace the standard input stream System.in, for example with prepared test input. | Try it |
setOut() | Redirect standard output System.out, for example to capture printed text. | Try it |
setErr() | Redirect the standard error stream System.err to another PrintStream. | Try it |
console() | Get the Console of the interactive terminal, or null when there is none. | Try it |
inheritedChannel() | The network channel inherited from the process that started the JVM, usually null. | Try it |
Native libraries, logging, and security
6 methodsLoad native (C or C++) libraries, get a platform logger, and deal with the deprecated Security Manager.
| Method | Description | Tutorial |
|---|---|---|
load() | Load a native library from an absolute file path. | Try it |
loadLibrary() | Load a native library by its short name, searched in java.library.path. | Try it |
mapLibraryName() | Turn a short library name into the platform file name, such as libhello.so or hello.dll. | Try it |
getLogger() | Get a System.Logger for platform logging with levels such as INFO and DEBUG (Java 9+). | Try it |
getSecurityManager() | Get the installed SecurityManager, which is null on modern Java (deprecated). | Try it |
setSecurityManager() | Install a SecurityManager. Throws UnsupportedOperationException on Java 18+ by default. | Try it |
Frequently Asked Questions
Start with arraycopy()
Copy part of an array into another array, or shift elements inside the same array.
12 people found this page helpful
