Hi, In the section 6 of the exam objective for SCJP 5.0, one objective is: "Recognize the limitations of the non-generic Collections API and how to refactor code to use the generic versions." Can anybody help me out in what does the term "refactor" means and how code can be refactored? Thanks and Regards, Isha.
Here is how I comment on that topic in my new book on the JDK 1.5 exam
What does refactor mean? Refactor means to modify and improve existing code, but in such a way that it still includes its original functionality. Improving code implies that it is easier to understand and use. Refactoring is a big subject and modern development tools such as NetBeans and Eclipse include menu options entitled refactor. However refactoring generally means the programmer understands the issues behind the code that is being changed. Refactoring brings with it the obvious benefits of better code, but the danger of the introduction of new bugs. To be able to answer the questions that emphasise refactoring means you need to understand both the old versions of the Collections classes and the new Generic parameter versions.
Before GenericsGenerics are designed mainly for use with Collections, i.e. Classes that act as containers for instances of other classes. You need to be familiar with using and creating container classes for this section to make much sense. The standard Java Collections hold all elements as Object references. Because all classes are of type Object this means there is no checking for homogeneity (being of the same type).