File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Doubt in System.out.print(). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt in System.out.print()." Watch "Doubt in System.out.print()." New topic
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: 10535
    
    9

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.


[How to ask questions] [Donate a pint, save a life!] [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: 10535
    
    9

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: 10535
    
    9

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: 40052
    
  28
Also a good idea to locate the Java™ Tutorials.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in System.out.print().