Refactoring JavaElliotte Rusty HaroldJavapolisWednesday, November 13, 2002elharo@metalab.unc.eduhttp://www.cafeaulait.org/ |
Improve Legibility
Improve Maintainability
Increase Robustness
Make Code More Reusable
Clean up the mess inherent in most 1.0 systems
Changes that everyone would really like to make, but that are prevented primarily by concern for backwards compatibility
Not focusing on new features that could be added to the existing Java in a backwards compatible way.
Not interested in turning Java into a different language.
The goal is to do the same things better, while building a stronger foundation for future development.
Java 1.4.0 ships with:
22 deprecated classes
8 deprecated interfaces
50 deprecated fields
Over 300 deprecated methods!
Color.red
, Color.blue
, Color.green
, etc.
System.gc()
InetAddress
All types have classes
All variables are objects
+, -, *, etc. are predefined similarly to how + is defined now for String objects
Compiler is responsible for optimization
Non-overflowing integers?
Unicode currently defines over 90,000 characters with more on the way
Unicode is not a two-byte character set.
Eliminate ThreadGroups
Delete the unimplemented destroy() method
Make double and long operations atomic
Undeprecate stop(), suspend(), and resume() methods, but move them into a different class
Decouple monitors from objects?
Preferences Files
JAR Manifests
Object Serialization
Two GUI APIs is one too many.
Two event models is one too many.
Some classes are thread-safe (Hashtable, Vector). Some aren't (LinkedList, HashMap).
Some collections return null when a missing element is requested. Others throw an exception.
File system interfaces
Replace PrintStream with PrintWriter
readUTF() and writeUTF()
Encodings for Reader and Writer
Default Buffering
Replace integer constants with type-safe enums
Hide confusing and unnecessary classes like StringTokenizer and StreamTokenizer
Make Cloneable a true mixin interface or perhaps eliminate it completely
Rename the Math.log() method the Math.ln() method
True design by contract support
Make all exceptions runtime exceptions
Limit objects to a single thread