The most intelligent Java IDE
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
Author

Why System.out

Anchit Jindal
Greenhorn

Joined: Feb 03, 2010
Messages: 4

'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
Bartender

Joined: Sep 28, 2004
Messages: 10022

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

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Anchit Jindal
Greenhorn

Joined: Feb 03, 2010
Messages: 4

@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
Bartender

Joined: Sep 28, 2004
Messages: 10022

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

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
David Newton
Author
Bartender

Joined: Sep 29, 2008
Messages: 6873

Same way we can use any class's variable if it's defined in such a way that gives us access.

Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
Greg Charles
Ranch Hand

Joined: Oct 01, 2001
Messages: 901

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.

This message was edited 1 time. Last update was at by Greg Charles

John de Michele
Ranch Hand

Joined: Mar 09, 2009
Messages: 510

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.
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
JProfiler
Get rid of your performance problems and memory leaks!