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()???
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.
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
posted
0
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
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.