This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Bunkhouse Porch and the fly likes Java 2 Programmer Exam Cram book errata Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Books » Bunkhouse Porch
Bookmark "Java 2 Programmer Exam Cram book errata" Watch "Java 2 Programmer Exam Cram book errata" New topic
Author

Java 2 Programmer Exam Cram book errata

Ken Hanks
Greenhorn

Joined: Mar 04, 2006
Posts: 4
Mr. Brogen, in Chapter 3, test question 10 -- I have a real problem with your answer on that one. You've implicitly cast a Long object to an Object. Everything I've read says that when you do this, you only have access to the methods in the item on the left, the "larger domain". The Object domain implements "equals" as a simple "=="; it checks to see if two objects are "the same", NOT if they have the same contents. Since you didn't state that there was an overridden implementation of 'equals' in the Long object, I have to assume it uses the one in Object. Therefore the statement at line 5 ( if (A.equals(L)) would yield false and your answer is wrong. Please let me know your thinking on this. I hope that the answer does not indicate that I'm supposed to know the implementation of every class in the API by heart, including Long.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

You do need to know something about the "core Java APIs," which certainly includes all the wrapper classes like Byte, Short, Character, Integer, Float, Double,Boolean, and Long, and other fundamental classes like String and StringBuffer. It's enough to know that equals() is implemented sensibly for all of these classes.

You also need to understand -- and from your question, I don't know if you do or not -- polymorphism. A cast might change what the compiler can see, but it never changes what happens at runtime. If Long has its own equals(), then this is used even if the compile-time type of a reference is Object.


[Jess in Action][AskingGoodQuestions]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Since you didn't state that there was an overridden implementation of 'equals' in the Long object,

Very true, I didn't state that. You should be sufficiently familiar with the classes in java.lang which correspond to the Java primitives to realize that they implement their own equals methods. Since these objects hold primitive values, it would be absurd to have it any other way.
The operation of equals() in the various java.lang core classes frequently comes up in the real world and in the exam.
You should read the JavaDocs for java.lang.Object, paying particular attention to the equals and hashCode methods.

Bill
Ken Hanks
Greenhorn

Joined: Mar 04, 2006
Posts: 4
Thanks, Ernest and Bill, for your answers and information. Sometimes, late at night, I lose common sense. I've since worked out a lot of examples in JBuilder and it's all making a lot more sense now. Thanks again!
 
Consider Paul's rocket mass heater.
 
subject: Java 2 Programmer Exam Cram book errata