Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sybex OCP Java 8 Study Guide - Page 346  RSS feed

 
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 346:

ScheduledFuture<V> is identical to the Future<V> class, except that it includes a
getDelay() method that returns the delay set when the process was created.



The API_documentation states about the getDelay() method:

Returns the remaining delay associated with this object, in the given time unit.
Returns:
the remaining delay; zero or negative values indicate that the delay has already elapsed

 
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct. I checked with Scott and he said the delay decreases over time as execution approaches.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on page 563 - explanation to exercise 10:

The problem here is that c1 is a String but c2 is an int, 


It's the opposite way: c1 is an int, and c2 a String.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 401 - exercise 17:
there is an import statement which is incomplete, the code doesn't compile

import java.util.concurrent.*;



You must add: import java.util.concurrent.atomic.*;
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Juerg Bauman wrote:on page 563 - explanation to exercise 10:

The problem here is that c1 is a String but c2 is an int, 


It's the opposite way: c1 is an int, and c2 a String.


Agreed. This is already listed on our errata page.

Juerg Bauman wrote:On page 401 - exercise 17:
there is an import statement which is incomplete, the code doesn't compile

import java.util.concurrent.*;



You must add: import java.util.concurrent.atomic.*;


The instructions on the exam tell you to assume any required imports are there. So missing imports are not errata.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 469:

Luckily, Java provides us with the normalize(Path)


normalize() is an instance method and doesn't take a Path argument.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Confirmed and added to the errata. Thanks!
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 477: the example with newBufferedWriter
it's not really an error, just a needless line of code:

List<String> data = new ArrayList();


List data isn't needed anywhere in that example.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 484:

The first method, Files.readAttributes(), returns a read-only view ...
...The second method, Files.getFileAttributeView(), returns


In the previous pages you always mentioned the complete method signatures, incl. parameters.
So in this case it should be:
Files.readAttributes(Path, Class<V>)
Files.getFileAttributeView(Path, Class<A>)
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Juerg,
Neither of those are errors. Inconsistencies, sure. But not errors.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on page 571, explanation to question 20:

...the path value after the first line is just the current directory symbol.



The path value after normalize() is empty, so doesn't contain the current directory symbol --> path.toString().isEmpty() outputs true.
Nevertheless getNameCount() results in 1 and the answer B is correct.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True. We meant logically. I'll add that to our private list of things that could be clearer.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 551, explanation 7:

D is incorrect, as adding settings is the opposite ...


It should say: ... adding setters ...
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed and logged in the errata. Thank you!
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 191:

The findAny() and findFirst() methods return an element of the stream unless the stream is empty.
If the stream is empty, they return an empty Optional.


These methods return an Optional in any case, wether the stream is empty or not.
It sould be something like: ... methods return an Optional wrapping an element of the stream ...
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 193:

This code snippet is intended to fail, anyway. Stream s is defined without generics and raw typing shouldn't be used anymore.
So better would be: Stream<Integer> s = ...
 
Marshal
Posts: 58367
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . or an explanation of the unchecked compiler warning?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Juerg Bauman wrote:On page 191:

The findAny() and findFirst() methods return an element of the stream unless the stream is empty.
If the stream is empty, they return an empty Optional.


These methods return an Optional in any case, wether the stream is empty or not.
It sould be something like: ... methods return an Optional wrapping an element of the stream ...


You are correct that they return an optional with the element. It's not an errata because were were talking colloquially.

Juerg Bauman wrote:On page 193:

This code snippet is intended to fail, anyway. Stream s is defined without generics and raw typing shouldn't be used anymore.
So better would be: Stream<Integer> s = ...


Also, not an errata. It doesn't compile with Stream or Stream<Integer>

Campbell Ritchie wrote:. . . or an explanation of the unchecked compiler warning?


There's no warning because it doesn't compile.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 565, explanation 1:

...use BufferedReader/BufferedWriter directly on a stream.


it should be: ... directly on a Stream. 
( or Stream class)
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stream is a concept there. Which is fine in lowercase.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something went wrong with the last update of https://www.selikoff.net/java-ocp-8-programmer-ii-study-guide/ ;
pages 483ff: one double entry, one entry missing the original 483)
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 511:

The UPDATE statement changes one or more rows in the database:
The DELETE statement deletes one or more rows in the database:


In both cases it should be: ... zero or more rows ...  as shown one page earlier:

UPDATE: Change zero or more rows in the table
DELETE: Remove zero or more rows from the table

 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Juerg Bauman wrote:On page 511:

The UPDATE statement changes one or more rows in the database:
The DELETE statement deletes one or more rows in the database:


In both cases it should be: ... zero or more rows ...  as shown one page earlier:

UPDATE: Change zero or more rows in the table
DELETE: Remove zero or more rows from the table


Confirmed and added to the errata.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 91, Figure 2.9:
The name of the class "ZooKeeper" declared in the factory pattern example doesn't match with figure 2.9, where the same class is called "Client". The other class names are identical in description and figure.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Juerg Bauman wrote:On page 91, Figure 2.9:
The name of the class "ZooKeeper" declared in the factory pattern example doesn't match with figure 2.9, where the same class is called "Client". The other class names are identical in description and figure.


The diagram is referring to the generic concept of a Client/caller.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 154:

16: String str = "abc";
17: Predicate<String> methodRef2 = str::startsWith;
...
Line 17 shows that we want to call string.startsWith()


It should be: ... to call str.startsWith()
 
Campbell Ritchie
Marshal
Posts: 58367
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid somebody else has beaten you to it and found that last misprint last week.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 247: Working with Durations

A Duration is stored in hours, minutes, and seconds.


JavaDoc states about Duration:

This class models a quantity or amount of time in terms of seconds and nanoseconds.



This is the reason why above Duration doesn't remember its original input of 3600s and prints the calculated value of 1H.
Period is different: it actually stores years, month, days.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 331/332:

Then you start the task by using the Thread.start() method.


...make sure that you remember to start the task with the Thread.start() method.


The start() method of Thread is an instance method, not a static one.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 333 - Real World Scenario

Implementing Runnable allows the class to be used by numerous Concurrency API classes.


Above quote is valid for both options: extending the Thread class and implementing Runnable.
Since the Thread class implements the Runnable Interface, Thread IS A Runnable, also.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
re threds:
In the Real World Scenario, you are correct. That's not the point were are trying to make. From the context, it is about why Runnable is often better. And with Thread.sleep, it's like writing ArrayList.add - we are expressing the class the method is on, not implying that it is static.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38027
605
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
re duration - that's true. We meant logically.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 113 - What you can't do with Generic Types

Create an array of that static type. This one is the most annoying, but it makes sense
because you’d be creating an array of Objects.


I have a doubt, why static type? Should it not be generic type? An array of generic type would result - due to type erasure - in an array of Object. What is the meaning of "static" in that context?
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 360 - table 7.9:
The elements of ConcurrentSkipListMap are kept sorted, they loose their original order. The column "Elements Ordered?" is incorrect (Yes), it should be: No
The same for ConcurrentSkipListSet, the elements get sorted and loose their original order. The column "Elements Ordered?" is incorrect (Yes), it should be: No
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 475 - Files.move(Path, Path):

By default, the move() method will follow links, ...
These behaviors can be changed by providing the optional values NOFOLLOW_LINKS , REPLACE_EXISTING , or ATOMIC_MOVE , ...


The JavaDoc says:

If the file is a symbolic link then the symbolic link itself, not the target of the link, is moved.


Furthermore there is no option parameter NOFOLLOW_LINKS available for this method.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 394 - question#3:

The get() method throws checked exceptions which are not handled in the code. For me an error, for you ... I already know your answer.
For me it's very weird to assume, that these exceptions are declared somewhere else ( f.e. in main()), not visible in the code since it's only a code snippet.
It's worse than the topic of missing import statement.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 565 - explanation#5:

The append() method throws an IOException.


The Console method writer() returns PrintWriter, its append() is overridden and does not throw any checked exceptions anymore.
JavaDocs says to PrintWriter:

Methods in this class never throw I/O exceptions, ...


 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page xliii - Assessment Test #11:

C. magic(Stream.iterate(1, x ->> x++)); ...
D. ...


I'm not sure wether the lambdas in option C and D are incorrect intentionly or it's just a typo.
 
Juerg Bauman
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mock exam#2 - the question with System.console / Writer / append:
It's the same topic as mentioned earlier. It's true that the Writer append() method throws an IOException, for compile time reasons this exception has to be catched/declared.
But the instance is of type PrintWriter, its append() is overridden and no IOException can be thrown.
The Option E: An IOException may be thrown is incorrect.
Writer readline() could throw an IOError, not Exception.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!