Troubleshooting

   

IndexOutOfBoundsException

I get a runtime error reporting an IndexOutOfBoundsException when I call a collection method.

Java provides automatic bounds checking for collections just as it does for arrays. This exception means you have passed in invalid index value to a List. Remember that an index must be greater than or equal to zero and strictly less than the number of elements in the list.

NullPointerException

I get a runtime error reporting a NullPointerException when I call a Map method.

Support for null key and value objects in a Map is optional. A Map implementation that does not allow null values in one or the other throws a NullPointerException if you attempt to insert one.

UnsupportedOperationException

I get a runtime error reporting an UnsupportedOperationException when I call a collection method.

The collections framework interfaces define a number of methods as optional, particularly those that modify a collection after it has first been created. A class that does not support an optional method throws an UnsupportedOperationException if it is called. The general-purpose implementations support all optional operations, but other implementations might not. If you require the functionality provided by an unsupported method, consider using a different implementation that is more complete.

JDK 1.1.x Use

I am restricted to a JDK 1.1.x runtime environment and cannot use the general-purpose collection classes.

JDK 1.1.x supports only the Vector, Stack, and Hashtable containers. You cannot use the general-purpose implementations in this environment.

Deprecated Method Warnings for Date

The compiler reports deprecation warnings when I use the methods of the Date class.

Most of the methods of Date are deprecated due to their inability to properly support internationalization. Most operations related to dates must be performed using the Calendar and DateFormat classes instead.

Thread Safety

I get errors resulting from simultaneous access to a collection by multiple threads.

A primary difference between the collections framework classes and the legacy classes is that the collections classes are not synchronized. If multiple threads have access to a collection, you must obtain a synchronized wrapper for it using the Collections class and then perform all access to the collection through that wrapper. You must also manually synchronize any iterations through the collection.

Poor Performance

The time required to add to, remove from, or search a collection is excessive.

The different collection classes offer different strengths and weaknesses when it comes to performance. Refer to the "Which Collection Class to Use?" section for an overview of these differences.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

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