Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Some minor typos and confused points about chapter 4 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. On page 172, parentheses is missing:
The second line is:
Parentheses of walk2 method is missing. Because it is written in explanation:
walk2() doesn’t compile because it is missing the braces around the empty method body.



2. On page 173, access modifiers:
The first sentence of Applying Access Modifiers topic:
You are already saw that there are four access modifiers: public, private, protected, and default access.

I downloaded java quiz from play market and I encountered the following question there:
“How many access modifiers are?”
My answer was four. But the correct answer was three. The explanation of that question was:
"There are four access level: public, private, protected and default access. But there are three access modifiers: public, private and protected".
Is it correct or not?


3. On page 192, return statement is missing:
The second part example:
And then it is written:
This method doesn’t compile because it only differs from the original by return type.

If these would be valid overloading the second fly method does not still compile because the return statement is missing.


4. On page 203, line 4 is missing:
In the third sentence:
Rule 2 says to run the static variable declarations and static initializers – in this case, line 5 and 6, which output 0 and 10.

“line 5 and 6” should be “line 4, 5 and 6”.


5. On page 209, maybe “that” is redundant:
In the seventh line:
You want to write a method that that takes an age() method as input.
Maybe one of “that” is redundant.


6. On page 211, semicolon is redundant:
Lambda Syntax section, first example:
Semicolon is redundant here, because we can use semicolon only inside braces with together return statement.


7. On page 212, confused point:
Third paragraph, fourth sentence:
Java doesn’t require you type return or use a semicolon when no braces are used.

There is no typo in this sentence but a bit confused. I understand this sentence as this: Java doesn’t require, so it is optional, we can type these if we want or not. But return and semicolon haven’t been to typed if there is no braces.
Maybe everything is ok but my English is not enough


8. On page 215, H should be h:

a) First paragraph, fifth sentence:
We decide we want to remove all of the bunny names that don’t begin with the letter h because our little cousin really wants us to choose an H name.
Maybe H should be h for case sensitive.

b)Third paragraph, second sentence:
Remember the one method in the interface called test()?
Maybe ? should be dot (.) .


9. On page 344, mock explanation #17:
First sentence:
Since Java is pass-by-reference, assigning a new object to a does not change the caller.

Maybe it is typo, because we say Java always use pass-by-value.


10. On page 346, mock explanation #29:
First sentence:
Option B is incorrect because it does not use the return keyword.

Third sentence:
Additionally, option C is missing the return keyword and option E is missing the semicolon.

It would be good that adding “and semicolon” after the return keyword. Because it does not still compile if we add only return keyword.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mushfiq Mammadov wrote:1. On page 172, parentheses is missing:
...
Parentheses of walk2 method is missing.

Correct! Should be public void walk2() ;

Mushfiq Mammadov wrote:2. On page 173, access modifiers:
The first sentence of Applying Access Modifiers topic:
You are already saw that there are four access modifiers: public, private, protected, and default access.

I think that sttement is indeed incorrect. Should be there are four access levels. In Java you have 3 access modifiers (private, protected and public) and 4 access levels.

Mushfiq Mammadov wrote:3. On page 192, return statement is missing:
...
If these would be valid overloading the second fly method does not still compile because the return statement is missing.

Spot-on! Should be something like public int fly(int numMiles) { return 1979; }

Mushfiq Mammadov wrote:4. On page 203, line 4 is missing:
In the third sentence:
Rule 2 says to run the static variable declarations and static initializers – in this case, line 5 and 6, which output 0 and 10.

“line 5 and 6” should be “line 4, 5 and 6”.

Correct as well! Line 4 has a static variable declaration (and initialization), so that's a part of the second rule.

Mushfiq Mammadov wrote:5. On page 209, maybe “that” is redundant:
In the seventh line:
You want to write a method that that takes an age() method as input.
Maybe one of “that” is redundant.

True! One "that" will do the job

Mushfiq Mammadov wrote:6. On page 211, semicolon is redundant:
...
Semicolon is redundant here, because we can use semicolon only inside braces with together return statement.

You are right! The lambda expression should not have the semicolon at the end. Probably the best proof: in figure 4.5 the same lambda expression doesn't have the semicolon at the end If you assigned that lambda expression to a reference variable of type Predicate<Animal>, you could have a semicolon at the end (but it's the semicolon to finish the statement, not the lambda expression)

7. On page 212, confused point:
...
There is no typo in this sentence but a bit confused. I understand this sentence as this: Java doesn’t require, so it is optional, we can type these if we want or not. But return and semicolon haven’t been to typed if there is no braces.
Maybe everything is ok but my English is not enough

I tend to agree with this, but it could be a typical English language thing (again). But because these code snippets do not compile, it might be better (more clear) to have something like: It's not allowed to type return or use a semicolon when no braces are used

Mushfiq Mammadov wrote:a) First paragraph, fifth sentence:
We decide we want to remove all of the bunny names that don’t begin with the letter h because our little cousin really wants us to choose an H name.
Maybe H should be h for case sensitive.

Agreed! Either all names should start with a capital and then each h should be changed to H; otherwise "an H name" should be "an h name".

Mushfiq Mammadov wrote:b)Third paragraph, second sentence:
Remember the one method in the interface called test()?
Maybe ? should be dot (.) .

I guess that sentence is not intended as a question, so it should indeed be ended with a dot.

Mushfiq Mammadov wrote:9. On page 344, mock explanation #17:
First sentence:
Since Java is pass-by-reference, assigning a new object to a does not change the caller.

Maybe it is typo, because we say Java always use pass-by-value.

From the explanation of #16: Since Java is pass-by-value
From the explanation of #17: Since Java is pass-by-reference
So it's one or the other. And we all know Java always uses pass-by-value, so the explanation of #17 should be fixed.

Mushfiq Mammadov wrote:10. On page 346, mock explanation #29:
...
It would be good that adding “and semicolon” after the return keyword. Because it does not still compile if we add only return keyword.

Spot-on again! Should be something like: Additionally, option C is missing both the return keyword and the samicolon; option E is only missing the semicolon.

Hope it helps!
Kind regards,
Roel
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note: I got interrupted numerous times while writing this so I started before Roel posted.

Mushfiq Mammadov wrote:1. On page 172, parentheses is missing:

Agreed and added to errata.

Mushfiq Mammadov wrote:2. On page 173, access modifiers:
The first sentence of Applying Access Modifiers topic:
You are already saw that there are four access modifiers: public, private, protected, and default access.

I downloaded java quiz from play market and I encountered the following question there:
“How many access modifiers are?”
My answer was four. But the correct answer was three. The explanation of that question was:
"There are four access level: public, private, protected and default access. But there are three access modifiers: public, private and protected".
Is it correct or not?

2) This is a semantics thing. There are four access modifiers/levels, but one happens to be the lack of a keyword. So there are three access modifier keywords. I checked and Oracle shows a table of four "modifiers" with one being "no modifier". Don't worry, the exam will quiz you on code in this space; not counting them.

Mushfiq Mammadov wrote:3. On page 192, return statement is missing:
The second part example:
And then it is written:
This method doesn’t compile because it only differs from the original by return type.

If these would be valid overloading the second fly method does not still compile because the return statement is missing.

3) While your point is true, the code doesn't compile because of the invalid override. The compiler doesn't get up to looking at the method. If you try compiling this class, you get the following error:

oca-ocp-book nyjeanne$ javac Jeanne.java
Jeanne.java:4: error: method fly(int) is already defined in class Jeanne
public int fly(int numMiles) { }
^
1 error

Mushfiq Mammadov wrote:4. On page 203, line 4 is missing:
In the third sentence:
Rule 2 says to run the static variable declarations and static initializers – in this case, line 5 and 6, which output 0 and 10.

“line 5 and 6” should be “line 4, 5 and 6”.

Agreed. Logged in errata

Mushfiq Mammadov wrote:5. On page 209, maybe “that” is redundant:
In the seventh line:
You want to write a method that that takes an age() method as input.
Maybe one of “that” is redundant.

Agreed. I was wondering how we didn't catch that (We do run Word spell/grammar check.) We didn't write the error. Two different editors updated that sentence and the change somehow got applied twice. Interesting.

Mushfiq Mammadov wrote:6. On page 211, semicolon is redundant:
Lambda Syntax section, first example:
Semicolon is redundant here, because we can use semicolon only inside braces with together return statement.

It's not redundant; it's wrong. Redundant implies it is allowed but unneeded. Here, a semi-colon isn't allowed. Anyway, logged the error.

Mushfiq Mammadov wrote:7. On page 212, confused point:
Third paragraph, fourth sentence:
Java doesn’t require you type return or use a semicolon when no braces are used.

There is no typo in this sentence but a bit confused. I understand this sentence as this: Java doesn’t require, so it is optional, we can type these if we want or not. But return and semicolon haven’t been to typed if there is no braces.
Maybe everything is ok but my English is not enough

Ooh. English ambiguity! I've made a note to clarify this if we do a Java 9 book. It isn't wrong per se. Java doesn't require you to type return/use a semi-colon when not using braces. The problem is that it doesn't allow it either. (Which is covered elsewhere in the text. But we should clean up that sentence so it is clearer in isolation)

Mushfiq Mammadov wrote:8. On page 215, H should be h:

That's just English not code. I agree with our editors that it reads better with uppercase.

Mushfiq Mammadov wrote:9. On page 344, mock explanation #17:
First sentence:
Since Java is pass-by-reference, assigning a new object to a does not change the caller.

Maybe it is typo, because we say Java always use pass-by-value.

Yes. Logged

Mushfiq Mammadov wrote:
10. On page 346, mock explanation #29:
First sentence:
Option B is incorrect because it does not use the return keyword.

Third sentence:
Additionally, option C is missing the return keyword and option E is missing the semicolon.

It would be good that adding “and semicolon” after the return keyword. Because it does not still compile if we add only return keyword.

For option C, i'll put it in my clarification list. It's not wrong so not an errata.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic