S.o.p.

1 view
Skip to first unread message

manoj patel

unread,
Feb 17, 2010, 11:00:53 PM2/17/10
to javatec...@googlegroups.com
Hi

Can anyone explain me how the System.out.println() prints in the
console. How it process internally to print the string value in the
console.

Thanking you,
manoj

Rejin Chandran

unread,
Feb 18, 2010, 3:28:52 AM2/18/10
to javatec...@googlegroups.com
Java Console is a simple debugging mechanism that redirects any System.out and System.err to the console window. So this is manged by jvm only. System is a final class and out is a static PrintStream object of System class. The methods println() and print() are defined in PrintStream class. The method print takes object as the argument and println is overloaded to handle both primitives and objects. By using certain mechanisam you can forward the stdout to your own file.
 
Thanks and Regards
Rejin Chandran R

manoj patel

unread,
Feb 18, 2010, 7:10:24 AM2/18/10
to javatec...@googlegroups.com
hi Rejin

I did explained it as u've described but they asked me how
it internally does that, which i don't have any idea ab't that.

Regards,
manoj

Rejin Chandran

unread,
Feb 18, 2010, 7:23:53 AM2/18/10
to javatec...@googlegroups.com
What you explained to them ? tell me in your own words.

manoj patel

unread,
Feb 18, 2010, 8:34:19 AM2/18/10
to javatec...@googlegroups.com
Hi Rejin

I told them that System is a final class and out is an
object and println() is a method in PrintStream. But i don't know what
he wanted or may be the explanation like what u've already given.


Regards,
manoj

Rejin Chandran

unread,
Feb 18, 2010, 8:39:32 AM2/18/10
to javatec...@googlegroups.com
As per my knowledge standarout is done by JVM only and i don't know how it is handled in that
 ;-)

 

Effective Java

unread,
Feb 18, 2010, 11:01:29 PM2/18/10
to javatechnicals
I think rejin provided a answer for your question.
As a web application developer i hope that answer is good enough.
Who asked you this question?
is it for an enterprise application developer interview?
or a system level programmer interview?
anyway my best wishes patel.

Regards
Sreehari

On Feb 18, 6:39 pm, Rejin Chandran <reji...@gmail.com> wrote:
> As per my knowledge standarout is done by JVM only and i don't know how it
> is handled in that
>  ;-)
>

> On 2/18/10, manoj patel <manoja.pa...@gmail.com> wrote:
>
>
>
>
>
> > Hi Rejin
>
> >           I told them that System is a final class and out is an
> > object and println() is a method in PrintStream. But i don't know what
> > he wanted or may be the explanation like what u've already given.
>
> > Regards,
> > manoj
>

> > On Thu, Feb 18, 2010 at 5:53 PM, Rejin Chandran <reji...@gmail.com> wrote:
> > > What you explained to them ? tell me in your own words.
>

> > > On 2/18/10, manoj patel <manoja.pa...@gmail.com> wrote:
>
> > >> hi Rejin
>
> > >>           I did explained it as u've described but they asked me how
> > >> it internally does that, which i don't have any idea ab't that.
>
> > >> Regards,
> > >> manoj
>

> > >> On Thu, Feb 18, 2010 at 1:58 PM, Rejin Chandran <reji...@gmail.com>


> > wrote:
> > >> > Java Console is a simple debugging mechanism that redirects any
> > >> > System.out
> > >> > and System.err to the console window. So this is manged by jvm only.
> > >> > System
> > >> > is a final class and out is a static PrintStream object of System
> > class.
> > >> > The
> > >> > methods println() and print() are defined in PrintStream class. The
> > >> > method
> > >> > print takes object as the argument and println is overloaded to handle
> > >> > both
> > >> > primitives and objects. By using certain mechanisam you can forward
> > the
> > >> > stdout to your own file.
>
> > >> > Thanks and Regards
> > >> > Rejin Chandran R
>

> > >> > On 2/18/10, manoj patel <manoja.pa...@gmail.com> wrote:
>
> > >> >> Hi
>
> > >> >>     Can anyone explain me how the System.out.println() prints in the
> > >> >> console. How it process internally to print the string value in the
> > >> >> console.
>
> > >> >> Thanking you,

> > >> >> manoj- Hide quoted text -
>
> - Show quoted text -

AmmasHoneylal

unread,
Feb 19, 2010, 1:37:41 AM2/19/10
to javatec...@googlegroups.com, javatechnicals

 

Hi hari

 

I’m sharing some information about println.

 

 

In Java applications, a typical way to write a line of output data is:

 

     System.out.println(data)

 

While executing  System.out.println(data),

 

The data goes to 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.

 

If the output is set to console then the output stream is redirected to PrintStream.

 

 Inside the PrintStream class it has the implementation of these methods

 

              java.io.PrintStream println()

              java.io.PrintStream println(boolean)

              java.io.PrintStream println(char)

              java.io.PrintStream println(char[])

              java.io.PrintStream println(double)

              java.io.PrintStream println(float)

              java.io.PrintStream println(int)

              java.io.PrintStream println(long)

              java.io.PrintStream println(java.lang.Object)

              java.io.PrintStream println(java.lang.String)

             

             

Working of println inside PrintStream

-------------------------------------

 

   PrintStream has  the ability to print representations of various data values conveniently. PrintStream can be created so as to flush automatically.This means that the flush method is automatically invoked after a byte array is written, that is while a println method is invoked, or a newline character or byte'\n' is written.

        

   Unlike other output streams, PrintStream never throws an IOException (if any exception has occured then that can be tested via the checkError method)

 

  

  HOW data is written to console

  --------------------------------------

 

  First JVM converts  data into string. All characters in the string are  printed by a PrintStream and are converted into bytes using the platform's default character encoding.  

 

    (Just keep in mind that in console, all other data formats are converted to string and then printing it)

 

Regards,

Honeylal M

AmritaTechnologies

Rejin Chandran

unread,
Feb 19, 2010, 2:52:24 AM2/19/10
to javatec...@googlegroups.com
Hi Honeylal,
 
Well Managed explanation. Thanks
 
Guys read this and share the knowledge.
 
Reply all
Reply to author
Forward
0 new messages