Java Reference
In-Depth Information
code. Therefore, any time you override equals in a class, you should also override
hashCode . In the Dog class, the following hashCode method maintains this required
relationship of equals and hashCode :
public int hashCode() {
return age;
}
If two Dog objects are equal in our example, they have the same age and therefore will
have the same hash code.
Summary
This chapter covered the “Fundamentals” objectives of the SCJP exam. Sun lists these
topics last in their offi cial list of objectives, but we needed to discuss these fundamentals
fi rst before tackling the more advanced topics of the exam.
The goal of this chapter was to discuss the details of running Java applications, including
working with packages and using an appropriate classpath. You should also have a good
understanding of garbage collection and when an object becomes eligible for garbage collection.
We also discussed the details of using the many operators in Java. As the title of the
chapter suggests, these topics are the “fundamentals” of Java that provide the building
blocks for the remainder of this topic.
Be sure to test your knowledge of these fundamentals by answering the Review Questions
that follow. I tried to write questions that refl ect the style and diffi culty level of questions
on the SCJP exam, so attempt to answer the questions seriously without looking back at the
pages of this chapter and do your best. Make sure you have a good understanding of the
following Exam Essentials before attempting the Review Questions, and good luck!
Exam Essentials
Understand the effect of putting a class in a package. In the real world, all classes are
declared within a package. Know how to run a Java class from a command prompt when
the class is in a package, and be sure to recognize what the CLASSPATH environment variable
needs to be.
Get comfortable with looking at code and determining its output. Many of the exam
questions provide either a small program or a snippet of code and ask what the output is.
Practice reading code and determining what it does, including whether or not the given
code compiles successfully.
Search WWH ::




Custom Search