• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how setIn() and setOut() works.

 
Sumant Mehta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic