• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Sybex 829 errata. Ch 13 Concurrency review question.

 
Ranch Foreman
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tb864585.JaSE17SG.c13.04




After fixing the errors as in the solution, there is another compile error on w4.




 
Marshal
Posts: 4400
567
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the documentation Future#get throws InterruptedException and ExecutionException.
 
Anil Philip
Ranch Foreman
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:According to the documentation Future#get throws InterruptedException and ExecutionException.



I agree. The issue is that should have been another option in the question - a further action to get it to compile
 
Ron McLeod
Marshal
Posts: 4400
567
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe, but without knowing the question, its hard to comment any further.
 
Anil Philip
Ranch Foreman
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Maybe, but without knowing the question, its hard to comment any further.



original question:



Original answer is w1 and w2 only.
I think it should be w4 also.
 
Ron McLeod
Marshal
Posts: 4400
567
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm - I'm not sure what is meant by to make the code compile.  Obviously to successfully compile the code it needs to be placed in a method inside a class. If the method declares that it throws Exception (or the specific exceptions), line w4 would not need to be changed.

 
Anil Philip
Ranch Foreman
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Hmm - I'm not sure what is meant by to make the code compile.  Obviously to successfully compile the code it needs to be placed in a method inside a class. If the method declares that it throws Exception (or the specific exceptions), line w4 would not need to be changed.

 
Marshal
Posts: 28009
94
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Hmm - I'm not sure what is meant by to make the code compile.  Obviously to successfully compile the code it needs to be placed in a method inside a class. If the method declares that it throws Exception (or the specific exceptions), line w4 would not need to be changed.


Or alternatively, you could delete line w4... or turn it into a comment... or do any number of things to it to make the code compile.
 
author & internet detective
Posts: 41775
887
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the book, it is common to have code snippets. It says in the intro to assume any surrounding code is correct. So you can assume imports/class/method signature. I made just the two changes the explanation suggests in the book and it compiles. Remember that you are assuming the method signature isn't the problem so no need to handle the exception:

 
Anil Philip
Ranch Foreman
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,
Do you not get an error on w4?
As I reported in my OP, w4 errors out



Jeanne Boyarsky wrote:In the book, it is common to have code snippets. It says in the intro to assume any surrounding code is correct. So you can assume imports/class/method signature. I made just the two changes the explanation suggests in the book and it compiles. Remember that you are assuming the method signature isn't the problem so no need to handle the exception:

 
Master Rancher
Posts: 4661
63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that in Jeanne's code, the main() method now says "throws Exception".  Did you add that?  Her code has only one method, so she needed "throws Exception" only on that one method.  In the code you showed where main() calls f6(), you would need to put "throws Exception" on both methods.
 
Anil Philip
Ranch Foreman
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:Note that in Jeanne's code, the main() method now says "throws Exception".  Did you add that?  Her code has only one method, so she needed "throws Exception" only on that one method.  In the code you showed where main() calls f6(), you would need to put "throws Exception" on both methods.



The actual question in the test bank is like in my post here https://coderanch.com/p/3546743
There is no wrapping method.
IMHO this is an incorrectly worded question.
The compiler does point to this line as producing an error and it is marked as w4 in the question.
Otherwise, it should not have been marked such.
 
Mike Simmons
Master Rancher
Posts: 4661
63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was addressed by Jeanne's comment.  They often show code snippets, without the containing class, maybe without a containing method, and maybe without mention of some exceptions that need to be added in throws statements to make the code compile.  In a book, they're trying to save printing space by not including some details that the reader can figure out without showing them.  Otherwise every example is longer, and it's more expensive and heavy to carry around.

In this case, w1 and w2 were things that needed to be fixed in the code shown.  w4 is something that can be fixed outside the code shown.  And for stuff like that, we're normally supposed to assume that outside code is written in a way to prevent errors.  That may seem a subtle point, but that's the logic being used here.
 
Ron McLeod
Marshal
Posts: 4400
567
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anil Philip wrote:The actual question in the test bank is like in my post here https://coderanch.com/p/3546743
There is no wrapping method.


Sure, but if the code was not wrapped in a method, it would not compile at all; even with line w4 commented-out.

I don't have the book, but Jeanne's comment regarding that was:

Jeanne Boyarsky wrote:In the book, it is common to have code snippets. It says in the intro to assume any surrounding code is correct. So you can assume imports/class/method signature.


 
Jeanne Boyarsky
author & internet detective
Posts: 41775
887
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anil Philip wrote:Jeanne,
Do you not get an error on w4?
As I reported in my OP, w4 errors out


The question is which lines need to be changed to make the code compile. Changing lines w1 and w2 as described in the explanation cause it to compile. The question doesn't ask whether fixing produces an exception.

This question is correct as is.
 
Honk if you love justice! And honk twice for tiny ads!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic