| Author |
Doubt in System.out.print().
|
lokesh pattajoshi
Ranch Hand
Joined: Jul 29, 2009
Posts: 130
|
|
hi,
Every body i have some doubt in java's SOP statement.
Actually in System class we are creating static out object of PrintStream class and in our program we are calling as System.out.print().
my doubt is that without doing these thing directly we can call PrintStream.print() method what is the need of doing these things in System class.
Thanks in advance
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8441
|
|
Even if you invoke PrintStream#print, you will still need to define where the output should go wont you? System.out does it for you.
From the API docs (emphasis added)
The "standard" output stream. This stream is already open and ready to accept output data. Typically this stream corresponds to display output or another output destination specified by the host environment or user.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
lokesh pattajoshi
Ranch Hand
Joined: Jul 29, 2009
Posts: 130
|
|
HI Maneesh,
Thank you very much for your replay actually i am beginner of java so can you please tell me exactly what is happening when we are calling System.out.print.
Regards,
Lokesh
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8441
|
|
Consider the statement System.out.print("Lokesh");
Here, "out" refers to a static variable which is pre-initialized to typically point to the console.
Thus, the data "Lokesh" is pumped via the output stream to the console.
|
 |
lokesh pattajoshi
Ranch Hand
Joined: Jul 29, 2009
Posts: 130
|
|
|
Thank you very much Maneesh now i got it......
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8441
|
|
You are welcome
PS. The Java API is well documented and quite descriptive. Also, in case you did not know, when you install the JDK, you also get the source code. Look for a file called src.zip under your JAVA_HOME (java installation directory). You can actually peek and the source code and see what is happening under the hood.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
Also a good idea to locate the Java™ Tutorials.
|
 |
 |
|
|
subject: Doubt in System.out.print().
|
|
|