Java Reference
In-Depth Information
19
Java Never Ends
And thick and fast they came at last,
And more, and more, and more—
LEWIS CARROLL,
Through the Looking-Glass
Introduction
Of course there is only a finite amount of Java, but when you consider all the standard
libraries and other accompanying software, the amount of power and the amount to
learn seem to be endless. In this chapter we give you a brief introduction to four topics
to give you a flavor of some of the directions you can take in extending your knowl-
edge of Java. The four topics are multithreading, networking with stream sockets,
JavaBeans, and the interaction of Java with database systems.
Prerequisites
You really should cover most of the topic before covering this chapter. However, Sec-
tion 19.1 requires only Chapters 17 and 18 and their prerequisites. Section 19.2
requires Chapters 1 through 5, 9, and 10. Sections 19.3 and 19.4 require only Chap-
ters 1 through 6. Aside from references to Section 19.1 in Section 19.2, all sections are
independent of each other and may be read in any order.
19.1
Multithreading
“Can you do two things at once?”
“I have trouble doing one thing at once.”
Part of a job interview
thread
A
is a separate computation process. In Java, you can have programs with multi-
ple threads. You can think of the threads as computations that execute in parallel. On a
computer with enough processors, the threads might indeed execute in parallel. In most
normal computing situations, the threads do not really execute in parallel. Instead, the
computer switches resources between threads so that each thread in turn does a little bit
of computing. To the user this looks like the processes are executing in parallel.
You have already experienced threads. Modern operating systems allow you to run
more than one program at the same time. For example, rather than waiting for your
virus scanning program to finish its computation, you can go on to, say, read your e-
mail while the virus scanning program is still executing. The operating system is using
thread
Search WWH ::




Custom Search