Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What exactly System.out.println() is?

 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
out is just a variable of type PrintStream, it's public, static and final.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic