CONTENTS
Ebook banner rotater for Web Programming and Administration
Web Programming
with Java
by Michael Girdley,
Kathryn A. Jones, et al.
C O N T E N T S
Introduction
Chapter
1 An Overview Of Java
Introduction
A Brief History of Java
Applets
Java's Features
Simple
Object-Oriented
Robust
Interpreted
Secure
Architecture Neutral
High Performance
Dynamic
The Fundamentals of the Java Language
Java as an Object-Oriented Language
Classes
Hierarchy
Variables
Methods
Inheritance
Basic Coding Elements
Statements
Expressions
Blocks
Comments
Data Types
Operators
Declaring Variables
Flow of Execution
Conditionals
Loops
Arrays
Using Classes, Objects, and Interfaces
Creating Classes
Overloaded Methods
Static Methods and Variables
Constructors
Creating Objects
References
Class Inheritance
null, this, and super Variables
Encapsulation
Access Modifiers
Creating Interfaces
Packages
How Java Differs from C++
Summary
Chapter
2 Getting Started
Obtaining the Java SDK
The Java Development Environment
Your Text Editor
The Java Compiler
The Java Interpreter
The Java Debugger
The Java AppletViewer
Compiling with Java
javac/javac_g
java/java_g
jdb
AppletViewer
Summary
Chapter
3 An Introduction to Java Classes
Packages in Java
java.lang
Object
Wrappers for Basic Types
Strings in Java
Math
Cloning Objects: the Cloneable Interface
Threads of Execution
Exceptions and Errors
The Runtime Environment
Classes at Runtime
java.awt
Component
Container Components
Buttons and Other Components
Event Handling
Getting Painted
Menus
Layout Managers
Graphics and Images
Fonts
java.applet
Applet
java.awt.image
Color Models
Producing Images
Image Filters
java.awt.peer
java.io
Basic Streams
Filtered Streams
Data I/O
Using Files
StreamTokenizer
java.net
Addressing the Web: URLs
Content Handlers
Sockets and Internet Addresses
java.util
Dictionaries, Hashtables, and Properties
Stacks and Vectors
Counting Things: Enumerations
Observers and Observables
Other Utility Classes
Summary
Chapter
4 Creating Your Own Objects
Creating Objects from Java Classes
Declaring the Reference Variable
Creating the Object
Initializing the Object
Using the Object
Creating Your Own Classes
Writing the Class
Declaring the Member Variables
Creating the Methods
Using Instance Members versus Class Members
Creating the Constructors and the Finalize() Methods
Creating Interfaces
Using the Garbage Collector
Understanding Garbage Collection
Looking At the Garbage Collector's Effect on Performance
Summary
Chapter
5 Writing a Java Applet: The Order
Entry System
The Sample Applet: The Order Entry System
The Java AWT
The Organization of the Java AWT
supersimple AWT-Based Applet Example
Applets
Java Applets versus Java Applications
Applet Limitations
Read/Write Limitations
Connectivity Limitations
Native Library Access
Process Limitations
The Applet Life Cycle
The init() Method
The start() Method
The stop() Method
The destroy() Method
Adding Applets to Web Pages
Netscape Navigator and Applets
html Coding for Applets in Netscape
Parameters and Applets
Aligning the Applets
Displaying the supersimple Example Applet
Applets and HotJava
What's Been Done So Far
What's Coming Up
Chapter
6 The Order Entry System: Adding
Features and Handling Events
Graphical Components
Buttons
Checkboxes
Coordinated Checkboxes: Radio Buttons
Pop-Up Choice Lists
Scrolling Choice Lists
Scrollbars
Getting Started on the Order Entry System
What's Wrong with the Order Entry System?
Dealing with Events
The handleEvent() Method
Dealing with the action() Method
What's Going On in the EventExample Applet
The Steps in Creating Event-Based AWT Programs
Handling Events in the Order Entry System
The Order Entry System So Far
Chapter
7 The Order Entry System: Entry
Fields, Labels, and Validation
Text-Oriented Components
Labels
Text Fields
Events and Text Fields
Text Areas
Events and Text Areas
Adding These Concepts to the Order Entry System
The Order Entry System So Far
Data Validation
Summary
Chapter
8 The Order Entry System: Managing the Applet Layout
More About Containers
Panels
Frames
Dialogs
Dialog Example Applet
File Dialogs
Adding to the Order Entry System
Making the Order Entry System a Stand-Alone Window
Adding Pop-Up Dialogs to the Order Entry System
Layout Managers in the AWT
FlowLayout
BorderLayout
CardLayout
Fixing the Layout of the Order Entry System
Summary
Chapter
9 The Order Entry System: Adding
Graphics and a Logo
The AWT Graphics Class
The paint and update Methods
The repaint Method
Java Graphics Primitives
The drawString Method and Fonts
Defining Colors
Setting and Using Colors
Precision String Alignment
Drawing
Filling
AdrawingExample Applet
Displaying and Dealing with Images
Getting Images
Displaying Images
A Final Component: Canvases
Adding to the Order Entry System
Adding a Logo to the Order Entry System
Adding Graphical Dividers to the Order Entry System
Audio in the Applet Package
play
The Order Entry System So Far
Chapter
10 The Order Entry System: Exception
Handling and Browser Interaction
Error and Exception Handling
Implementing Exception and Error Handling
Using try and catch
Using finally
Throwing Exceptions
Using Throws
Declaring Your Own Exceptions
Using Exceptions in the Order Entry System
Interacting with the Browser
Looking at the Final Listing of the Order Entry System
What's Wrong with the Order Entry System?
Summary
Chapter
11 Reading and Writting with Java
The java.io Package
The Two Big Daddies
InputStream
OutputStream
So Many Streams in Java
The FileInputStream and FileOutputStream Classes
The ByteArrayInputStream and ByteArrayOutputStream Classes
FilterInputStream, FilterOutputStream, and Their Children
The DataInputStream and DataOutputStream Classes
The PipedInputStream and PipedOutputStream Classes
Dealing with Files
The File Class
Random Access Files
Summary
Chapter
12 Network Programming with Java
The Protocol Zoo
IP
UDP
TCP
DNS
World Wide Web
Sockets in Java
Stream Socket Classes
Datagram Sockets
A Chat Applet
The WWW in Java
The URL Class
The URLConnection Class
MIME Types and Content Handlers
The GET method
The POST Method
Summary
Chapter
13 General Purpose Classes
What's in This Chapter
Linked Lists, Queues, Search Trees, and Other Dynamic Data Structures
Using the Utilities Package
Enumeration
Observer
Classes
BitSet
Date
Random
StringTokenizer
Vector
Stack
Dictionary
Hashtable
Properties
Observable
Summary
Chapter
14 Extending Java
The Runtime and Process Classes
Executing External Programs Using Runtime
Monitoring Executed Applications Using Process
A Practical Example: DAOCmd
Extending Java Using Native Methods
Basic Mechanics of Creating Native Methods
Calling Java from Native Methods
Writing Well-Behaved Native Code
An Interface to Microsoft Data Access Objects (DAO)
Applets and Security Restrictions
Java Remote Method Invocation
Summary
Chapter
15 Developing Database Applications
and Applets with the JDBC
Why the Java Database Connectivity (JDBC) Specification?
Storing Data for the Web
Providing Access to Data
The JDBC API
Database Requirements
The JDBC Interfaces
Simple Database Access Using the JDBC Interfaces
The Counter Applet Example
Result Sets and the Meta-data Interfaces
Other JDBC Functionality
Transaction Management
Cursor Support
Stored Procedures
Multiple Result Sets
Building a JDBC Implementation
Implementing the Interfaces
Extending JDBC
Designing a Database Application
Security Issues
Constructing a Three-tier Application
A Three-tier Bug Tracking System
Implementing a Three-tier Application with Java
Summary
Chapter
16 Multithreading with Java
What Is a Thread?
The Thread Class
Simple Thread Examples
Problems with Multithreading
What Goes Wrong?
Thread Names and Current Threads
Java's synchronized
Synchronizing Threads
Multiple Locks
The Dining Philosophers Problem
Deadlocks
A Solution to the Dining Philosophers Problem
Java's wait() and notify()
Dining Philosophers Example
Summary
Chapter
17 Advanced Graphics: Multimedia
Introduction: The Information Age
The Internet Medium
Information Format
Rotator
The Subtleties of Update and Paint
Rotator on the Run
Omatrix and Solid Classes
Omatrix
Solid
Summary: The Bottom Line Is Bandwidth
Chapter
18 Serious Play: Game Applets
Computer Games
Net Games
Interface Design
The Game of CopyCat
Looking At Objects and Data Flow
Coordinating CopyCat and PlayArea
Dealing with Events
Interface and Communication
Summary
Chapter
19 Security Issues
The Java Language
The Java Compiler
The Java Interpreter
The Class Loader
The Bytecode Verifier
The Execution of Code
Java Virtual Machine
The Bytecode Instruction Set
The JVM Register Set
The Java Stack
The Garbage Collection Heap
The JVM Memory Areas
Limitations
Known Bugs
Future Java Security
Summary
Credits
To mom and dad, who support unconditionally, c.w. liew, kas, spalding, phil lesh, and the mailing list.
--Michael Girdley
To Thuy
--Brian Gloyer
|
Copyright © 1996 by Sams.net Publishing
FIRST EDITION
All rights reserved. No part of this book shall be reproduced,
stored in a retrieval system, or transmitted by any means, electronic,
mechanical, photocopying, recording, or otherwise, without written
permission from the publisher. No patent liability is assumed
with respect to the use of the information contained herein. Although
every precaution has been taken in the preparation of this book,
the publisher and author assume no responsibility for errors or
omissions. Neither is any liability assumed for damages resulting
from the use of the information contained herein. For information,
address Sams.net Publishing, 201 W. 103rd St., Indianapolis, IN
46290.
International Standard Book Number: 1-57521-113-0
html conversion by :
M/s. LeafWriters (India) Pvt. Ltd.
Website : http://leaf.stpn.soft.net
e-mail :
leafwriters@leaf.stpn.soft.net
Publisher and President: | Richard K. Swadley
|
Development Manager: | Dean Miller
|
Managing Editor: | Cindy Morrow
|
Director of Marketing: | John Pierce
|
Assistant Marketing Managers: | Kristina Perry, Rachel Wolfe
|
Acquisitions Editor | Grace M. Buechlein
| Development Editor | Brian-Kent Proffitt
|
Software Development Specialist |
Cari Skaggs | Production Editor
| Deborah Frisby |
Copy Editors | Miriam Bishop, Fran Blauw, Stacey Houston, Kristen Ivanetich, Howard Jones, Nanci Sears Perry
|
Indexer | Tim Griffin
| Technical Reviewer | Christopher Stone
|
Editorial Coordinator | Bill Whitmer
| Technical Edit Coordinator | Lynette Quinn
|
Editorial Assistants | Carol Ackerman, Andi Richter, Rhonda Tinch-Mize
| Cover Designer | Tim Amrhein
|
Book Designer | Alyssa Yesh
| Copy Writer | Peter Fuller
|
Production Team Supervisor | Brad Chinn
| | |
Production | Stephen Adams, Debra Bolhuis, Michael Brumitt, Kevin Cliburn, Jason Hand, Daniel Harris, Sonja Hart, Chris Livengood, Casey Price, Laura Robbins, Bobbi Satterfield, Mark
Walchle
|
All terms mentioned in this book that are known to be trademarks
or service marks have been appropriately capitalized. Sams.net
Publishing cannot attest to the accuracy of this information.
Use of a term in this book should not be regarded as affecting
the validity of any trademark or service mark. Java is a trademark
of Sun Microsystems, Inc.
Acknowledgments
A special acknowledgment goes to Lawrence Harris for his work
on the table of contents of this book. Thank you!
Thanks to Brian Proffitt and to the rest of the gang at Sams.net.
Most of all, thanks to Grace Buechlein, who called me on that
May afternoon to talk about this Java book. Everyone has been
very kind, and it is great to be involved with a team so committed
to producing quality products.
The other authors and contributors to this book also worked hard
to produce a high-quality, informative book. I was responsible
only for about a half of this book, but it was originally going
to be only a chapter or two. My portion just kept growing and
growing. This book, above all, was a team effort of authors and
editors, many of whom I've never met or spoken to. The efforts
from all sides to produce Web Programming with Java are
something I have a great deal of respect for, and I appreciate
all the work people did to make my 50 percent read well.
I would also like to thank Professor Liew for providing my first
introduction to the Java language, along with the rest of the
faculty at Lafayette, including Professor Bjorling-Sachs and Professor
Collins. Kelly Anne has also been great when I was unavailable
to run. My employers at Southwest Research Institute were also
great, even though I walked in some mornings so bleary-eyed from
late-night writing that I could barely stand. And to Mom and Dad
who bought that first Apple IIe fifteen Christmases ago. And to
everyone else, friends, family, grandparents: thank you.
- Michael Girdley
About the Authors
Michael Girdley is from San Antonio, Texas. He is currently
pursuing a Bachelor of Science in computer science at Lafayette
College in Easton, Pa. He is also the chief consultant at Allwilk
Consulting (http://www.allwilk.com/),
an organization specializing in Web site creation and Java programming.
He is a member of the Lafayette College varsity swimming team
and will earn his fourth varsity letter in 1996-1997. Michael
hopes to find a job or go to graduate school after possibly graduating
on time in May of 1997. He can be reached at girdleyj@allwilk.com
and on the Web at http://www.lafayette.edu/~girdleyj/.
Kathryn A. Jones is a senior technical specialist in the
New York office of Smith Barney, where she designs and develops
NT-based client/server systems.
Jim Morey is a graduate student in pure mathematics at
the University of British Columbia. He got his undergraduate degree
from University of Guelph, Ontario. He is a hacker in the sense
that he learns programming by hacking through other people's code.
Catching the Java bug early, he hacked his way through the alpha
version of Java and wrote "Pythagorus's Haven," a geometrical
proof of the Pythagorean Theorem. This program won the Grand Prize
in the Applet Programming Contest (http://java.sun.com/contest/results.html)
sponsored by Sun. And recently, he won first place in the individual
entertainment and games category in the Java Cup International
(http://javacontest.sun.com/winners_circle/index.html)
for CopyCat, a 3-D geometrical game. With all the computer equipment
he has won, Jim will be in hacker heaven for quite some time at
morey@math.ubc.ca or http://www.math.ubc.ca/~morey/.
Keith Orpen is a student of mathematics and coffee and
lives in Vancouver. He can be pestered at korpen@math.ubc.ca,
which is handy for sending him money and stuff. His favorite thing
in the world is to answer Java newbie questions for free, especially
if a ton of effort is involved.
Thomas Fredell is the consulting manager for the Atlanta
office of Brainstorm Technologies, a leading provider of Groupware
tools and consulting services. Thomas has the distinction of being
the first graduate with a degree in cognitive science from the
University of Virginia. His interests include software development
using C, C++, and Java, and he is interested in language design
and artificial intelligence. His noncomputer hobbies include skiing,
sailing, squash, and chess. He can be contacted via e-mail at
tfredell@braintech.com.
Brian Gloyer placed first in Sun's Java Applet Programming
Contest with his Dining Philosophers applet. He is currently pursuing
his Ph.D. at the University of California, Irvine. His research
interests include artificial neural networks, image processing,
and information systems. Some of his work, along with the original
Dining Philosophers applet, can be seen on his home page at http://www.eng.uci.
edu/~bgloyer.
Richard Lesh (rich@micros.umsl.edu)
is an instructor with the Microcomputing Program at the University
of Missouri, St. Louis. He has developed a variety of applications
for the Macintosh, IBM pc, and various UNIX platforms. A number
of software products that he has developed are in national distribution,
including PLANMaker, a business plan building product, and a number
of screen-saver modules published by Now Software in Now Fun!
and by Berkeley Systems in After Dark.
George Reece (borg@imaginary.com)
holds a philosophy degree from Bates College in Lewiston, Maine.
He works as a consultant with York and Associates, Inc., and as
a magazine columnist for the Java Developer's Journal. He has
written some of the most popular MUD software on the Internet,
include the Nightmlare Object Library and the Foundation Object
Library. For Java, he was the creator of the first JDBC implementation,
the Imaginary JDBC Implementation for mSQL. His Internet publications
include the free textbooks on the Lpc programming language,
Lpc Basics and Intermediate Lpc.
Tell Us What You Think!
As a reader, you are the most important critic of our books. We
value your opinion and want to know what we're doing right, what
we could do better, what areas you'd like to see us publish in,
and any other words of wisdom you're willing to pass our way.
You can help us make strong books that meet your needs and give
you the computer guidance you require.
Do you have access to CompuServe or the World Wide Web? Then check
out our CompuServe forum by typing GO
SAMS at any prompt. If you prefer the World
Wide Web, check out our site at http://www.mcp.com.
Note: |
If you have a technical question about this book, call the technical support line at
(800) 571-5840, ext. 3668.
|
As the team leader of the group that created this book, I welcome
your comments. You can fax, e-mail, or write me directly to let
me know what you did or didn't like about this book-as well as
what we can do to make our books stronger. Here's the information:
FAX: | 317/581-4669 |
E-mail: | opsys_mgr@sams.mcp.com
|
Mail: | Dean Miller
Sams Publishing
201 W. 103rd Street
Indianapolis, IN 46290
|
Introduction
by Michael Girdley
Today you went Web "surfing" (a silly name, in my opinion),
and you scoped out what's there. First you loaded up your favorite
site (maybe one you created) and checked it out. Seems like everything's
going fine-same white background, same images, nice logo-impressive,
to say the least. You make your way around and wander into some
home pages, possibly from a school somewhere or from one of the
multitude of Web space providers. You might see pages like the
one shown in Figure IN.1.
Figure IN.1. A page you might see.
Alternatively, you might visit one of the big commercial sites
like ESPNet's Sportszone. You keep seeing references to Java everywhere,
and you feel you're missing out.
So you search the Web for a Java-enhanced browser and eventually
find one. Then you're off. Another world opens to you. Suddenly,
the Web has started coming alive. You reach Gamelan (http://www.gamelan.com),
a compendium of links to Java resources, and an amazing number
of Java's wonders present themselves.
Or again, say you've seen all the hype (when it reaches Time
magazine, it's hype). Of course, you want to use Java in your
own pages, but how?
Web Programming with Java is your guidebook to creating,
designing, and using Java for and on the World Wide Web.
Who Should Buy This Book?
You might be one of the people who should buy this book if you
are excited and amazed by the extension that Java provides to
the World Wide Web (also called WWW or "the Web"). You
might have seen the amazing Java applets out on the Internet,
and you are interested in learning how to do it yourself. Perhaps
you've heard or seen the hype in magazines and periodicals, and
your curiosity is aroused. But you don't know how to make your
own Java programs (and you are not alone-I get many e-mails from
people who want to know how). You need a source that will function
both as a tutorial and as a reference for you to create your own
Java applets.
This book provides you the capability to make your Web pages and
sites come alive.
Besides serving as a tool to teach Java, this book will help programmers
who are already familiar with Java and who are interested in the
application of Java to the Web. This book covers Java completely,
with special attention paid to its application on the WWW.
The most basic thing that a user of this book should have is access
to a computer (pc or workstation) running on a Java-capable platform,
to which the Java compiler and interpreter have been ported. At
the time of this writing, many platforms are Java-capable. These
range from the Sun SPARC workstations to the Microsoft Windows
95 interface to Steve Job's NeXT. A complete OS/2 port has already
been completed and released by IBM, though many of the bugs are
still being worked out at present.
The version of Sun's Java Developer's Kit (JDK) included in the
CD-ROM that accompanies this book contains the full release of
the Java language (1.x) for many different platforms.
If your platform isn't supported on the version included with
this book, don't worry. Chapter 2, "Getting
Started," covers the where and the how of getting the Java
Developer's Kit.
Caution |
The JDK is currently not ported to run under Microsoft Windows 3.1. As such, this book and the programs included will not be useful for 3.1 users. The JDK does work under Windows 95. If you haven't looked into Windows 95, this may be one more reason to
consider it.
|
If you have access to an appropriate system, what next? Most importantly,
you should have an understanding of the major concepts of computer
programming and some programming experience. As you will discover
in this book, Java is an object-oriented language. Any previous
experience you have in object-oriented design (OOD) will be a
major bonus, though it is not necessary.
And finally, this is a book that concentrates on the use of Java
on the World Wide Web. There are a number of differences between
Java programming for the Web and for stand-alone Java programs.
You'll see in this book that the difference between these two
programming goals extends all the way to their names: stand-alone
Java programs are called applications, but Java programs designed
for the Web are called applets.
In conclusion, you should
Have a background in programming computers.
Have access to a computer capable of Java.
Be in the market to use Java on the World Wide Web.
What's in This Book?
This book covers the complete story of using Java on the Web.
It contains all the information necessary to implement and create
your very own Java applets and to effectively use all of the power
of Java language. Web Programming with Java begins with
an overview of the Java language and then deals progressively
with more powerful and detailed concepts. Here is a summary of
what each chapter contains.
Chapter 1, "An Overview of Java,"
is an overview of the Java language itself and some of the circumstances
which prompted Sun Microsystems to create it. You will learn the
why and how of Java as an object-oriented language.
This object-oriented nature, you will discover, is key to the
platform-independence of Java.
Chapter 2, "Getting Started,"
covers the major concepts you'll need to know to use Java on your
platform. In this chapter, you'll learn about where to get the
Java Developer's Kit and how to use it on your system. Finally,
you'll see how to compile your Java programs and then view them
using Sun's AppletViewer
utility.
In Chapter 3, "An Introduction to
Java Classes," you'll get a complete overview of what makes
a Java class. The multiple classes and packages of classes available
to you in the Java class library will all be covered. These include
packages such as the java.net
package, which enables network connections, and the java.awt
package, which enables you to easily create GUIs.
Rounding out Part I, in Chapter 4, "Creating
Your Own Objects," you'll get into creating your very own
classes. You will learn how to subclass Java classes and also
how to subclass your own classes. Finally, you will learn how
Java handles Garbage Collection, which frees up system resources
from where they are no longer needed.
Part II deals with the concept of building a complete Java applet.
One of the most appealing aspects of the Web today is the graphical
interaction between the user and source-the applet you create
will do just that. Chapter 5, "Writing
a Java Applet: The Order Entry System," begins Part II by
discussing the first applet you will be creating, the Order Entry
System. This chapter also describes exactly what applets entail
in Java, and why.
Coverage of the Abstract Windowing Toolkit (AWT) will begin, with
a description of the limits and capabilities of both applets and
it. The control path of applets (init(),
start(), etc.) will also
be covered. Finally, you will learn exactly how to put applets
into your Web pages.
Chapter 6, "The Order Entry System:
Adding Features and Handling Events," begins with an explanation
of the Java Abstract Windowing Toolkit, which is a package of
classes that facilitate the inclusion and use of the typical user
interface components, such as windows, pulldown menus, buttons,
and dialog boxes. You'll look into the use and description of
the AWT concepts of containers and components. Part of this chapter
will cover the implementation of some of the components. The graphical
components of the AWT will be covered in this chapter, while others
will be left for later chapters. This chapter also covers some
of the limitations of applets and compares them with Java applications.
Chapter 7, "The Order Entry System:
Entry Fields, Labels, and Validation," covers the remaining
components, including those specific to text input and output.
There are multiple components dealing with text, including Labels,
Text Fields, and Text Areas. The implementation and function of
each one of these components is detailed in this chapter. This
chapter also takes some more steps toward completing the Order
Entry System. You will extend the System to include the components
discussed in this chapter and to handle them appropriately. You
will also fill in some of the "holes," such as the unfinished
updateValues method, and
you will activate the "Clear" button. To finish Chapter 7,
you will learn the methods of password entry and identification,
which are very important in the applet design business. This same
section also covers data validation in the entry fields in applets.
Chapter 8, "The Order Entry
System: Managing the Applet Layout," is a monster. First,
you are going to further explore the concepts of containers in
the Java AWT. The chapter covers how to implement the different
container types and how they interact with each other. The different
containers available enable you to create stand-alone window applets,
and also enable you to clean up the appearance of the Order Entry
System. I will also describe pop-up dialog boxes and the means
to incorporate them into your applets.
Next, Chapter 8 covers the five different
AWT Layout Managers. These enable you, the programmer, to place
your components in containers in an orderly fashion, while still
maintaining platform independence. The five layout managers are:
Flow Layout, Border Layout, Card Layout, Grid Layout, and the
GridBag Layout. The GridBag Layout is the layout manager you will
use to reorganize the Order Entry System applet panel.
Chapter 9, "The Order Entry System:
Adding Graphics and a Logo," covers some of the most exciting
aspects of Java, those dealing with graphics. I will discuss the
AWT Graphics class, which
enables you to implement many different graphical items. These
features involve drawing, displaying images, and setting colors,
among others. I will discuss the Canvas
class, which is a special type of component designed for use in
dealing with graphics. The Order Entry System applet will also
be extended further to include the concepts dealt with in this
chapter.
Many languages do not have built-in capabilities to enable you
to efficiently detect and deal with errors, mishaps, and events
out of the ordinary. Luckily, Java includes a means to handle
these exceptions to the norm simply and effectively. You will
learn this process of handling exceptions
and errors. In other words,
although you plan on a certain progression through your code,
you will also plan to implement code that will cover the instances
where things don't go your way. The handling of exceptions and
errors, and the command structures to implement them, will be
the focus of this chapter.
Chapter 11, "Reading and Writing
with Java," covers the implementation of reading and writing
with Java. This process in Java is centered around the concept
of streams. Just as a stream of water flows in one direction,
starting and ending, so does a stream of data. Streams simply
are linear paths that connect a data producer and a data consumer
together to allow the serial (one chunk after another) transmission
of data. Streams can connect many different things. For example,
a stream can connect two independent processes together; they
can connect a class to a file or even connect your class to a
network. This chapter will cover in depth the usage of the multiple
types of streams available in the Java-standard libraries.
Chapter 12, "Network Programming
with Java," begins the third and final part of this book.
Where the first part introduced the Java language, and the second
part covered basic applet techniques, the chapters in this section
cover more complicated and powerful applet techniques. Chapter 12
covers network programming with Java. The examples in this chapter
rely extensively on the java.net
package in the Java class library in order to make, manage, and
utilize the network capabilities of Java. You'll learn how to
have your applets and applications in Java make connections across
LANs and the Internet. And most importantly, you'll learn the
process of connecting from your applet to your Web server. The
security limitations placed on applets will be discussed. You
will develop an on-line inquiry applet, which will demonstrate
these concepts.
Chapter 13, "General Purpose Classes,"
covers the different general purpose classes available in the
Java class library and demonstrates their use. Then, Chapter 14,
"Extending Java," covers extending Java to interface
with other languages, including C applications. Chapter 15,
"Interfacing with a Database: Catalog Applet," is about
interfacing with databases in Java. It covers the process of making
a network connection to a database and then creating an on-line
catalog applet.
Chapter 16, "Multithreading with
Java," covers one of the most important features of Java:
multithreading. It is a complicated topic, which will prove to
be one of the most important and powerful features of Java. Chapter 17,
"Advanced Graphics: Multimedia," covers multimedia in
Java applications. You'll learn how to create your own multimedia
applet.
Chapter 18, "Serious Play: Game Applets,"
covers game programming in Java. The process of creating game
elements will be discussed. You will learn about the implementation
of those elements into an example applet. Finally, Chapter 19,
"Security Issues," covers the future of Java and security
implementations of Java.
Conventions Used in This Book
This book uses the following conventions:
The lines of some listings are numbered. The numbers are only
for ease of reference. You do not type the line numbers into the
code.
New terms appear in italic.
All code appears in a monospace computer
font, as do filenames and directory names.
Placeholders in code appear in italic
monospace.
When a line of code is too long to fit on only one line of
this book, it is broken at a convenient place and continued to
the next line. The continuation of the line is preceded by a code
continuation character (Â).
The CD-ROM icon tells you that the file being discussed is
included on the CD-ROM that comes with this book.
Next
|