In this appendix, you used classes ArrayList
and LinkedList
, which both implement the List
interface. You used several predefined methods for manipulating collections. Next, you learned how to use the Set
interface and class HashSet
to manipulate an unordered collection of unique values. We discussed the SortedSet
interface and class TreeSet
for manipulating a sorted collection of unique values. You then learned about Java’s interfaces and classes for manipulating key/value pairs—Map
, SortedMap
, HashMap
and TreeMap
. We discussed the Collections
class’s static
methods for obtaining unmodifiable and synchronized views of collections.
Next, we introduced fundamental concepts of file and stream processing and overviewed object serialization. Finally, we introduced multithreading. You learned that Java makes concurrency available to you through the language and APIs. You also learned that the JVM itself creates threads to run a program, and that it also can create threads to perform housekeeping tasks such as garbage collection. We presented the interface Runnable
, which is used to specify a task that can execute concurrently with other tasks. We showed how to use the Executor
interface to manage the execution of Runnable
objects via thread pools, which can reuse existing threads to eliminate the overhead of creating a new thread for each task and can improve performance by optimizing the number of threads to ensure that the processor stays busy. We discussed how to use a synchronized
block to coordinate access to shared data by multiple concurrent threads.
We discussed the fact that Swing GUIs are not thread safe, so all interactions with and modifications to the GUI must be performed in the event dispatch thread. We also discussed the problems associated with performing long-running calculations in the event dispatch thread. Then we showed how you can use the SwingWorker
class to perform longrunning calculations in worker threads and how to display the results of a SwingWorker
in a GUI when the calculation completed.