This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I'm studying the K&B book for the SCJP and I'm working on Exercise 5-4 on page 377-378
Here is my solution:
I have two questions
1) Evidently I misunderstand how "finally" works. Why is "That's all for now" printing before the stack trace?
2) I am used to editing and running my Java programs in NetBeans.
How do I pass an argument when I run a file in NetBeans?
You should be able to pass JVM arguments via NetBeans; if you get a "run" dialogue search through that.
I suggest you get a pencil and paper, print out your code with double-spacing, and draw arrows from line to line, so you can see the flow of execution. You may have misunderstood; I tried exactly the same program and got the stack trace before "That's all". The reason may be that the stack trace prints to the standard error stream, and the other output to the standard output stream, which re like different threads, and do not necessarily print in a particular order. Also using an IDE may alter the order of output.
Barbara Flink wrote:1) Evidently I misunderstand how "finally" works. Why is "That's all for now" printing before the stack trace?
It doesn't. At least, not from my command line. The thing is, "That's all for now" goes to System.out while the stack trace goes to System.err. The console usually interweaves these two quite well, but IDE's like Eclipse and NetBeans guarantee no specific interweaving at all. In your case, apparently, NetBeans finishes the System.out part before the System.err part.
Joined: Oct 13, 2005
Yesterday, I wrote:. . . You may have misunderstood . . .
And looking at that now, it doesn't make sense. I think I ought to have said
You may not have misunderstood
Joined: Aug 02, 2010
Thanks guys! So it isn't me ... it's NetBeans!!!
I appreciate your help.