may be used with the finally statement.
Syntax:
try
   statement(s)
catch(Exception list)
  statement(s)
finally
  statement(s)
Example:
InputStream in;
int val;
...
try
  val = in.read() / in.read();
catch(ArithmeticException e) {
    System.out.println("Invalid data.  val set to 0.");
    val = 0;
  }
catch(Exception e)
    System.out.println("Exception encountered, but not handled.");
finally {
    in.close();
    System.out.println("Stream closed.");

  }

while

This is used to perform a loop operation while a certain condition is met.

Syntax:
while (booleanVariable)
     statement(s)
while (booleanExpression)
     statement(s)
Example:
FileInputStream din;
byte info;

while (info = din.read() != -1) // End of File
     System.out.println(info);
while (stillValidData) {
     info = din.read();
     stillValidData = checkData(info);  // returns false if data is not valid
}



Chapter 16 -- Java Action Index

Chapter 16

Java Action Index


CONTENTS


This is a table for problem solving. Common questions are posed in the first column below, while the second column tells you what Java command will help you with the solution. The page numbers refer you to a detailed explanation for each entry.

Animation

QuestionSolution
How do I display my graphics? Graphics
How do I enable my applet to run on its own? Runnable
How do I begin the animation? Thread
Is there an animation example in this manual? Runnable
How do I reduce flickering? overrides the update().Applet method in the Applet class

Applets

QuestionSolution
How do I create an applet? Applet
How do I interact with the browser? AppletContext
How do I handle user interactions? Event
Which methods catch user interactions? Component

Applications

QuestionSolution
How do I display text on the screen? System.out
How do I start other programs on the client's side? Runtime
How do I handle files? File
How do I read from a file? FileInputStream
How do I write to a file? FileOutputStream

Communication

QuestionSolution
How do I display an URL? AppletContext.showDocument()
How do I handle URLs? URL
How do I load information from an URL? URLConnection
How do I communicate with a server? Socket
How do I create a TCP socket? ServerSocket
How can I continually communicate with a socket? Thread

Image Processing

QuestionSolution
How do I load an image in an applet? Applet.getImage()
How do I load an image in an application? Toolkit.getImage()
How do I manipulate an image? ImageFilter
How do I crop an image? CropImageFilter
How do I create an image from pixel data? MemoryImageSource

Input and Output

QuestionSolution
Is there a class that's like printf() in C? Printstream
Is there any easy way to parse streams? StreamTokenizer
How do I read doubles, strings, etc., from a stream? DataInputStream
How do I write doubles, strings, etc., to a stream? DataOutputStream
How do I link InputStreams together? SequenceInputStream
How do I interact with the environment (either the prompt of the Java console or a browser)? System

Math