Java Developer's Reference
J A V A
DEVELOPER'S REFEREncE
by Mike Cohn
Bryan Morgan
Michael Morrison
Michael T. Nygard
Dan Joshi
Tom Trinko
C O N T E N T S
PART I The Java Development System
Chapter 1 Introduction to Java
Chapter 2 Installing Java
- Getting Started with the Java Developer's Kit
- JDK Installation Notes
- Testing the Installation
- Exploring the Java Developer's Kit
- Distributing the Java Virtual Machine
- Other Development Environments
- Summary
Chapter 3 The Java Language
- Comments
- Java Keywords
- Primitive Types
- Literals
- Arrays
- Operators
- Controlling Your Program
- Java Classes
- Class Inheritance
- Summary
Chapter 4 Java for C++ Programmers
Chapter 5 Java for Delphi Programmers
Chapter 6 Java for Visual Baisc Programmers
- Visual Basic versus Java, or Object-Based versus Object-Oriented
- Comparing ActiveX to Java Classes
- Understanding Java Program Flow
- Language Features and Syntax
- Summary
Chapter 7 Developing Java Applets
- What Is an Applet?
- What Is Required to Run an Applet?
- Capabilities and Limitations of Applets
- Building a Java Applet
- HTML and Java Applets
- Simple Graphics and GUI Techniques
- Inter-Applet Communication
- Summary
Chapter 8 Developing Java Applications
Chapter 9 javac : The Java Compiler
Chapter 10 java : The Java Interpreter
Chapter 11 Using the Applet Viewer
Chapter 12 HTML for Java Programmers
- Welcome to the Internet
- What Exactly Is HTML?
- Diving into the HTML Format
- Java and HTML: The Basics
- Starting the Document: The <HTML> Tag
- Setting Up the Title: The <HEAD> and the <TITLE> Tags
- The <APPLET> Tag in Detail
- HTML Document Creation
- Summary
Chapter 13 HotJava and Other Java-Enabled Browsers
- The HotJava 1.0 Browser
- The Netscape Navigator 2.0 Browser
- Microsoft's Internet Explorer 3.0
- Summary
Chapter 14 Using javah
Chapter 15 jdb: The Java Debugger
Chapter 16 Using JavaDoc to Document Your Program
- Overview
- Running JavaDoc
- Adding JavaDoc Comments
- Enhancing Your Documentation with HTML
- An Example
- Summary
|
Chapter 17 Programming the User Interface
- Introduction and Basic Concepts
- Platform Independence: Gone Today, Here Tomorrow
- Abstract Window Toolkit (AWT)
- Drawing
- Interactive Interface Elements
- Organizing Your Interface with Layouts
- Images
- Windows
- Frames
- Dialog
- FileDialog
- Working with Applications
- Applet Methods of Interest
- Extending the AWT
- Summary
Chapter 18 Writing Secure Programs
- A Bit of History
- Java Security Issues
- The Differing Security Aspects of Applets and Applications
- Applets
- The Java Security Model
- The Future
- Summary
Chapter 19 Extending Your Programs with Native Methods
- An Overview of Native Methods
- Who Am I? A Java Class to Identify the User
- The Nuts and Bolts of Native Methods
- The Method and the Function
- Arguments and Return Values
- Using Java Objects from Native Methods
- Multithreading and Native Methods
- Native Methods and Exceptions
- Using Java Strings from Native Methods
- Summary
Chapter 20 Working with Threads
- Thread Basics
- The Thread Classes
- Creating Threads
- Scheduling and Thread Priority
- Daemons
- Grouping Threads
- Thread States
- New
- Runnable
- Not Running
- Dead
- Synchronization
- Summary
Chapter 21 Event Handling
Chapter 22 Exception Handling
- What Is Exception Handling?
- Why Is Exception Handling Important?
- Types of Exceptions
- Throwing Exceptions
- Catching Normal Exceptions
- Catching Runtime Exceptions
- Forced Execution
- When to Use Exception Handling
- Summary
Chapter 23 Using Observers
- Introduction
- A Simple Example: The SlideValue Applet
- Flexible Object-Oriented Design
- Observer as a Design PatternIK
- The Model-View-Controller Paradigm
- The AppletCAD Applet
- Other Applications of Observer
- Summary
Chapter 24 Using the Provided Data Structures
Chapter 25 Working with Databases
Chapter 26 Network-Aware Programming
- The Server Discussion
- The Server Workshop
- The Client Discussion
- The Client Workshop
- Inter-Applet Communication
- The First Applet
- The Second Applet
- Applet Communication with the Browser
- Java Communication with the Internet Using URLConnection
- Summary
|
Chapter 27 Package java.applet
Chapter 28 Package java.awt
- BorderLayout
- Button
- Canvas
- CardLayout
- Checkbox
- CheckboxGroup
- CheckboxMenuItem
- Choice
- Color
- Component
- Container
- Dialog
- Dimension
- Event
- FileDialog
- FlowLayout
- Font
- FontMetrics
- Frame
- Graphics
- GridBagConstraints
- GridBagLayout
- GridLayout
- Image
Chapter 29 Packages java.awt image
- ColorModel
- CropImageFilter
- DirectColorModel
- FilteredImageSource
- ImageFilter
- IndexColorModel
- MemoryImageSource
- PixelGrabber
- RGBImageFilter
- ImageConsumer
- ImageObserver
- ImageProducer
Chapter 30 Package java.awt.peer
- ButtonPeer
- CanvasPeer
- CheckboxMenuItemPeer
- CheckboxPeer
- ChoicePeer
- ComponentPeer
- ContainerPeer
- DialogPeer
- FileDialogPeer
- FramePeer
- LabelPeer
- ListPeer
- MenuBarPeer
- MenuComponentPeer
- MenuItemPeer
- MenuPeer
- PanelPeer
- ScrollbarPeer
- TextAreaPeer
- TextComponentPeer
- TextFieldPeer
- WindowPeer
Chapter 31 Package java.io
- DataInput
- DataOutput
- BufferedInputStream
- BufferedOutputStream
- ByteArrayInputStream
- ByteArrayOutputStream
- DataInputStream
- DataOutputStream
- File
- FileDescriptor
- FileInputStream
- FileOutputStream
- FilterInputStream
- FilterOutputStream
- InputStream
- LineNumberInputStream
- OutputStream
- PipedInputStream
- PipedOutputStream
- PrintStream
- PushbackInputStream
- RandomAccessFile
- SequenceInputStream
- StreamTokenizer
- StringBufferInputStream
- EOFException
- FileNotFoundException
- IOException
- InterruptedIOException
- UTFDataFormatException
Chapter 32 Package java.lang
- Cloneable
- Runnable
- Boolean
- Character
- Class
- ClassLoader
- Compiler
- Double
- Float
- Integer
- Long
- Math
- Number
- Object
- Process
- Runtime
- SecurityManager
- String
- StringBuffer
- System
- Thread
Chapter 33 Package java.net
- ContentHandler
- DatagramPacket
- DatagramSocket
- InetAddress
- ServerSocket
- Socket
- SocketImpl
- URL
- URLConnection
- URLEncoder
- URLStreamHandler
- MalformedURLException
- ProtocolException
- SocketException
- UnknownHostException
- UnknownServiceException
- ContentHandlerFactory
- SocketImplFactory
- URLStreamHandlerFactory
Chapter 34 Package java.util
- BitSet
- Date
- Dictionary
- Enumeration
- Hashtable
- Observable
- Observer
- Properties
- Random
- Stack
- StringTokenizer
- Vector
- EmptyStackException
- NoSuchElementException
Chapter 35 Package sun.tools.debug
- RemoteArray
- RemoteBoolean
- RemoteByte
- RemoteChar
- RemoteClass
- RemoteDebugger
- RemoteDouble
- RemoteField
- RemoteFloat
- RemoteInt
- RemoteLong
- RemoteObject
- RemoteShort
- RemoteStackFrame
- RemoteStackVariable
- RemoteString
- RemoteThread
- RemoteThreadGroup
- RemoteValue
- StackFrame
- DebuggerCallback
- NoSessionException
- NoSuchFieldException
- NoSuchLineNumberException
Credits
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-129-7
HTML conversion by :
M/s. LeafWriters (India) Pvt. Ltd.
Website : http://leaf.stpn.soft.net
e-mail :
leafwriters@leaf.stpn.soft.net
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.
| President, Sams Publishing | Richard K. Swadley |
| Publishing Team Leader | Greg Wiegand |
| Managing Editor | Cindy Morrow |
| Director of Marketing | John Pierce |
| Assistant Markerting Managers | Kristina Perry, Rachel Wolfe |
| Acquisitions Editor | Christopher Denny | Development Editor | Anthony Amico |
| Software Development Specialist | Brad Myers | Senior Editor | Kristi Hart |
| Production Editor | Bart Reed | ||
| Copy Editors | Margaret Berson, Fran Blauw, Lisa Lord, Marla Reece, Kris Simmons | ||
| Indexer | Tom Dinse | Technical Reviewer | Karen Clere, Vincent Mayfield |
| Editorial Coordinator | Bill Whitmer | Technical Edit Coordinator | Lynette Quinn |
| Resource Coordinator | Deborah Frisby | ||
| Editorial Assistants | Carol Ackerman, Andi Richter, Rhonda Tinch-Mize | ||
| Cover Designer | Jay Corpus | Book Designer | Alyssa Yesh |
| Copy Writer | Peter Fuller | Production Team Supervisor | Brad Chinn |
| Production | Charlotte Clapp, Jeanne Clark, Merry Dankanich, Mike Dietsch, Mike Henry, Tim Osborn, Shawn Ring, M. Anne Sipahimalani, Becky Stutzman | ||
Acknowledgments
A book of this size is clearly a team effort. We would like to thank Chris Denny, our acquisitions editor, for getting the ball rolling. Thanks also to Tony Amico, our development editor, who, once the ball was rolling, made sure we all rolled in the same direction. Thanks also to Vincent Mayfield and Karen Clere, our technical editors, who had the difficult job of making sure that what we wrote remained accurate as the Java language continued to evolve.
Much of what we've written would be less useful without the work of Alyssa Yesh, who designed the icons used throughout the book. Similarly, our thanks go to Brad Myers, who converted the reference section into HTML files for inclusion on the CD. Fittingly, these two have helped make this book more than the sum of its words.
Finally, special thanks to Bart Reed, our production editor, who pulled everything together and who taught us why "production editor" starts with "prod."
Special Thanks from Mike Cohn:
I would like to thank Jim Kearns and Jim Steeb of Access Health for their encouragement and for providing a cutting edge environment that needs products like Java. Thanks also to the two teachers who taught me how to write-John Dale, formerly of Rancho Alamitos High School, and my mother, Carlene. Special thanks to my daughter, Savannah, for just being who you are. Finally, nothing would be possible without the love and encouragement I receive from my wife, Laura. I love you. Thanks for being my kid's mom.
Special Thanks from Michael Morrison:
I'd like to thank my faithful and now legal accomplice, Mahsheed, for all your love and support.
Special Thanks from Tom Trinko:
Special thanks to the good Lord for all His blessings, especially my wife Colleen and the kids-Kate, Peter, Ted, Mary, and Therese.
About the Authors
Mike Cohn is the Director of Information Technology at Access Health, Inc., the leading provider of personal health management. Before that he was with Andersen Consulting and the Adler Consulting Group in New York. He holds a Masters degree in Computer Science from the University of Idaho and has been programming for 16 years. Mike lives in Cameron Park, California with his wife, Laura, and their daughter, Savannah.
Bryan Morgan is a software engineer with TASC, Inc. in Fort Walton Beach, Florida. He holds a B.S. in Electrical Engineering from Clemson University and is currently using Java to build Web applications as well as to perform Web-based distributed interactive simulations. Bryan and his wife, Becky, are expecting their first child in November 1996. Bryan is the co-author of Teach Yourself SQL in 14 Days and Teach Yourself ODBC in 21 Days for Sams Publishing.
Michael Morrison is the author of Teach Yourself Internet Game Programming with Java in 21 Days, co-author of Windows 95 Game Developer's Guide, Using the Game SDK, and is a contributing author of Tricks of the Java Programming Gurus and Java Unleashed.
Michael Nygard received his B.S. from the California Institute of Technology in 1994. He is currently employed by TASC, Inc. in Fort Walton Beach, Florida, where he is a Member of Technical Staff in the Simulation Technologies Department. Michael investigates leading-edge technologies and is currently focusing on Java, Delphi, and Windows NT.
Dan Joshi is a professional developer working for several Fortune 100 companies. He currently owns his own Internet-based consulting company, The Joshi Group. Dan is also a co-author of Teach Yourself Java in Cafe in 21 Days.
Tom Trinko, Mad Scientist. Born human. Unclear if he's stayed same. Worked on just about every type of computer since 1972. Expert on the world's only user-friendly computers, the Macintosh and Newton, with a couple of books on Mac scripting on his resume. When coherent, he can be reached at trinkos@aol.com, 72147,3723 on CompuServe, or via his Web page at http://members.aol.com/trinkos/basepage.html, which features some nice (in his unbiased opinion) Java stuff, including a cellular automata engine.
Tell Us What You Think!
As a reader, you are the most important critic and commentator 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: | programming_mgr@sams.mcp.com |
| Mail: | Greg Wiegand
Comments Department Sams Publishing 201 W. 103rd Street Indianapolis, IN 46290 |
Conventions Used in This Book
This book uses the following conventions:
- New terms appear in italic.
- Placeholders (words that stand for what you actually type) in regular text appear in italic.
- All code appears in monospace, 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 ( ). You should type a line of code that has this character as one long line without breaking it.
- An ellipsis (...) indicates that the remaining or intervening code required to complete a statement or code structure has been omitted for the sake of brevity.

