Certification Summary


We began with a quick review of the tostring() method. The tostring() method is automatically called when you ask System.out.println() to print an object—you override it to return a String of meaningful data about your objects.

Next we reviewed the purpose of == (to see if two reference variables refer to the same object) and the equals() method (to see if two objects are meaningfully equivalent). You learned the downside of not overriding equals()—you may not be able to find the object in a collection. We discussed a little bit about how to write a good equals() method—don't forget to use instanceof and refer to the object's significant attributes. We reviewed the contracts for overriding equals() and hashcode(). We learned about the theory behind hashcodes, the difference between legal, appropriate, and efficient hashcoding. We also saw that even though wildly inefficient, it's legal for a hashcode() method to always return the same value.

Next we turned to collections, where we learned about Lists, Sets, and Maps, and the difference between ordered and sorted collections. We learned the key attributes of the common collection classes, and when to use which.

We covered the ins and outs of the Collections and Arrays classes: how to sort, and how to search. We learned about converting arrays to Lists and back again.

Finally we tackled generics. Generics let you enforce compile-time type-safety on collections or other classes. Generics help assure you that when you get an item from a collection it will be of the type you expect, with no casting required. You can mix legacy code with generics code, but this can cause exceptions. The rules for polymorphism change when you use generics, although by using wildcards you can still create polymorphic collections. Some generics declarations allow reading of a collection, but allow no updating of the collection.

All in all, one fascinating chapter.




SCJP Sun Certified Programmer for Java 5 Study Guide Exam 310-055
SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055) (Certification Press)
ISBN: 0072253606
EAN: 2147483647
Year: 2006
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net