The followings are random thoughts on some of the key Java data structures and their importance.
Primitive Types
What are the sizes of byte, short, int, long, float, double, boolean and char? int can be either 32 bits or 64 bits. char is 16 bits (to support UTF-16 encoding of Unicode code points).
Encoding
EBCDIC (mainly on mainframes) has different encoding scheme comparing to ASCII (UNIX, PC, etc). When you FTP a file from a EBCDIC machine to a ASCII machine, an explicit conversion will happen automatically.
Byte ordering
Byte ordering can be either big Endian or little Endian. If you migrate an application to a different processor family (e.g. from SPARC to x86) and the application code has logic that depends on byte locations, transformation is needed. If you store numbers in binary format (e.g. with 4 bytes int) or ASCII characters as Unicode code points in a file and transfer the file to a machine with different byte ordering, transformation is needed again.
String
String and StringBuffer. StringBuffer should be used if the value of the string could change.
Collections Framework
There are 3 major interfaces in the Collections framework. List, Map, Set. There are specific implementations for each of the 3 major interfaces. For example, there are HashSet, TreeSet and LinkedListSet implementations for the Set interface.
All the implementations in the Collections framework are designed to be unsynchronized for performance reason. However, we can use synchronization wrappers to return a synchronized (thread-safe) version of each collection implementation. You can also refer to the external link in my comment for an interesting article on how JVMs do synchronization optimization.
Vector and Hashtable
These are legacy implementations that are synchronized. ArraryList and HashMap are the corresponding unsynchronized versions of Vector and Hashtable.
Hashcode() and equal()
The default implementation uses the address of each key to do the hashing and testing for equality. If performance is important, a custom implemenation can be evaluated.
Wednesday, May 20, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment