Q&A -2 On Java Program


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

A
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 either as an application or as an applet, rather than attempting to do both.

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

A
Java puts 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 the coming hours.

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

A
Java applets don't have the same access requirements because they don't pose the same risk to a Web site provider. Gateway programs don't have any kind of security in place to prevent the program from attempting to do harmful things to the machine running 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.

Quiz

Test your knowledge of the material covered in this chapter by answering the following questions.

Questions

1. Which type of Java program can be run by the java interpreter tool?

(a)
Applets
(b) Applications
(c) none

2.
What special HTML tag is used to put a Java program onto a Web page?

(a)
<APPLET>
(b)
<PROGRAM>
(c)
<RUN>

3.
If you get into a fight with someone over the way to send information to a Java application, what are you doing?

(a)
Struggling over strings
(b) Arguing about arguments
(c) Feudin' on functionality

Answers

1. b. Applications are run with the interpreter tool, and Web pages containing applets can be run with the appletviewer tool as well as Java-capable World Wide Web browsers.

2.
a. The
<APPLET> tag is used along with the <PARAM> tag to send parameters to the applet.

3.
b. Can't we all get along?

Activities

If you'd like to apply your acumen of applets and applications, do the following activities:

·         Check out the Gamelan site at <http://www.gamelan.com> and use the search term Marquee to see links and descriptions to all of the applets that have been written to display text in a marquee sign format. Each of these applets use parameters to modify the text that is displayed.

·         Write a Java applet that can handle a parameter named X and a parameter named Y. Display the two numbers in a drawString() statement like the one in the RootApplet program.

 

 

 

 

Post a Comment

Previous Post Next Post