• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why System.out  RSS feed

 
Anchit Jindal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'out' is an object of InputStream class .Then why we use it with system class as we write System.out.print() to print some message
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, System.out is an OutputStream -- not an InputStream.

But to answer your question... standard out has to be provided somehow. What do you propose to use instead?

Henry
 
Anchit Jindal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Henry

I am not proposing aything..I just want to know how we are able to use object of one class with some other class
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anchit Jindal wrote:
I am not proposing aything..I just want to know how we are able to use object of one class with some other class


It is perfectly valid for any class to have a final static variable that refers to an instance of another class.

Henry
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same way we can use any class's variable if it's defined in such a way that gives us access.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did that answer your question Anchit? I think your initial question reads like a challenge to Java, when really you meant it sincerely. The System class in Java contains a number of fields (like "in" and "out"), and methods (like currentTimeMillis()), which are useful to basic programming. However, looked at another way the whole System class is a sacrifice of elegance for convenience. We Java guys can be sensitive about that.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should also be remembered that System is a very old (1.0) class, and the way things were done at the beginning of Java were not necessarily the best way to do things. It's easy to have 20/20 hindsight, but public APIs are hard to change once they're released into the wild.

John.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!