JVM Tutorials - Herong's Tutorial Examples
∟java.lang.System Class - The Operating System
∟What Is java.lang.System
This section describes what is java.lang.System - A Java built-in class that presents the operating system where the Java Virtual Machine (JVM) is running.
What Is java.lang.System?
java.lang.System is a built-in class that presents the operating system
where the Java Virtual Machine (JVM) is running.
java.lang.System class allows the application to interface with the operating system
in which the JVM is running through these static properties and static methods:
- static PrintStream err - Represents the "standard" error output stream.
- static InputStream in - Represents the "standard" input stream.
- static PrintStream out - Represents the "standard" output stream.
- static long currentTimeMillis() - Returns the current time in milliseconds.
- static long nanoTime() - Returns the current value of the most precise available system timer, in nanoseconds.
- static Map<String,String> getenv() - Returns an unmodifiable string map view of the current system environment.
- static String getenv(String name) - Gets the value of the specified environment variable.
- static Properties getProperties() - Determines the current system properties.
- static String getProperty(String key) - Gets the system property indicated by the specified key.
- static String clearProperty(String key) - Removes the system property indicated by the specified key.
- static void setProperties(Properties props) - Sets the system properties to the Properties argument.
- static String setProperty(String key, String value) - Sets the system property indicated by the specified key.
- static SecurityManager getSecurityManager() - Gets the system security interface.
- static void setSecurityManager(SecurityManager s) - Sets the System security.
- static int identityHashCode(Object x) - Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode().
- static void setErr(PrintStream err) - Reassigns the "standard" error output stream.
- static void setIn(InputStream in) - Reassigns the "standard" input stream.
- static void setOut(PrintStream out) - Reassigns the "standard" output stream.
- static Console console() - Returns the unique Console object associated with the current Java virtual machine, if any.
- static Channel inheritedChannel() - Returns the channel inherited from the entity that created this Java virtual machine.
- static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) - Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.
java.lang.System class also provides some methods that are equivalent to those on the JVM Runtime instance for
quick access:
- static void exit(int status) - Terminates the currently running Java Virtual Machine.
The call System.exit(n) is effectively equivalent to the call: Runtime.getRuntime().exit(n).
- static void gc() - Runs the garbage collector.
The call System.gc() is effectively equivalent to the call: Runtime.getRuntime().gc().
- static void load(String filename) - Loads a code file with the specified filename from the local file system as a dynamic library.
The call System.load(name) is effectively equivalent to the call: Runtime.getRuntime().load(name).
- static void loadLibrary(String libname) - Loads the system library specified by the libname argument.
The call System.loadLibrary(name) is effectively equivalent to the call: Runtime.getRuntime().loadLibrary(name).
- static String mapLibraryName(String libname) - Maps a library name into a platform-specific string representing a native library.
- static void runFinalization() - Runs the finalization methods of any objects pending finalization.
The call System.runFinalization() is effectively equivalent to the call: Runtime.getRuntime().runFinalization().
Tutorial example programs are provided in next sections to test those properties and methods.
Table of Contents
About This Book
JVM (Java Virtual Machine) Specification
Java HotSpot VM - JVM by Oracle/Sun
java.lang.Runtime Class - The JVM Instance
►java.lang.System Class - The Operating System
►What Is java.lang.System
Standard Input, Output, and Error Streams
Current Time in Milliseconds and Nanoseconds
Accessing System Environment Variables
Getting and Adding System Properties
ClassLoader Class - Class Loaders
Class Class - Class Reflections
JVM Runtime Data Areas
JVM Stack, Frame and Stack Overflow
Thread Testing Program and Result
CPU Impact of Multi-Thread Applications
I/O Impact of Multi-Thread Applications
CDS (Class Data Sharing)
Micro Benchmark Runner and JVM Options
Micro Benchmark Tests on "int" Operations
Micro Benchmark Tests on "long" Operations
Micro Benchmark Tests in JIT Compilation Mode
Micro Benchmark Tests on "float" and "double" Operations
OpenJ9 by Eclipse Foundation
JRockit JVM 28.2.7 by Oracle Corporation
Archived Tutorials
References
Full Version in PDF/EPUB