This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exercise 5-4  RSS feed

 
Barbara Flink
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Campbell Ritchie
Marshal
Posts: 55707
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 55707
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sorry.
 
Barbara Flink
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys! So it isn't me ... it's NetBeans!!!
I appreciate your help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!