• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

System.err or System.out

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have one question:
What is the difference between
System.err.print() or System.out.print().
Both use to print to standard output.
they seems behaviours same.
Can anybody explain to their difference? Thank you!
[ January 22, 2003: Message edited by: michelle Lee ]
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In some applications, output is redirected to a file. In that scenario, System.err.println() is used to display the error messages in the console. If we use System.out.println(), then all the messages will be redirected to the specified file. This is done in order to prevent the error messages being displayed in the redirected file.
------------
Nayan.
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Thanks Talukdar ,
I have writen a sample code to test your suggestion hope it will be useful to understand
Type this in the command prompt while executing code.
java ErrStreamCheck >> test.txt
Error free output will go into file 'test.txt' and error records get printed into consol.
public class ErrStreamCheck
{
public static void main(String args[])
{
String strArr[] = { "p1","p2","p3" };
for(int i =0 ; i<5 ; i++ )
{
try
{
System.out.println("array content " + strArr[i] );
}
catch( Exception oEx )
{
System.err.println("Exception due to wrong index.");
}
}
}
}
[ January 22, 2003: Message edited by: Arun Boraiah ]
[ January 22, 2003: Message edited by: Arun Boraiah ]
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Arun,
That example was great! Putting that in my memory bucket( on disk )
 
Nayanjyoti Talukdar
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice example, Arun
I forgot to mention example!!
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.err does not print to standard out (as stdout); it prints to standard error (stderr). Normally, these are both the console, but as shown in the above example it doesn't have to be. I think these ideas stem from Unix. At least that's where I have become the most familiar with them.
HTH
Layne
 
Nayanjyoti Talukdar
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Normally, these are both the console, but as shown in the above example it doesn't have to be.


what do u mean by that? Do u meanit shouldn't behave like that?
--------------
Nayan
 
Michelle Lee
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all! javaranch is really great, you
can learn a lot from here.
 
reply
    Bookmark Topic Watch Topic
  • New Topic