Sams Teach Yourself Java 2 in 24 Hours

Sams Teach Yourself Java 2 in 24 Hours

By Rogers Cadenhead

Q&A

  1. Can a single Java program be both an applet and an application?

    It is possible to make a program serve as both applet and application, but it's often an unwieldy solution unless the program is simple. An applet could be set up to run as an application also by including a main() block in the applet, but you would not be able to use the init() block or paint() block in the automatic fashion they are used in an applet. Most programs are written as either an application or as an applet, rather than attempting to do both.

  2. Do all arguments sent to a Java application have to be strings?

    Java makes all arguments into strings for storage when an application runs. When you want to use one of these arguments as an integer or some other non-string type, you have to convert the value. You'll learn how to do this during Hour 11, "Describing What Your Object Is Like."

  3. I get errors when I try to load RootApplet.html into either Mozilla or Microsoft Internet Explorer. What's the problem?

    In most cases, the problem is that the browser isn't equipped to run Java 2 applets. Internet Explorer and Netscape Navigator have built-in support for Java 1.0, the first widely available version of the language, and partial support for Java 1.1. Sun offers a Java Plug-in that makes it possible for both leading browsers to support Java 2 applets, but it only works if the Web page containing the applet is equipped to work with the plug-in. When you're in doubt about why an applet won't work in a browser, try loading it with the appletviewer tool included with the Software Development Kit. If it works in appletviewer, the problem is with the browser rather than your Java applet.

  4. Why don't Java applets require the same kind of special access as gateway programs?

    Java applets don't have the same access requirements because they don't pose the same risk to a Web hosting provider. Gateway programs don't have much security in place to prevent the program from attempting to do harmful things to the machine presenting the Web page. Java applets, on the other hand, have strict restrictions to prevent them from being used to write harmful programs. Also, Java programs do not run on the Web site's machine—they run on the system of the person viewing the page. This means that the Web site's machine will not slow down due to numerous people running a Java applet on a page.

Share ThisShare This

Informit Network