System Class in Java

The System class contains several useful class fields and methods. It cannot be instantiated.

Among the facilities provided by the System class are

  • standard input(in), standard output(out), and standard error output(err) streams;
  • access to externally defined properties and environment variables;
  • a means of loading files and libraries;
  • a utility method for quickly copying a portion of an array.

Utility Methods

System Class in JavaScreen Shot 2020-04-16 at 7.51.53 PM

package com.java.core;

import java.io.IOException;

public class SystemExample {

    public static void main(String[] args) throws IOException {
        System.out.println("currentTimeMillis:" + System.currentTimeMillis());
        System.out.println("nanoTime:" + System.nanoTime());
        System.out.println("Env Map:" + System.getenv());
        System.out.println("Properties:" + System.getProperties());
        System.err.println("Error Message");
        System.gc();
        System.exit(0);
    }

}
currentTimeMillis:1587094201157 
nanoTime:640933913473059 
Env Map:{....JAVA_MAIN_CLASS_24013=com.java.core.SystemExample...} 
Properties:{...java.specification.version=1.8,...}
Error Message

Leave a Reply

Your email address will not be published. Required fields are marked *