Sams Teach Yourself Java 2 in 24 Hours

Sams Teach Yourself Java 2 in 24 Hours

By Rogers Cadenhead

Q&A

  1. Why isn't javax.swing.JApplet needed in the class statement of the Revolve applet?

    It isn't needed because of the import statement that makes all the javax.awt.swing classes available to the program. The only purpose of import is to make it easier to refer to classes in a program. If you don't use it, you have to use full class references such as javax.swing.JApplet instead of simply JApplet. You could write all of your Java programs without using import, though it would make the source files more difficult to understand.

  2. If the Revolve applet only has one thread, what's the point of using threads at all?

    Multithreading has benefits, even if it's really just one-threading. One of the main benefits is that you can start, stop, and pause a thread from within a program; you don't have the same kind of control without threads. Also, by making an applet a thread, even for a single-thread project, you make it easier to implement additional threads as needed later on.

  3. Are there any reasons not to leave a pair of empty brackets after a catch statement, which causes errors to be disregarded?

    It depends on the type of error or exception being caught. In the Revolve applet, you know with both catch statements what the cause of an exception would be. Because of this knowledge, you can handle the error. In the getURL() method, the MalformedURLException would only be caused if the URL sent to the method is invalid.

Share ThisShare This

Informit Network