• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

diff between System.out and System.err

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the actual difference bwtween system.out.println and system.err.println()
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by saikrishna cinux:
what is the actual difference bwtween system.out.println and system.err.println()



The first writes to "standard output". The second writes to "standard error". These two streams are setup by the operating system when the Java program is executed... And can be redirected with the uses of "|", ">", etc. on the command line.

If the Java program is just ran without any redirection (and the java program don't redirect them), there should be no difference.

Henry
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is neither system.out.println(), nor system.err.println().

Extending Henrys answer,


is guaranteed to print "Hello World", but

might print "llo He World" or "HeWorld llo" too.

[ May 13, 2006: Message edited by: Stefan Wagner ]
[ May 13, 2006: Message edited by: Stefan Wagner ]
 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henery/Stefan,

Could you please eloborate some more about the System.err and System.out .....


It's really sound very much interesting for me.



 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There isn't much to elaborate on that.

If you got an errormessage you want to put out to console, write it to System.err, and normal output to System.out, so the user can distinguish them.

Assume a program which searches for email-Adresses and a second one, which writes an email to an adress.


You redirect the output to another program as input:

The second program would try to write a mail to "Unknown shortcut: Virginie".
But the user can use redirection:

The message "Unknown shortcut: Virginie" would go to the logfile, and only the valid output would be used as input for the second program.
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stefan Wagner:
There is neither system.out.println(), nor system.err.println().

Extending Henrys answer,


is guaranteed to print "Hello World", but

might print "llo He World" or "HeWorld llo" too.

[ May 13, 2006: Message edited by: Stefan Wagner ]

[ May 13, 2006: Message edited by: Stefan Wagner ]



No boss i nerver see such thing happen in my system.
it is displaying correctly
the order is correct




cinux
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ankur Sharma:
Henery/Stefan,

Could you please eloborate some more about the System.err and System.out .....


It's really sound very much interesting for me.






Hai

Its very simple,

Every operating system opens file handles for system input , output and error. the programming languages links your application to that handles.

System.out. --------> output handle ( mostly conslole ).
System.err --------> linked to both err file or some times to console

ofcourse you can change the file handle to which these are pointing.....

read some operation stuff( preferrebly unix)..

All the best....
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[cinux]: No boss i nerver see such thing happen in my system.
it is displaying correctly
the order is correct


The fact that it displays correctly on your system is no guarantee for other systems. On many systems, standard output and standard error will use different buffers, and these buffers may be flushed at different times. On my own system just now I got:

HeWorld
llo
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Generally STDERR is not buffered, STDOUT is.

The last thing STDERR writes do is internally call flush().

If you intermingle the two, e.g.:



it is possible (likely) to see error messages before you see what actually caused the error.

Guy
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srinivas Kalvala:




System.out. --------> output handle ( mostly conslole ).
System.err --------> linked to both err file or some times to console



you r saying tht it saves in the error file
where can i get tht file in my system???
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic