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

Errors in OCA certification book

 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am reading a book by Mala Gupta with title OCA Java SE7 certification guide. This book has numerous errors because the code in the book was not tested. I found this out when i entered the same code into my Netbeans IDE and try to run the prog. My current problem is that i am unable to successfully compile a piece of code that i wrote to test "Sample exam question 3.3" in the mentioned book. Please look at the following code and tell me where the method definition should go. I tried inserting the method before "main" and within "main", but both give compile errors, at the start of the definition of the method. If i put the method above "main" I get an error about "static method.......". If i move the method to inside main, different set of errors.

Thanks - s.


public class JavaCert2 {


public double subtractnumbers(long a1, long a2, short a3) {
double sum = a1 + a2 + a3;
return sum;
}

public static void main(String[] args) {

/* sample exam question 3.3 */
/* public double subtractnumbers(long a1, long a2, short a3) {
double sum = a1 + a2 + a3;
return sum;
}
*/

double test = subtractnumbers(1L, 2L, (short) 3);
System.out.println(test );
}

}

 
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
The actual question 3.3 just gives you the method signature such as:



This does compile. When calling it from main which is a static method, you need to create a local variable first:


ps - I was the technical proofreader of the book and I assure you that each and every example was tested. (It's possible an error was introduced after that point, but I'm surprised to hear the code has "numerous errors." Can you provide an example of such an error? This current example isn't an error in the book because only a single method was provided. The problem came from the code that you added afterwards to make it a standalone program.
 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I didn't create an object in order to call the method of the object (and it was not a static method). Very basic, but a good place a beginner would stumble. I shouldn't have said "numerous", so i retract it. I did find some problems here and there, but i forgot to mark them down. If i come across any, i will be sure to post it into this thread at that time. For now, one that came to my mind was Exercise 2.2. When i type in that code into Netbeans IDE and compile, it hits errors only on 2 lines (4 and 6). Line 7 is not triggering an error, because once 6 is fixed 7 will be ok. So, based on the 2 errors shown in this IDE (windows XP), i would say option d is not correct. Notice that i do understand what the author is trying to explain regarding line 7, but the fact remains that only 2 errors are triggered while compilation.

The other question i find difficult to swallow is Q3.9. Wouldn't it be appropriate to say that there is one basic constructor, which has been overloaded 2 times ? I do see that one could argue that all 3 constructors should be counted, as they are all "overloaded". What do you think ?

Special thanks to you, for checking out all the code bits in the book, because that gives me more confidence in the book now.
 
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
I concur. Missed that one.
 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any books that you are aware of that will give me "practice exams" for OCA ? The only book that comes up on amazon is a e-book kindle edition and i don't own a kindle. I have one book that gives practice questions (about 100) with green/black cover, but i would like to go through some timed exams to be ready for the exam. Mala gupta gives only one exam. I do see one other at oracle website for $69. It is under Certification -> Exams -> ePractice exam

Oracle site OCA exam

But that would be a steep price, if oracle only gives one exam for that price. Do you know how many exams are present if i purchase that at oracle site ?
 
Campbell Ritchie
Sheriff
Posts: 51413
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know.

I think this discussion would fit better in our exams fora. Moving.
 
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
Does it have to be a book? Software would better simulate the exam experience. You can buy 6 mock exams for way less than the price Oracle lists.
 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that response Jeanne. Here is another that i consider to be error in the OCA book. It is option e in sample exam question 3.10. (posted this at manning.com with no reply in 2 days).
This question asks to select incorrect options. Option e should have been one of the incorrect options for class below.


This class has a user defined constructor (even though it is an empty constructor, doing nothing). Once the user defines a constructor, the default constructor is NOT supplied (according to the author's own words in the book). So, the above class is NOT eligible for a default constructor, and option e should be incorrect.

Where am i going wrong in my logic ?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3817
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
N Sam wrote:Thanks for that response Jeanne. Here is another that i consider to be error in the OCA book. It is option e in sample exam question 3.10. (posted this at manning.com with no reply in 2 days).
This question asks to select incorrect options. Option e should have been one of the incorrect options for class below.


This class has a user defined constructor (even though it is an empty constructor, doing nothing). Once the user defines a constructor, the default constructor is NOT supplied (according to the author's own words in the book). So, the above class is NOT eligible for a default constructor, and option e should be incorrect.

Where am i going wrong in my logic ?

Although I am not aware of the full context of this question, please observe that the class you've quoted does not have a user defined constructor. Notice the return type void. That makes it a regular method, not a constructor.

HTH,
Paul.
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
N Sam wrote:



That's not a constructor, but a method with name same as a class name. As mentioned above: hint for you is "void" return type.

For sure, this is extremely bad to write in real work, but it was made for learning purposes to confuse you.

Bottom line: the class does not have a constructor and default one will be provided by compiler.

HTH,
MZ
 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran across a sentence in the OCA book that does not make sense to me. It could be wrong. So, I have posted it here:
www.coderanch.com/t/627890/java/java/Static-method-related#2873456

Please take a look, and reply in that thread. Thanks.
 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is another error in the book:

Page 369 has "Categories of exceptions" and here Errors are classified as one category of exceptions. Fast forward to page 401. There is a sentence for 'option C' on this page that reads "Error is NOT an exception". Although i understand what the author is trying to convey, this could have been reworded more appropriately.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic