*
The moose likes Beginning Java and the fly likes What exactly System.out.println() is? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What exactly System.out.println() is?" Watch "What exactly System.out.println() is?" New topic
Author

What exactly System.out.println() is?

Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
Hi all genius,

I know the use of System.out.println() and also know that System is a class and println() is a static method of some class.
But what is out in System.out.println()???

Please explain
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

out is just a variable of type PrintStream, it's public, static and final.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Note that the docs for java.lang.System state specifically what it is, and it's almost always faster to look it up!
lil Yaure
Greenhorn

Joined: Feb 25, 2010
Posts: 23
all I care and know about it is that it will output words to the command prompt and is really useful for debugging
Vasiq Molvizadah
Ranch Hand

Joined: Dec 24, 2009
Posts: 66
Hardik Trivedi wrote:Hi all genius,

I know the use of System.out.println() and also know that System is a class and println() is a static method of some class.
But what is out in System.out.println()???

Please explain


The System class contains several useful class fields and methods. The example of fields would be "out" field which is an object of PrintStream class ...and with the help of this field "out" we can call the method "println()"...which is available in class PrintStream....
The reason why we have to write this whole line to write or print a line is :
1. System is a final class, so you cannot extend it and the constructor of System class is private...so it cannot be instantiated too...that's why we use classname to call the System class instead of using the object name.
2. In System class there's a field known as "out" which is an object of class PrintStream and the reason why we cannot create an object of PrintStream directly is because PrintStream has got a parameterized constructor...which we don't need here...
3. With the help of this "out" object we can call the println() method in PrintStream class..to write a line on the command prompt..

Hope, this is the answer to your question....


Human Knowledge Belongs to the World.
- Vasiq Mz
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What exactly System.out.println() is?
 
Similar Threads
Curious - are the primitives listed in the API?
createNewFile( )
static method in parent class
output of this program?
Overriding