Java Reference
In-Depth Information
Assertions are an unusual feature of the Java language—under most circumstances they
cause absolutely nothing to happen. They're a means of expressing in a class the condi-
tions under which it is running correctly (and the things you assume to be true as it runs).
If you make liberal use of them in a class, it will either be more reliable, or you'll learn
that some of your assumptions are incorrect, which is useful knowledge in its own right.
Some Java programmers believe that because assertions can be
turned off at runtime, they're an unreliable means of improving the
reliability of a class.
CAUTION
Threads
One thing to consider in Java programming is how system resources are being used.
Graphics, complex mathematical computations, and other intensive tasks can take up a
lot of processor time.
This is especially true of programs that have a graphical user interface, which is a style
of software that you'll be learning about next week.
If you write a graphical Java program that is doing something that consumes a lot of the
computer's time, you might find that the program's graphical user interface responds
slowly—drop-down lists take a second or more to appear, button clicks are recognized
slowly, and so on.
To solve this problem, you can segregate the processor-hogging functions in a Java class
so that they run separately from the rest of the program.
This is possible through the use of a feature of the Java language called threads.
Threads are parts of a program set up to run on their own while the rest of the program
does something else. This also is called multitasking because the program can handle
more than one task simultaneously.
Threads are ideal for anything that takes up a lot of processing time and runs continu-
ously.
By putting the workload of the program into a thread, you are freeing up the rest of the
program to handle other things. You also make handling the program easier for the vir-
tual machine because all the intensive work is isolated into its own thread.
7
 
Search WWH ::




Custom Search