Skill-Building Exercises


Summary

An applet is a Java program that can be embedded in a web page with an <applet> tag and run in a web browser. An applet extends the JApplet class and thus gains an enormous about of functionality. Applets have methods that make it easy to manipulate sound and image files.

Applets have four life-cycle stages: initialization, start, stop, and destroy. Each stage calls the corresponding lifecycle method: init(), start(), stop(), and destroy(). Applets do not have to implement all life-cycle methods.

The init() method functions much like a constructor and is where applet state initialization code is usually placed. An applet can also have constructor methods if required, one of which must be a no-argument constructor.

Place clean-up code in the destroy() method.

Applets run in a restricted environment and are considered to be untrusted code. Applets cannot, as a rule, access the local file system or initiate or receive network connections to any computer other than the one from which it was served.

Use <param> tags to embed applet parameters in HTML pages. Use the Applet class’s getParameter() method to fetch parameter values and use them in your program. Use wrapper classes as required to convert parameter value strings to primitive type values.

JDBC is an API that lets you access data sources from Java programs. The JDBC API comes in two packages: the java.sql package contains the JDBC core API and the javax.sql package contains the JDBC Optional Package API. The JDBC API consists mostly of interfaces which must be implemented by Java platform vendors. Database vendors must also supply JDBC driver classes to facilitate JDBC connectivity to their database products.

MySQL is a relational database server. Before connecting to a MySQL database with JDBC you must install it, create a database, create database tables, and establish the necessary database access permissions. MySQL access control is essentially managed with the use of five tables located in the mysql database: user, db, host, tables_priv, and columns_priv. To alleviate complexity, database security can be ignored in a learning environment, however, in a production environment it is a subject of which you must be keenly aware.

The general steps to employing JDBC include 1) loading the database vendor’s JDBC driver class using the class.forName() method, 2) using the DriverManager.getConnection() method to establish a connection to the database, 3) using the connection object to create a statement or prepared statement object, 4) using the statement or prepared statement objects to execute SQL statements against the database, and 5) manipulating the data contained in the returned resultset object if applicable.

Use JDBC Statements when dealing with simple queries. Otherwise use PreparedStatements for efficiency and ease of use.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net