• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Some minor typos in chapter 6 (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 301, exception text:
$ javac Zoo.java
$ java Zoo Zoo


ZooException in thread "main"
java.lang.ArrayIndexOutOfBoundsException: 1
at mainmethod.Zoo.main(Zoo.java:7)


The code example and the exception text are the same on page 7/8, but there is a bit difference. The example which is on page 301 has line numbers. Therefore 7 should be 4 in exception text because ArrayIndexOutOfBoundsException occur on line 4. And mainmethod.Zoo.main should be Zoo.main because there is no package (as line start from 1).

Maybe I am wrong but I think it may be helpful if I am right, so I want to note
mainmethod.Zoo.main should be Zoo.main in the exception text on page 8 too. If we guess that Zoo class (on page 7) include in mainmethod package so we have to compile and execute it as the following:

$ javac mainmethod/Zoo.java
$ java mainmethod.Zoo Zoo



2. On page 306, the second code example:
line 3 does not compile too. It may be added comment to this line.


3. On page 308, the second code example:
"DOES NOT COMPILE" have been added on line 25, but compile error occurs on line 29.


4. On page 313, the first sentence:
However, the finally block runs after the try block.

Maybe try block should be catch block.


5. On page 316, the first code example:
We use this for referring instance members therefore we can't use this keyword in static method. So setNumberEggs() method shouldn't be static.


6. On page 317, "Checked Exceptions" section, the fourth sentence:
Common runtime exceptions include the following:

runtime should be checked.


7. On page 330, question #14:
There is no typo in this question. Just I note it for informing authors about it. IOException is written two different forms: one of them without package name (line 7) and the other with package name (option D). If it is used without package name in code we guess that package has already been imported. And it can be used without package name in option D.
 
Roel De Nijs
Sheriff
Posts: 10666
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 301, exception text:

Agreed on both the qualified name of the class (should be Zoo.main instead of mainmethod.Zoo.main) as on the line number (should be 4 instead of 7)

The code example and the exception text are the same on page 7/8, but there is a bit difference. The example which is on page 301 has line numbers. Therefore 7 should be 4 in exception text because ArrayIndexOutOfBoundsException occur on line 4. And mainmethod.Zoo.main should be Zoo.main because there is no package (as line start from 1).

Mushfiq Mammadov wrote:Maybe I am wrong but I think it may be helpful if I am right, so I want to note
mainmethod.Zoo.main should be Zoo.main in the exception text on page 8 too.

Agreed on this one as well. Still wondering why the stack trace says line 7 Even with an additional package statement and an empty line, it should have been line 6 (unless package statement and class declaration are seperated by two empty lines).

Mushfiq Mammadov wrote:2. On page 306, the second code example:
line 3 does not compile too. It may be added comment to this line.

True! If curly braces were added to the try statement, the catch statement would still not compile.

Mushfiq Mammadov wrote:3. On page 308, the second code example:
"DOES NOT COMPILE" have been added on line 25, but compile error occurs on line 29.

Yeps! My compiler also gives the compiler error on line 29.

Mushfiq Mammadov wrote:4. On page 313, the first sentence:
However, the finally block runs after the try block.

Maybe try block should be catch block.

Definitely! Because the catch block executes (to catch the RuntimeException from the try block).

Mushfiq Mammadov wrote:5. On page 316, the first code example:
We use this for referring instance members therefore we can't use this keyword in static method. So setNumberEggs() method shouldn't be static.

Spot-on! On the previous page the setNumberEggs() method is an instance method (as it should be).

Mushfiq Mammadov wrote:6. On page 317, "Checked Exceptions" section, the fourth sentence:
Common runtime exceptions include the following:

runtime should be checked.

Absolutely! Probably a copy/paste issue from the "Runtime Exceptions" section.

Mushfiq Mammadov wrote:7. On page 330, question #14:
There is no typo in this question. Just I note it for informing authors about it. IOException is written two different forms: one of them without package name (line 7) and the other with package name (option D). If it is used without package name in code we guess that package has already been imported. And it can be used without package name in option D.

I'm not the author of the book, but I think this one is intentional. Those exam creators try anything to confuse you and thus so do book authors

Hope it helps!
Kind regards,
Roel
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Agreed and logged

2) The point the text is making is that the code example doesn't compile as a whole. Writing every line that doesn't compile is distracting. (Line 2 doesn't compile either if we are listing things). But the point is that the braces are missing rather than what lines fails.

3) Same as #2. The point is that the example doesn't compile rather than the line where it occurs.

4) Agreed and logged

5) Good catch! I'm impressed. You are going to great on the test if you can find this sort of thing when thinking about exceptions.

6) Yes. Vince reported it three months ago so it is already in the errata.

7) Yes, it is intentional. We try to get you used to different styles.
 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote: 5) Good catch! I'm impressed. You are going to great on the test if you can find this sort of thing when thinking about exceptions.

But my test results are not still good enough. When I read a topic I look at examples carefully. But I hurry up for time when I take mock exam. And I make simple mistake for my carelessness.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mushfiq Mammadov wrote:
Jeanne Boyarsky wrote: 5) Good catch! I'm impressed. You are going to great on the test if you can find this sort of thing when thinking about exceptions.

But my test results are not still good enough. When I read a topic I look at examples carefully. But I hurry up for time when I take mock exam. And I make simple mistake for my carelessness.

I don't suppose there is any pattern to the mistakes? Like can you make a checklist for yourself: 1) Look for error X. 2) Look for null pointer 3) profit?
 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote: I don't suppose there is any pattern to the mistakes? Like can you make a checklist for yourself: 1) Look for error X. 2) Look for null pointer 3) profit?

I try but I can't always do it successfully. When I take mock exam without time I look through code example minimum three times. But when I take mock exam with time I look through code example maximum twice. One of the my last mistake was that I saw the valid method as constructor which its name is the same with the name of class. And I follow constructor rules. I go crazy when I saw the correct answer and explanation
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mushfiq Mammadov wrote:When I take mock exam without time I look through code example minimum three times. But when I take mock exam with time I look through code example maximum twice.

As I've already mentioned in another topic, this is probably a big (maybe even huge) factor in the difficulty of these exams: in a limited time you have to read the question very carefully and evaluate the code snippet thoroughly. One minor slip-up and you select the wrong answer. And you have to stay really focused for 2.5 hours (or 2 hours for OCA7)!

Mushfiq Mammadov wrote:One of the my last mistake was that I saw the valid method as constructor which its name is the same with the name of class. And I follow constructor rules. I go crazy when I saw the correct answer and explanation

No worries! We all have had similar experiences. And it's much better to make this mistake in a mock exam than on the actual exam I'm pretty sure you won't make this mistake again on the actual exam. Long live the mock exams!
 
Roel De Nijs
Sheriff
Posts: 10666
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:If we guess that Zoo class (on page 7) include in mainmethod package so we have to compile and execute it as the following:

$ javac mainmethod/Zoo.java
$ java mainmethod.Zoo Zoo

Although you are correct about the java command, you are not required to invoke the commandto compile the Zoo.java source code file. If the current directory would be the directory mainmethod, you could compile the Zoo.java source code file using the commandAnd from inside the directory mainmethod, you could even run the Zoo.class file using the option -cp

Now let's try! Assume we have this source code fileAnd Zoo.java is located in the directory D:\ocajp\src\mainmethod. Here are the commands to compile and run this code

Just adding this note for completeness (and a little bit for fun ). More examples about using javac and java command can be found here.

Hope it helps!
Kind regards,
Roel
 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:Although you are correct about the java command, you are not required to invoke the commandto compile the Zoo.java source code file. If the current directory would be the directory mainmethod, you could compile the Zoo.java source code file using the commandAnd from inside the directory mainmethod, you could even run the Zoo.class file using the option -cp


It is interesting that we can compile code without package name If the current directory is mainmethod directory, but we can't run the code without package name in that directory. Thanks for extra information.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic