Java Reference
In-Depth Information
QUICK SUMMARY
1. Code should contain lots of logging to enable users to figure out what it does, but
none of that should be enabled by default.
2. Don't forget to test for the logging level before calling the logger if the arguments
to the logger require method calls or object allocation.
Java Collections API
Java's collections API is quite extensive; there are at least 58 different collection classes sup-
plied by Java 7. Using an appropriate collection class—as well as using collection classes ap-
propriately—is an important performance consideration in writing an application.
The first rule in using a collection class is to use one suitable for the algorithmic needs of an
application. This advice is not specific to Java; it is essentially Data Structures 101. A
LinkedList is not suitable for searching; if access to a random piece of data is required,
store the collection in a HashMap . If the data needs to remain sorted, use a TreeMap rather
than attempting to sort the data in the application. Use an ArrayList if the data will be ac-
cessed by index, but not if data frequently needs to be inserted into the middle of the array.
And so on…the algorithmic choice of which collection class is crucial, but the choice in Java
isn't different than the choice in any other programming language.
There are, however, some idiosyncrasies to consider when using Java collections.
Synchronized Versus Unsynchronized
By default, virtually all Java collections are unsynchronized (the major exceptions being the
Hashtable , Vector , and their related classes).
Search WWH ::




Custom Search