Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming

Self-Test Questions

1. 

How is an applet different from an application?

2. 

List at least four applet security restrictions.

3. 

List and briefly discuss the four applet life-cycle states and their associated applet life-cycle methods.

4. 

(True/False) An applet can initiate network connections to, and accept incoming network connections from, any computer on the network.

5. 

List and describe the purpose of each <applet> tag attribute.

6. 

How can information be passed to an applet from an HTML page?

7. 

List and briefly discuss the general steps required to create a database in MySQL.

8. 

List and briefly discuss the steps required to utilize JDBC in a program.

9. 

What two packages contain the JDBC classes and interfaces?

10. 

Describe at least one benefit derived from using applets vs. applications.

11. 

What type of constructor can an applet have?

12. 

What additional code must be written before you can run an applet?

13. 

What’s the difference between JDBC Statements and PreparedStatements?

14. 

What character is used as a variable placeholder in a PreparedStatement?

15. 

Describe a scenario where you would choose to use a PreparedStatement vs. a Statement.

Answers

1. 

- an applet can be run in a browser

2. 

  • They cannot listen on network ports less than or equal to 1024

  • They cannot register or create a URLStreamHandlerFactory, ContentHandlerFactory, or SocketImplFactory

  • They cannot call System.exit() or Runtime.exit()

  • They cannot call Runtime.exec() methods

  • They cannot dynamically load library modules using the System or Runtime classes’ load() or loadLibrary() methods

  • Swing windows created by applets have a warning at the bottom

  • They can’t print, access the clipboard, or access the system event queue

  • They have restricted access to certain system properties

  • They cannot create or access external threads or thread groups

  • They are limited in their ability to load classes

  • They are limited in their ability to use reflection

3. 

- initialized, started, stopped, destroyed

4. 

- false

5. 

<applet code = applet_class_name width = width_in_pixels height = height_in_pixels [archive = jar_file_name, [jar_file_name],...] [codebase = base_applet_uri] [object = serialized_applet] [alt = alternative_text] [name = applet_name] [align = applet_alignment] [vspace = vertical_margin_space_in_pixels] [ hspace = horizontal_margin_space_in_pixels] > [<param name = parameter_name value = parameter_value>] ... [alternative_text] </applet>

6. 

- via applet parameters

7. 

- create the database, create one or more tables, define columns for each table and relationships between each table, and establish permissions on the database to the required granularity using the MySQL permissions tables.

8. 

  • A database that’s been properly configured (i.e., tables, relationships, access rights, etc.)

  • A suitable database JDBC driver class (provided by the database vendor)

  • Knowledge of relational database design (if you are accessing a relational database)

  • Knowledge of the database schema you are going to access

  • Knowledge of SQL

  • A Java program that uses the JDBC API to connect to the database

9. 

- java.sql, javax.sql

10. 

- easier to distribute than an application

11. 

- a no-argument constructor

12. 

- an HTML page that references the applet code

13. 

- PreparedStatements are created ahead of time with variable placeholders. PreparedStatements are also precompiled.

14. 

- ?

15. 

- When you are repeatedly executing the same statement with different variable values

Категории