• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

System.in,System.out,System.err

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very much confused about these three.
I read from some book these all are predefined object of subclass of InputStream.
And one more book i read java.lang.System is class
and these three are public variable of that class.
give me clear explanation.
Thanks in advance.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Best place to get help is the API documentation for the java.lang.System class.
Ajith
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Best thing to do when you are confused about these types of things is to go the API and look up the System class.
You can tell that they are static because you don't have to have an instance of a class to use them.
And you can tell that they are fields and not methods because you are not writing System.out().println() but you are writing System.out.println().
So then the question becomes what are the types of these fields. Well, out and err are PrintStreams, so you then have to go to the PrintStream class to look up println() and see what that method does. PrintStream is a subclass of FilterOutputStream which is a subclass of OutputStream. println() is a method of the class that can take any primitive or object or String as an argument, which means you can pass anything to println() and it will work.
System.in is a field of InputStream type. But InputStream is an abstract class, so then how can it be an instance of InputStream. Well that is when I open the source file System so I can see what is going on. System.in is initialized in the source file to a BufferedInputStream, a subclass of InputStream.
So the final answer:
System.out - static field of class System that is an instance of PrintStream.
System.in - static field of class System that is an instance of BufferedInputStream
System.err - static field of class System that is an instance of PrintStream.
Bill

[This message has been edited by bill bozeman (edited January 05, 2001).]
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic