Java System Methods
System Methods
The System
class contains several useful static methods for input, output, properties, time, and memory management.
Method | Description | Return Type |
---|---|---|
currentTimeMillis() | Returns the current time in milliseconds since January 1, 1970 (Unix epoch) | long |
nanoTime() | Returns the current value of the most precise available system timer, in nanoseconds | long |
exit(int status) | Terminates the running Java program. A nonzero status indicates abnormal termination | void |
gc() | Suggests that the Java Virtual Machine run the garbage collector | void |
getProperty(String key) | Gets the system property indicated by the key (e.g., "user.dir" ) |
String |
getProperty(String key, String defaultValue) | Gets the system property indicated by the key, or returns the default value if not found | String |
getProperties() | Returns all system properties as a Properties object |
Properties |
setProperty(String key, String value) | Sets the system property indicated by the key | String |
clearProperty(String key) | Removes the system property indicated by the key | String |
arraycopy(Object src, int srcPos, Object dest, int destPos, int length) | Copies elements from the source array into the destination array | void |
identityHashCode(Object x) | Returns the default hash code of the given object (even if hashCode() is overridden) |
int |
lineSeparator() | Returns the system-dependent line separator string (e.g., "\n" on Linux, "\r\n" on Windows) |
String |
getenv() | Returns an unmodifiable map of the system environment variables | Map<String,String> |
getenv(String name) | Returns the value of the specified environment variable, or null if it does not exist |
String |
in | Standard input stream (usually the keyboard) | InputStream |
out | Standard output stream (usually the console). Often used with println() |
PrintStream |
err | Standard error output stream (usually the console) | PrintStream |