142014Sep

What is System Class in java

System Class In Java:-

  • is a core class.
  • provides number of method and class fields.
  • is available in java.lang package.
  • provides facility like Standard input,Standard output,error stream output, loading files and libraries, access to externally defined properties and environment variables and a utility method for quickly copying a portion of an array.

Unique Features in System Class:-

System is only class in java which can directly interact with device, it has all library regarding to input and output Stream. It means we have to lookup for the os library in order to perform read and write operation .This class dynamically takes input and out specific buffer from os.

How System class internally takes the input and output specific buffer from operating system:-

System class have refference of input and out stream this refference is static whenever system class is loaded into memory it have static automtically interact to operating system and takes all the necesary input and output specific library from os .

System class internal structure (few method and variables):-

public final class System extends Object
{

	public static void void registerNative();
	static
	{
		registerNative();
	} 

	public final static InputpuStream in=null;
	public final static PrintStream out=null;
	public final static PrintStream err = null;

	public static void setOut(PrintStream out){}
	public static void setErr(PrintStream err){}
	public static void setIn(InputStream in){}

	public static Console console() {}
	public static native long nanoTime();
}

System is final class so we can’t override its behaviour through inheritance.All methods and variables available in System class is static so we cannot be instantiated or subclassed.Constructor avaliable in system class is private so we can’t instantiated System class.

What is  JNI(java Native Interface):-It allow cross-platform capability.JNI offers number of Standards Interface methods. Using these interface functions, you can call JNI functions from your native method code  and JNI directly interact to another plateform using its library ,gives new objects or call method,corresponding value etc.

How System class work :

At the time of class loading firstly System class load its static block and call registerNatives() method which call to JNI(java Native Interaction) .Now JNI inbuilt code interact to os and load all required library specified by JVM.Now JVM aim to get all static refference variable like public final static PrintStream out=null;JVM read corresponding code and instruct to JNI to get Output Buffer from os,JNI run its method and give OutputStream Buffer,Similar way for remaining static variables System class get corresponding Buffer Stream from os.