GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes how setIn() and setOut() works. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "how setIn() and setOut() works." Watch "how setIn() and setOut() works." New topic
Author

how setIn() and setOut() works.

Sumant Mehta
Greenhorn

Joined: Jan 09, 2014
Posts: 10
in system class in & out methods are static final data member which means there value can not be change after intialization, if its true then how setIn() and setOut() works.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Sumant Mehta wrote:how setIn() and setOut() works.

If you look at the source code for the System class (there's a src.zip in your JDK installation), you will see that those methods actually call native code, so how it works is operating system dependent.
Luan Cestari
Ranch Hand

Joined: Feb 07, 2010
Posts: 163

A good question. I remeber that I had that question long ago. I found the answer looking the source code like the following:

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/System.java#60
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/System.java#System.registerNatives%28%29
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/System.java#System.setIn%28java.io.InputStream%29
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/System.java#System.setIn0%28java.io.InputStream%29

As you can see, the class statically call the registerNatives which is native and also have some other internal native methods to make the things works (even that not follow the Java language rules (due it is native))

Regards


Please, visit me for some cool tech post at www.ourdailycodes.com
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39079
    
  23
Welcome to the Ranch
 
GeeCON Prague 2014
 
subject: how setIn() and setOut() works.