`
`JAVA Developer’s Guide
`
`JAVA Developer’s Guide
`by Jamie Jaworski
`
`C O N T E N T S
`
`Introduction
`
`Chapter1
`The Java Phenomenon
`• What Is Java?
`• The Origins of Java
`• Why Program in Java?
`• Java and HotJava
`• Summary
`Java Overview
`Chapter2
`• Getting the JDK
`• A Quick Tour of the JDK
`• The Java Language
`Java Is Familiar and Simple
`Java Is Object-Oriented
`Java Is Safer and More Reliable
`Java Is Secure
`Java Is Multithreaded
`Java Is Interpreted and Portable
`Java Is the Programming Language of the Web
`• The Java API
`• Summary
`Chapter3
`• Overview
`• The Compiler
`¤ Using Classes from Other Packages
`Setting CLASSPATH
`¤ Changing the Root Directory
`¤ Generating Debugging Tables
`¤ Code Optimization
`Suppressing Warnings
`¤ Using Verbose Mode
`• The Interpreter
`¤ Changing CLASSPATH
`¤ Checking for Source Code Changes
`¤ Verifying Your Code
`¤ Controlling the Garbage Collector
`¤ Changing Properties
`Setting Memory and Stack Limits
`¤ Debugging Options
`• The Debugger
`• The Disassembler
`• The Applet Viewer
`• Automating Software Documentation
`• Header File Generation
`
`Using the Java Developer’s Kit
`
`JAVA Developer’s Guide
`
`1
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 1
`
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`First Programs: Hello World! to
`
`• Running the Demo Programs
`• Summary
`Chapter 4
`BlackJack
`• Hello World!
`¤ Comments
`Java Program Structure
`¤ The package Statement
`¤ The import Statement
`¤ Classes and Methods
`¤ The System Class
`• I Can Read!
`¤ Overview of ICanReadApp
`¤ Declaring Variables and Creating Objects
`Identifiers and Keywords
`¤ Using System.in
`• Type This!
`¤ Overview of TypeThisApp
`¤ The Primitive Java Data Types
`¤ Literal Values
`• BlackJack
`¤ Overview of BlackJackApp
`¤ Arrays
`Statements
`• Summary
`Classes and Objects
`Chapter 5
`• Object-Oriented Programming Concepts
`It’s an Object-Oriented World
`¤ Composition and Reuse
`¤ Classes
`¤ Classification and Inheritance
`¤ Multiple Inheritance
`¤ Messages, Methods, and Object Interaction
`¤ Encapsulation
`Polymorphism
`¤ Dynamic Binding
`• Java Classes
`¤ Class Syntax
`¤ The Point Class
`¤ Class Modifiers
`¤ Extending Superclasses
`¤ Adding Body to Classes
`¤ The CGrid Class
`¤ The CGObject Class
`¤ The PrintCGrid Class
`¤ The BorderedPrintCGrid Class
`¤ The CGPoint Class
`¤ The CGBox Class
`¤ The CGText Class
`¤ The KeyboardInput Class
`¤ The CDrawApp Program
`¤ Running CDrawApp
`¤ CDrawApp’s Implementation of Object-Oriented Concepts
`• Summary
`Chapter 6
`Interfaces
`• The Purpose of Java Interfaces
`• The Benefits of Interfaces
`• Declaring Interfaces
`
`Chapter 4 First Programs: Hello World! to BlackJack
`
`2
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 2
`
`¤
`¤
`¤
`¤
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`• Implementing Interfaces
`• The CDrawApp Interface Example
`¤ The CGTextEdit Interface
`¤ Updating the CGText Class
`¤ The CGTextPoint Class
`¤ The CGTextBox Class
`¤ Updating the CDraw Class
`¤ Running the Example
`¤ Example Summary
`• Using Interfaces as Abstract Types
`• Interface Constants
`• Extending Interfaces
`• Combining Interfaces
`• Summary
`Chapter 7
`Exceptions
`• Eliminating Software Errors
`• Error Processing and Exceptions
`• Throwing Exceptions
`• Declaring Exceptions
`• Declare or Catch?
`• Using the try Statement
`• Catching Exceptions
`• Nested Exception Handling
`• Rethrowing Exceptions
`¤ Analysis of NestedExceptionTest
`• Summary
`Chapter 8
`Multithreading
`• Understanding Multithreading
`• How Java Supports Multithreading
`¤ Creating Subclasses of Thread
`Implementing Runnable
`• Thread States
`• Thread Priority and Scheduling
`• Synchronization
`• Daemon Threads
`• Thread Groups
`• Summary
`Using the Debugger
`Chapter 9
`• Overview of the Debugger
`• An Extended Example
`• Debugging Multithreaded Programs
`• Summary
`Chapter 10
`Automating Software Documentation
`• How javadoc Works
`• Using javadoc
`• Placing Doc Comments
`• Using javadoc Tags
`• Embedding Standard HTML
`• Summary
`Chapter 11
`Language Summary
`• The package Statement
`• The import Statement
`• Comments
`
`Chapter 7 Exceptions
`
`3
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 3
`
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`• Identifiers
`• Reserved Words
`• Primitive Data Types and Literal Values
`• Class Declarations
`• Variable Declarations
`• Constructor Declarations
`• Access Method Declarations
`• Static Initializers
`• Interfaces
`• Blocks and Block Bodies
`• Local Variable Declarations
`• Statements
`¤ Empty Statement
`¤ Block Statement
`¤ Method Invocation
`¤ Allocation Statements
`¤ Assignment Statements
`¤ The if Statement
`Statement Labels
`¤ The switch Statement
`¤ The break Statement
`¤ The for Statement
`¤ The while Statement
`¤ The do Statement
`¤ The continue Statement
`¤ The synchronized Statement
`¤ The try Statement
`¤ The return Statement
`• Operators
`• Summary
`Chapter 12
`Portable Software and the
`java.lang Package
`• The Object and Class Classes
`¤ Object
`¤ Class
`¤ A Touch of Class
`• The ClassLoader, SecurityManager, and Runtime Classes
`¤ ClassLoader
`SecurityManager
`¤ Runtime
`• The System Class
`Property-Related Methods
`Security Manager-Related Methods
`¤ Runtime-Related Methods
`¤ Odds and Ends
`¤ Time and Properties
`• Wrapped Classes
`¤ The Boolean Class
`¤ The Character Class
`¤ The Integer and Long Classes
`¤ The Double and Float Classes
`¤ The Number Class
`¤ All Wrapped Up
`• The Math Class
`• The String and StringBuffer Classes
`String Literals
`¤ The + Operator and StringBuffer
`String Constructors
`String Access Methods
`¤ The StringBuffer Class
`• Threads and Processes
`¤ Runnable
`¤ Thread
`
`Chapter 12 Portable Software and the java.lang Package
`
`4
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 4
`
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`¤ ThreadGroup
`Process
`¤ Hello Again
`• The Compiler Class
`• Exceptions and Errors
`¤ The Throwable Class
`¤ The Error Class
`¤ The Exception Class
`• Summary
`Chapter 13
`Stream-Based Input/Output and the
`java.io Package
`• Streams
`• The java.io Class Hierarchy
`• The InputStream Class
`¤ The read() Method
`¤ The available() Method
`¤ The close() Method
`¤ Markable Streams
`¤ The skip() Method
`• The OutputStream Class
`¤ The write() Method
`¤ The flush() Method
`¤ The close() Method
`• Byte Array I/O
`¤ The ByteArrayInputStream Class
`¤ The ByteArrayOutputStream Class
`¤ The ByteArrayIOApp Program
`¤ The StringBufferInputStream Class
`• File I/O
`¤ The File Class
`¤ The FileDescriptor Class
`¤ The FileInputStream Class
`¤ The FileOutputStream Class
`¤ The FileIOApp Program
`• The SequenceInputStream Class
`¤ The SequenceIOApp Program
`• Filtered I/O
`¤ The FilterInputStream Class
`¤ The FilterOutputStream Class
`¤ Buffered I/O
`PushbackInputStream
`¤ The LineNumberInputStream Class
`¤ Data I/O
`¤ The PrintStream Class
`Piped I/O
`• The RandomAccessFile Class
`¤ The RandomIOApp Program
`• The StreamTokenizer Class
`¤ The StreamTokenApp Program
`• Summary
`Chapter 14
`• The Date Class
`¤ DateApp
`• The Random Class
`¤ RandomApp
`• The Enumeration Interface
`• The Vector Class
`¤ VectorApp
`• The Stack Class
`StackApp
`
`Useful Tools in the java.util Package
`
`Chapter 13 Stream-Based Input/Output and the java.io Package
`
`5
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 5
`
`¤
`¤
`¤
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`• The BitSet Class
`¤ BitSetApp
`• The Dictionary, Hashtable, and Properties Classes
`¤ Dictionary
`¤ Hashtable
`¤ The Properties Class
`• The StringTokenizer Class
`¤ TokenApp
`• Observer and Observable
`¤ Observable
`• Summary
`Chapter 15
`Window Programming with the
`java.awt Package
`• Window Programming Classes
`• Components and Containers
`¤ The Container Class
`¤ The Window Class
`¤ The Panel Class
`¤ The Label Class
`¤ The Button Class
`¤ The Checkbox Class
`¤ The Choice Class
`¤ The List Class
`¤ The TextComponent Class
`¤ The Canvas Class
`¤ The Scrollbar Class
`• Constructing Menus
`¤ The MenuBar Class
`¤ The MenuItem Class
`¤ The Menu Class
`¤ The CheckboxMenuItem Class
`¤ The MenuContainer Class
`• Organizing Windows
`¤ The LayoutManager Class
`¤ The BorderLayout Class
`¤ The CardLayout Class
`¤ The FlowLayout Class
`¤ The GridLayout Class
`¤ The GridBagLayout Class
`• Handling Events
`• Working with Images
`¤ The Color Class
`¤ The java.awt.image Package
`¤ The MediaTracker Class
`• Geometrical Objects
`¤ The Point Class
`¤ The Rectangle Class
`¤ The Polygon Class
`¤ The Dimension Class
`• Using Fonts
`¤ The FontMetrics Class
`• Using the Toolkit
`• Summary
`Chapter 16
`Web Programming With the
`java.applet Package
`• Applets and the World Wide Web
`¤ The Applet Class
`¤ Applets and HTML
`• The Life Cycle of an Applet
`• Responding to Events
`
`Chapter 15 Window Programming with the java.awt Package
`
`6
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 6
`
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`Opening Windows
`
`• Using Window Components
`• Adding Audio and Animation
`• Summary
`Chapter 17
`Network Programming with the
`java.net Package
`• The Internet Protocol Suite
`¤ What Is the Internet and How Does It Work?
`¤ Connection-Oriented Versus Connectionless Communication
`• Client/Server Computing and the Internet
`Sockets and Client/Server Communication
`• Overview of java.net
`• The InetAddress Class
`• The Socket Class
`• The ServerSocket Class
`• The DatagramSocket Class
`• The DatagramPacket Class
`¤ TimeServerApp
`¤ GetTimeApp
`• The SocketImpl Class and the SocketImplFactory Interface
`• Web-Related Classes
`¤ URL
`¤ URLConnection
`¤ URLEncoder
`• The ContentHandler and ContentHandlerFactory Classes
`• The URLStreamHandler Class and the URLStreamHandlerFactory Interface
`• Summary
`Chapter 18
`• Hello Windows!
`• Going Round in Ovals: A Graphics Program
`• A Text Editor
`• Summary
`Chapter 19
`Organizing Window Programs
`• Designing Window Programs
`• Opening and Closing Windows
`• Using Layouts
`• Connecting Code to Events
`• The Window Sampler Program
`¤ MyTextField
`¤ MyButton
`¤ MyCanvas
`¤ MyCheckBoxGroup
`¤ MyChoice
`¤ MyList
`¤ MyScrollbar
`• Summary
`Chapter 20
`Menus, Buttons, and Dialong Boxes
`• Adding Menus to Windows
`¤ The MyMenu Class
`¤ The MyMenuBar Class
`¤ The MenuApp Program
`• Working with Buttons
`¤ The ButtonBar Class
`¤ The ButtonApp Program
`• Using Dialog Boxes
`¤ The MessageDialog Class
`
`Chapter 17 Network Programming with the java.net Package
`
`7
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 7
`
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`Text and Fonts
`
`¤ The MessageApp Program
`¤ The FileDialog Class
`• Summary
`Chapter 21
`Checkboxes, Choices, and Lists
`• Using Checkboxes
`¤ The CheckboxPanel Class
`• Working with Radio Buttons
`¤ The CheckboxGroupPanel Class
`• The CheckboxApp Program
`• Making Choices
`¤ The MyChoice Class
`• Selecting from Lists
`¤ The MyList Class
`• The ChoiceListApp Program
`• Summary
`Chapter 22
`• The Text Classes
`• Font Basics
`¤ Using the Toolkit Class
`¤ The FontApp Program
`• WYSIWYG Editors
`¤ The EditApp Program
`¤ The FontDialog Class
`¤ The ColorDialog Class
`• Summary
`The Canvas
`Chapter 23
`• The Canvas and Graphics Classes
`• Displaying Bitmapped Images
`¤ The DisplayImageApp Program
`• Drawing and Painting
`¤ The DrawApp Program
`• Combining Graphics and Text
`• The Image-Processing Classes of java.awt.image
`¤ The ImageApp Program
`• Summary
`Chapter 24
`Scrollbars
`• How Scrollbars Work
`• Using Scrollbars
`• Scrolling Text
`¤ The TextScrollApp Program
`• Scrolling Graphics
`¤ The ImageScrollApp Program
`• Summary
`Chapter 25
`Using Animation
`• Animation Basics
`• A Simple Animation
`• A Graphics Animation
`• Improving Animation Display Qualities
`• An Updated Graphics Animation
`• Summary
`
`Chapter 21 Checkboxes, Choices, and Lists
`
`8
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 8
`
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`Client Programs
`
`Server Programs
`
`Chapter 26
`• Types of Clients
`• Client Responsibilities
`• A Simple Telnet Client
`¤ The Network Virtual Terminal
`¤ The Interpret as Command Code
`¤ Negotiated Options
`Symmetry Between Terminals and Processes
`¤ The TelnetApp Program
`¤ The NVTPrinter Class
`¤ The NVTInputStream Class
`¤ The NVTOutputStream Class
`• A Mail Client
`¤ The MailClientApp Program
`• The Web Fetcher Program
`• Summary
`Chapter 27
`• Types of Servers
`• Server Responsibilities
`• An SMTP Server
`¤ The SMTPServerApp Program
`• A Web Server
`¤ The WebServerApp Program
`• Summary
`Chapter 28
`Content Handlers
`• Using Content Handlers
`• Multipurpose Internet Mail Extensions (MIME)
`• Developing a Content Handler
`• A Simple Content Handler
`¤ The GridContentHandler Class
`¤ The GetGridApp Program
`• Summary
`Chapter 29
`Protocol Handlers
`• Using Protocol Handlers
`• Developing a Protocol Handler
`• A Simple Protocol Handler
`• Summary
`Chapter 30
`• Hello Web!
`• An Audio Player
`• BlackJack Revisited
`• Summary
`Developing Applets
`Chapter 31
`• How Applets Work
`¤ The Relationship Between HTML and Applets
`¤ Applets and Interactive Web Pages
`¤ Applets Versus Scripts
`¤ The Execution of an Applet
`¤ Using Window Components
`¤ Adding Content and Protocol Handlers to Applets
`• Using Applets as Inline Viewers
`• Using Applets as Network Clients
`
`Sample Applets
`
`Chapter 26 Client Programs
`
`9
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 9
`
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`Integrating Applets into Distributed
`
`• Optimizing Applets
`• Learning from Online Examples
`• Summary
`Chapter 32
`Applications
`• Architecture for Distributed Applications
`• OMG and CORBA
`¤ The Spring Project and Java IDL
`¤ NEO and JOE
`JIDL
`¤ Black Widow
`¤ HORB
`• Interfacing with CGI Programs
`¤ How CGI Programs Work
`• Connecting Applets with CGI Programs
`Fortune Teller
`• Summary
`Working with JavaScript
`Chapter 33
`• JavaScript and Java
`• How JavaScript Works
`• The Relationship Between HTML and Scripts
`• Embedding JavaScript
`• Combining Scripts with Applets
`• Summary
`Chapter 34
`Sample Scripts
`• A Customizable Web Page
`• Story Teller
`• Web Guide
`• Summary
`JavaScript Reference
`Chapter 35
`• JavaScript Objects
`• Properties and Methods
`¤ The navigator Object
`¤ The window Object
`¤ The location Object
`¤ The history Object
`¤ The document Object
`¤ The form Object
`¤ The button Object
`¤ The checkbox Object
`¤ The text, textarea, hidden, and password Objects
`¤ The radio Object
`¤ The select Object
`¤ The string Object
`¤ The Date Object
`¤ The Math Object
`• Handling Events
`• Arrays
`• Operators and Expressions
`• Statements
`• Summary
`
`Chapter 32 Integrating Applets into Distributed Applications
`
`10
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 10
`
`¤
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`The Java Virtual Machine
`
`Chapter 36
`The Java Source Code
`• Obtaining the Java Source Code
`• Platform Differences
`• Platform Benchmarks
`• Windows 95/NT Overview
`• Summary
`Chapter 37
`• Overview
`• Structure of .class Files
`¤ Magic
`¤ Version
`¤ Constant_pool
`¤ Access_flags
`¤ This_class
`Interfaces
`Fields
`¤ Methods
`¤ Attributes
`• Virtual Machine Architecture
`JVM Registers
`JVM Stack
`¤ Garbage-Collected Heap
`¤ Method Area
`• Instruction Set
`Pushing Constants onto the Stack
`Pushing Local Variables onto the Stack
`Storing Stack Values into Local Variables
`¤ Managing Arrays
`Stack Instructions
`¤ Arithmetic Instructions
`¤ Logical Instructions
`¤ Conversion Operations
`¤ Control Transfer Instructions
`Function Return Instructions
`¤ Table Jumping Instructions
`¤ Manipulating Object Fields
`¤ Method Invocation
`¤ Exception Handling
`¤ Object Utility Operations
`¤ Monitors
`¤ The breakpoint Instruction
`• Summary
`Chapter 38
`Creating Native Methods
`• Using Native Methods
`• How Native Methods Are Called
`• How Native Methods Are Created
`• Summary
`Chapter 39
`Java Security
`• Threats to Java Security
`• Java Security Features
`¤ Language Security Features
`¤ Compiler Security Features
`¤ Runtime Security Mechanisms
`• Staying Current with Java Security Issues
`• Summary
`
`Chapter 36 The Java Source Code
`
`11
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 11
`
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`Chapter 40
`Java Platforms and Extensions
`• Java-Enabled Browsers
`¤ HotJava
`¤ Netscape Navigator
`¤ Oracle PowerBrowser
`• Borland’s Latte
`¤ Visual Design
`¤ The Integrated Development Environment
`Performance Improvements
`• Symantec’s CafØ
`• Database Extensions
`• VRML Extensions with Iced Java/Liquid Reality
`¤ Three-Dimensional Modeling
`Iced Java and Liquid Reality
`• Summary
`AppendixA The Jawa API Quick Reference
`• java.applet
`• java.awt
`• java.awt.image
`• java.awt.peer
`• java.io
`• java.lang
`• java.net
`• java.util
`AppendixB Differences Between java and C++
`• Program Structure
`¤ The main() Method
`Packages
`Importing Classes
`Functions and Variables Declared Outside of Classes
`• Program Development
`• Compilation and Execution
`• The Preprocessor and Compiler Directives
`• The Java API Versus C++ Libraries
`• Using CLASSPATH
`• Language Syntax
`¤ Comments
`¤ Constants
`Primitive Data Types
`¤ Keywords
`Java Classes Versus C++ Classes
`Public, Private, and Protected Keywords
`¤ Variables
`¤ Types
`Pointers
`¤ Objects
`¤ Arrays
`Strings
`null Versus NULL
`Statements
`¤ Methods Versus Functions
`¤ Operators
`AppendixC Moving C/C++ Legacy Code to Java
`• Why Move to Java?
`Platform Independence
`¤ Object Orientation
`Security
`
`Chapter 40 Java Platforms and Extensions
`
`12
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 12
`
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`¤ Reliability
`Simplicity
`¤ Language Features
`Standardization
`¤ The Java API
`¤ Transition to Distributed Computing
`¤ Rapid Code Generation
`¤ Ease of Documentation and Maintenance
`• Reasons Against Moving to Java
`¤ Compatibility
`Performance
`¤ Retraining
`Impact on Existing Operations
`¤ Cost, Schedule, and Level of Effort
`• Transition Approaches and Issues
`Interfacing with Existing Legacy Cod
`Incremental Reimplementation of Legacy Code
`¤ Off-Boarding Access to Legacy Objects
`Full-Scale Redevelopment
`• Translation Approaches and Issues
`¤ Automated Translation
`¤ Manual Translation
`Source-Level Redesign
`
`Credits
`
`This book is dedicated to Lisa, Emily, and Jason.
`
`Copyright ' 1996 by Jamie Jaworski
`
`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-069-X
`
`HTML conversion by :
` M/s. LeafWriters (India) Pvt. Ltd.
` : http://leaf.stpn.soft.net
`Website
` : leafwriters@leaf.stpn.soft.net
`
`Trademarks
`
`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.
`
`Credits
`
`13
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 13
`
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`¤
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`President, Sams Publishing
`Publishing Manager
`Managing Editor
`Marketing Manager
`Assistant Marketing Manager
`
`Richard K. Swadley
`Mark Taber
`Cindy Morrow
`John Pierce
`Kristina Perry
`
`Acquisitions Editor
`
`Christopher
`Denny
`
`Development Editor
`
`Software
`Development
`Specialist
`Copy Editor
`
`Editorial
`Coordinator
`Formatter
`
`Cover Designer
`Copy Writer
`
`Production
`
`Merle Newlon
`
`Production Editor
`
`Kimberly K.
`Hannel
`Bill Whitmer
`
`Frank
`Sinclair
`
`Technical Reviewer
`
`Technical Edit
`Coordinator
`Editorial
`Assistants
`
`Tim Amrhein
`Peter Fuller
`
`Book Designer
`Production Team
`Supervisor
`Mary Ann Abramson, Steve Adams, Georgiana
`Briggs, Mona Brown, Michael Brumitt,
`Charlotte Clapp, Jeanne Clark, Bruce
`Clingaman, Michael Dietsch, Sonja Hart, Jason
`Hand, Michael Henry, Ayanna Lacey, Clint
`Lahnen, Paula Lowell, Donna Martin, Steph
`Mineart, Dana Rhodes, Erich Richter, Craig
`Small, SA Springer, Mark Walchle
`
`L.
`Angelique
`Brittingham
`Kitty Wilson
`
`Christopher
`M. Stone
`Lynette
`Quinn
`Carol
`Ackerman,
`Andi
`Richter,
`Rhonda
`Tinch-Mize,
`Alyssa Yesh
`Brad Chinn
`
`Acknowledgments
`I’d like to thank everyone who helped to see this book to completion. In
`particular, I’d like to thank George Stones for introducing me to Java,
`Margo Maley for making the book possible, and everyone at Sams.net for
`their great support. I’d also like to thank my co-author, Cary Jardin,
`for helping me finish the book closer to the scheduled deadline.
`
`About the Author
`James Jaworski develops advanced systems for the United States
`Department of Defense. He has used Java in several research and
`development projects, including a terrain analysis program and a genetic
`algorithm demonstration.
`
`Introduction
`Never before has a new programming language received so much attention
`and become so popular so quickly. In less than a year, Java evolved from
`
`Acknowledgments
`
`14
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 14
`
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`experimental Alpha and Beta versions to its initial 1.0 release. Along
`the way, it took the Web by storm and became its adopted programming
`language. The Java phenomenon has captivated the imaginations of Web
`programmers and content developers and is leading the way toward the
`next era of Internet application development.
`
`Java’s appeal lies in its simplicity, its familiarity, and the careful
`selection of programming features that it includes and excludes. Java
`was not designed by a government committee or by a clique of academics.
`It shares the spirit of its birth with C more than any syntactical
`similarities. It is a programming language that was designed by
`programmers for programmers.
`
`This book shows you how to program in Java. It covers all the details of
`the language, provides you with plenty of programming examples, and most
`importantly, arms you with the mindset needed to write Java code in a
`manner that is simple, efficient, and true to the nature of the
`language.
`
`Who Should Read This Book
`
`If you want someone to teach you how to program in Java, this book is
`for you. You will learn how to develop standalone Java programs, Java
`applets, and JavaScript applets. You will learn how to program window
`GUI controls, work with network sockets, and use stream-based input and
`output. You will learn to develop object-oriented programs and explore
`the breadth and depth of the Java application program interface. If you
`want to become a Java programmer, this book will show you how.
`
`This book is for programmers and those who aspire to become Java
`programmers. It consists of 40 chapters that are filled with programming
`examples. If you have written programs in other languages, you will have
`the necessary background to understand the material presented in this
`book. If you have programmed in C or C++, then you will be able to
`quickly get up to speed with Java, since its syntax is based on these
`languages. If you have never programmed before, then you will have a
`difficult time using this book, because it assumes familiarity with
`basic programming concepts such as variables, types, statements, and
`expressions. I suggest that you pick up an introductory programming book
`to help you learn this material.
`
`Conventions Used in This Book
`
`This book uses certain conventions that make it easier for you to use.
`
`A monospaced font is used to identify program code. An italic monospaced
`font is used to identify placeholders used in Java syntax descriptions.
`
`Note
`
`Tip
`
`Notes like this are used to call your
`attention to information that is important to
`understanding and using Java.
`
`Tips like this are used to identify ways that
`you can use Java more efficiently or take
`advantage of undocumented features in the Java
`Developer’s Kit or Java-enabled browsers.
`
`Warning
`Warnings like this are used to help you to
`avoid common problems encountered when using
`
`Who Should Read This Book
`
`15
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 15
`
`
`
`CONTENTS
`
`JAVA Developer’s Guide
`
`Java and to keep you clear of potential
`programming difficulties.
`
`In order to help you understand where you are going and where you have
`been, each chapter begins with a short description of the information
`that will be presented and ends with a summary of the material that has
`been covered.
`
`Getting Started
`
`To use this book with the Java Developer’s Kit, you’ll need a computer
`and operating system that are capable of running Java 1.0. There are a
`wide variety of computers and operating systems that support Java, and
`Java continues to be ported to new hardware and software platforms.
`
`To effectively use Java with Windows 95, you will need the following:
`• A personal computer that is capable of running Windows 95
`• At least 8MB of RAM
`• At least 10MB of available hard disk space
`• A VGA monitor
`• A mouse
`
`To effectively use this book, you will need access to a compact disc
`drive so that you can copy files from the enclosed CD. In addition, an
`Internet connection will be required to complete some of the networking
`examples, and a Java-enabled browser, such as Netscape 2.0 or later,
`will be needed to work with Java applets and JavaScript. A sound card
`and speakers will be needed to use audio-playing applets.
`
`You can get started if you are able to run Windows 95 and have access to
`the Web. Chapter 2 shows you how to obtain the Java Developer’s Kit from
`Sun’s JavaSoft website. You can add additional hardware, as necessary,
`to complete the programming examples of each chapter.
`
`The best way to use this book is to start with Chapter 1 and proceed
`through each chapter, in succession, working through each programming
`example that is presented. You will learn to program in Java by
`compiling, running, analyzing, and understanding the sample programs.
`Additional hands-on learning can be acquired by tinkering with the
`sample programs, modifying them, and augmenting their capabilities.
`
`Getting Started
`
`16
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 16
`
`
`
`CONTENTS
`
`Using the Java Developer’s Kit
`
`public fields and methods of the class. With this information, you will
`be able to figure out how to create instances of the class and access
`their methods.
`
`The debugger is executed as follows:
`
`javap options class
`
`class is the full name of a Java class created by the Java compiler. The
`options control the type of information displayed by the disassembler.
`
`When no options are used, only the public fields and methods of the
`class are displayed. If the ›p option is specified, the class’s
`private and protected fields and methods are also displayed.
`
`The ›c option is used to display the source bytecode instructions for
`the class methods.
`
`The ›classpath option is used in the same way as it is with the compiler
`and interpreter.
`
`Chapter 37 describes the Java virtual machine, the bytecode instruction
`set, and the use of the disassembler to analyze compiled classes.
`The Applet Viewer
`The applet viewer is used to run Java applets and test the applets that
`you develop. The applet viewer creates a window in which the applet can
`be viewed. It provides complete support for all applet functions,
`including networking and multimedia capabilities.
`
`You use the applet viewer as follows:
`
`appletviewer optionsURL
`
`URL is the universal resource locator of an HTML document containing the
`applets to be viewed. It can be located on a local machine or on any
`accessible website. If you just want to view an applet in a local HTML
`file, you can use the file’s name instead of the entire URL of the file.
`
`The ›debug option is the only option supported by the applet viewer. It
`is used to run the applet viewer, using jdb, to test and debug the
`applets contained in the selected HTML document.
`
`The applet viewer is covered in Part VI, "Programming the Web with
`Applets and Scripts." The last section in this chapter shows how to use
`it to display the demo applets included with the JDK.
`Automating Software Documentation
`The Java documentation generator, javadoc, is the tool that created the
`excellent Java API documentation. This documentation can (and should) be
`obtained from Sun’s Java website. Make sure that you get the
`documentation that is applicable to your Java release. You can find it
`by pointing your browser at http://java.sun.com and then clicking on the
`documentation icon.
`
`The documentation generator is executed using either the name of a Java
`source code file, a full class name, or a package name. If it is
`executed with a class name or package name, it will automatically load
`the source code associated with the class or with all the classes in the
`package. If it is executed with a source code file, it will generate
`documentation for all classes and interfaces defined in the file.
`
`The javadoc command line is as follows:
`
`The Applet Viewer
`
`39
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 17
`
`
`
`CONTENTS
`
`Web Programming With the java.applet Package
`
`each of the four life cycle stages of an applet. The init() method is
`invoked by the runtime environment when an applet is initially loaded.
`It is invoked to perform any required initialization processing. The
`start() method is invoked by the runtime system when an applet is
`initially started or restarted as a result of a user switching between
`Web pages. The stop() method is invoked by the runtime system when the
`user switches from the Web page containing the applet to another Web
`page or another program. The destroy() method is invoked when an
`applet’s execution is terminated, usually as the result of the user
`exiting the browser. The isActive() method is used to determine whether
`an applet is currently active.
`
`The getApplet Context() method is used to obtain the
`AppletContext object associated with an applet. The
`AppletContext interface defines methods by which an applet can access
`its execution environment. The getAppletInfo() method returns a
`String object that provides information about an applet. This
`information can include version, copyright, and authorship data as well
`as applet-specific data. The getAppletInfo() method is overridden by
`Applet subclasses to provide this information. The getCodeBase() method
`returns the base URL specifying the applet’s location. The
`getDocumentBase() method returns the URL of the document in which the
`applet is contained. The getParameter() method is used to obtain
`parameter data that is passed to an applet in an HTML file. The
`getParameterInfo() method returns an array that describes all the
`parameters used by an object. It is overriden by Applet subclasses in
`the same manner as the getAppletInfo() method.
`
`The resize() methods are used to resize an applet. The setStub() method
`is used to set the AppletStub associated with the applet. It should not
`be used unless you are constructing your own custom applet viewer. The
`showStatus() method is used to display a status message using the
`applet’s context.
`
`The AppletContext interface defines methods that allow an applet to
`access the context in which it is being run. This is typically a Web
`browser, such as Netscape, but could also be the applet viewer. The
`AppletContext interface of an applet is accessed using the
`getAppletContext() method of the Applet class. AppletContext provides
`seven methods that allow an applet to obtain information about and
`manipulate its environment. The getApplets() method returns an
`Enumeration object that contains all applets which are accessible in the
`applet’s context. The getApplet() method returns an Applet object whose
`name matches a String parameter.The getAudioClip() method returns an
`AudioClip object that is referenced using an URL. The getImage() object
`returns an Image object that is identified by an URL. The two
`showDocument() methods are used to instruct a Web browser to display the
`Web document located at a particular URL. The showStatus() method is
`used to display a status message via the Web browser executing the
`applet.
`
`The AppletStub interface is used to implement an applet viewer. It is
`not generally used by applets. It provides six methods that are used to
`retrieve applet parameters that can be used to support applet viewing.
`
`The AudioClip interface defines three methods: play(), stop(), and
`loop(). The play() method is used to play an audio clip. The
`stop() method is used to terminate the playing of an audio clip. The
`loop() method is used to start and play an audio clip in a continuous
`loop.
`
`Applets and HTML
`
`Web documents are written in Hypertext Markup Language (HTML). HTML uses
`tags to describe the structure of Web documents. Tags are used to
`
`Applets and HTML
`
`247
`
`BLUE COAT SYSTEMS - Exhibit 1052 Page 18
`
`
`
`CONTENTS
`
`Java Security
`
`The compiler checks all class, interface, variable, and method accesses
`to ensure that the accesses are consistent with the access modifiers
`used in their declaration. This prevents classes, interfaces, variables,
`and methods from being used in unintended ways and enforces the
`information hiding capabilitie