IntelliJ Java IDE
The moose likes Beginning Java and the fly likes Why System.out Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Why System.out" Watch "Why System.out" New topic
Author

Why System.out

Anchit Jindal
Greenhorn

Joined: Feb 03, 2010
Posts: 21
'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

Joined: Sep 28, 2004
Posts: 14606

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
Posts: 21
@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

Joined: Sep 28, 2004
Posts: 14606

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

Joined: Sep 29, 2008
Posts: 12612
Same way we can use any class's variable if it's defined in such a way that gives us access.
Greg Charles
Bartender

Joined: Oct 01, 2001
Posts: 1855

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

Joined: Mar 09, 2009
Posts: 600
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.
 
 
subject: Why System.out
 
Threads others viewed
why can't we instantiate abstract class
protected class ???
class loaders
abstract
Question on protected access modifier
IntelliJ Java IDE