aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Whats wrong with system.err? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Whats wrong with system.err?" Watch "Whats wrong with system.err?" New topic
Author

Whats wrong with system.err?

Amrish Bharatiya
Greenhorn

Joined: Nov 10, 2009
Posts: 5
Hello,

I wrote the below piece of code to print out a multiplication table on the console and highlight the numbers that are exact square in red.



When I run this code I get a different output every time:

This is what I got on my last run:


If I replace system.err (line #12) with system.out, then the output is fine:



Interestingly when I put a debug point in eclipse and do a step by step debug (with system.err) the out put comes on fine. (I tried flushing the streams for every loop of i and j but it didn't help).

So whats happening when I use system.err? Any pointers appreciated!

Thanks in Advance,
Amrish

~Amrish
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
I don't think it's an issue of System.err being broken. It's combining the use of System.err and System.out.
I added flush() methods and it displayed correctly:I'm sure someone smarter than me can give you the salient details.
Amrish Bharatiya
Greenhorn

Joined: Nov 10, 2009
Posts: 5
Thanks Tom, but even after adding the flush after the print I am getting the same (inconsistent) results:



Here is the code I am running:
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
You missed two places to add flush(). See my code.
Amrish Bharatiya
Greenhorn

Joined: Nov 10, 2009
Posts: 5
I tried copy pasting your exact code, but I am still getting inconsistent results. I guess it might be problem with my compiler.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Here's a tip on debugging: Rule #1: Never assume it's someone else's bug.
Amrish Bharatiya
Greenhorn

Joined: Nov 10, 2009
Posts: 5
Thanks that's helpful!!

All I am saying is that it might be something that "I" might have setup my eclipse environment that would be causing it. if you have a solution please do tell.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're running in Eclipse: the output from streams to the output tab is non-deterministic and will be interwoven essentially randomly. You cannot rely on IDE-specific behavior. Run it in a real console.
Amrish Bharatiya
Greenhorn

Joined: Nov 10, 2009
Posts: 5
David Newton wrote:You're running in Eclipse: the output from streams to the output tab is non-deterministic and will be interwoven essentially randomly. You cannot rely on IDE-specific behavior. Run it in a real console.


Thanks David! That did work.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Just to be nitpicky:

Use System.out for normal program output and System.err for error output. Most OS's are geared for this usage and it's a little easier if you follow the conventions.

Of course, System,anything should only be used where appropriate - which is primarily in command-line applications. For environments that don't run directly in a command-line shell such as Applets, webapps, mobile apps, and so forth, you should use some sort of logging system.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Whats wrong with system.err?