Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!

Vincent Botteman

+ Follow
since May 22, 2015
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vincent Botteman

Hi Roel,

The answers of the quiz:

It compiles successfully because the checked exception FoodException is caught. No problems at runtime.

At compile time the reference a is an Animal. And the exception FoodException is not caught or declared to be thrown. So compile error.

Similar to case 1: no compile or runtime errors

The reference is cast to Animal and the method throws FoodException which is not caught or declared to be thrown, so compile error.

The reference is cast to Tiger and the method throws VeggieException which is a subclass of Exception thrown by method5, so the source compiles. But at runtime it will throw a ClassCastException because the object the reference a is pointing to is not a Tiger object.

The reference a is cast to Elephant and the method throws no exception. It will compile and run successfully. A method is free to declare to throw an exception without actually throwing it.

This time it fails to compile because the catch block is unreachable.

I have some remarks about the String methods described in chapter 3:
- page 109: the String method contains takes a CharSequence and not a String
- page 106: according to the API the method charAt throws IndexOutOfBoundsException (superclass of StringIndexOutOfBoundsException). Do we need to know the exact exception on the exam? A similar case: according to the API the String method substring throws IndexOutOfBoundsException but the StringBuilder method substring throws StringIndexOutOfBoundsException.
- Methods like isEmpty() and intern() are not mentioned. No chance these are used on the exam?
Thanks to all for the clarification. It takes my knowledge of exceptions one step further.
I think the code will not compile because FileNotFoundException is a checked exception and FileNotFoundException is not a superclass of the class that is declared to be thrown by the method (i.c. IOException). So the compiler will detect that FileNotFoundException or a subclass will never be thrown in the try block.
One of the question about the String methods

The explanation starts with the sentence "Line 6 returns the number 3 since indexes are zero based." The index of number 6 in the string is 2 and not 3.
One of the question is

In which order can you assemble the following statements in to make a valid Java program? (Choose all that apply)
A. /* Hello World */
B. ArrayList list;

What is the purpose of this question as you can not specify any order of the elements?
I selected answers A,D,E,F because together and in that order they make a valid Java program. But the correct answer is different and I don't understand the explanation.

Maybe the question was supposed to be something like this?

1: /* Hello World */
2: ArrayList list;

Possible answers:
A: 1,3,4,2,6,5
B: 4,1,3,5,2,6
One of the questions is about what exception can fill in the blank line to make the code compile.

In the answer option D (LimpException) is said to be incorrect because the method split throws HurtException and no other exception. Therefore catching LimpException would be unreachable code because HurtException is already caugth.
But I can compile following code, so answer D is correct. I do receive a warning in my IDE about unreachable code but the source compiles and runs.

I found 2 small error in Chapter 6:
- page 314: ClassCastException: Thrown by the JVM when an attempt is made to cast an object to ...
- page 317: Third line: Common checked exceptions include the following:

I was also confused because a NumberFormat is stated as thrown by the programmer and not by the JVM but other threads in this forum seems to confirm this.
In the explanation of mock exam question 15 of chapter 4, the class names should start with capital:
It can be autoboxed to a Boolean
It can be autoboxed to a Double