• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

OCP Oracle Certified Professional Java SE8 Programmer II Study Guide - Error on test question 12  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is:
What is the result of executing the following application? (Choose all that apply.)

Answer options:

A. It compiles and runs without issue.
B. The code will not compile because of m1.
C. The code will not compile because of m2.
D. The code will not compile because of m3.
E. It compiles but throws an exception at runtime.
F. It compiles but hangs at runtime.

The correct answer is:

E. The program compiles without issue, so B, C, and D are incorrect. Lines m2 and m3
throw a compiler warning about generics but still compile. Notice that RecursiveAction,
unlike RecursiveTask, does not return a value. However, since we used a generic Fork-
JoinTask reference, the code still compiles. The issue here is that the base condition is not
reached since the numbers start/end are consistently positive. This causes an infinite loop,
although since memory is finite, Java detects this and throws a StackOverflowError, so E
is correct. In practice, this could also generate a locking exception before the StackOverflowError
when the program runs out of memory, but in either circumstance, the program
will exit.

If correct answer is E it should be either "It compiles but throws an error at runtime." or "It compiles but throws an throwable at runtime.". Because of the exception word I switch my answer to option F despite the fact the book is mentioned that we should take into account that it will be infinite recursion that will end up as StackOverflowError or OutOfMemoryError
 
author & internet detective
Posts: 39208
726
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically yes. In practice, people say 'exception" meaning "anything that could be thrown at runtime." Expect to see that style on the exam as well.
 
Tyoma Sakurakoji
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Technically yes. In practice, people say 'exception" meaning "anything that could be thrown at runtime." Expect to see that style on the exam as well.


Thanks for the warning
 
Marshal
Posts: 63795
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:. . . In practice, people say 'exception" meaning "anything that could be thrown at runtime." . . .

So does the JLS (=Java® Language Specification). It uses the term “exception classes” for Throwable and all its subtypes, and it has similarly precise meanings for “checked exceptions” and “unchecked exceptions”. So that particular convention has official backing.
 
permaculture is largely about replacing oil with people. And one tiny ad:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!