You are previewing Learning Java, 3rd Edition.
O'Reilly logo
Learning Java, 3rd Edition

Book Description

Version 5.0 of the Java 2 Standard Edition SDK is the most important upgrade since Java first appeared a decade ago. With Java 5.0, you'll not only find substantial changes in the platform, but to the language itself-something that developers of Java took five years to complete. The main goal of Java 5.0 is to make it easier for you to develop safe, powerful code, but none of these improvements makes Java any easier to learn, even if you've programmed with Java for years. And that means our bestselling hands-on tutorial takes on even greater significance. Learning Java is the most widely sought introduction to the programming language that's changed the way we think about computing. Our updated third edition takes an objective, no-nonsense approach to the new features in Java 5.0, some of which are drastically different from the way things were done in any previous versions. The most essential change is the addition of "generics", a feature that allows developers to write, test, and deploy code once, and then reuse the code again and again for different data types. The beauty of generics is that more problems will be caught during development, and Learning Java will show you exactly how it's done. Java 5.0 also adds more than 1,000 new classes to the Java library. That means 1,000 new things you can do without having to program it in yourself. That's a huge change. With our book's practical examples, you'll come up to speed quickly on this and other new features such as loops and threads. The new edition also includes an introduction to Eclipse, the open source IDE that is growing in popularity. Learning Java , 3rd Edition addresses all of the important uses of Java, such as web applications, servlets, and XML that are increasingly driving enterprise applications. The accompanying CD includes the Java 5.0 SDK for Windows, Linux, and Solaris, plus the Eclipse IDE, the NetBeans IDE, and the many example programs from the book.

Table of Contents

  1. Learning Java
  2. A Note Regarding Supplemental Files
  3. Preface
    1. New Developments
      1. New in This Edition
    2. Using This Book
      1. Online Examples
    3. Online Resources
    4. Conventions Used in This Book
    5. Using Code Examples
    6. Safari Enabled
    7. How to Contact Us
    8. Acknowledgments
  4. 1. A Modern Language
    1. 1.1. Enter Java
      1. 1.1.1. Java’s Origins
      2. 1.1.2. Growing Up
    2. 1.2. A Virtual Machine
    3. 1.3. Java Compared with Other Languages
    4. 1.4. Safety of Design
      1. 1.4.1. Simplify, Simplify, Simplify...
      2. 1.4.2. Type Safety and Method Binding
      3. 1.4.3. Incremental Development
      4. 1.4.4. Dynamic Memory Management
      5. 1.4.5. Error Handling
      6. 1.4.6. Threads
      7. 1.4.7. Scalability
    5. 1.5. Safety of Implementation
      1. 1.5.1. The Verifier
      2. 1.5.2. Class Loaders
      3. 1.5.3. Security Managers
    6. 1.6. Application and User-Level Security
      1. 1.6.1. Signing Classes
    7. 1.7. Java and the Web
      1. 1.7.1. Applets
      2. 1.7.2. New Kinds of Media
      3. 1.7.3. New Software Development Models
    8. 1.8. Java as a General Application Language
    9. 1.9. A Java Road Map
      1. 1.9.1. The Past: Java 1.0-Java 1.4
      2. 1.9.2. The Present: Java 5.0
      3. 1.9.3. The Future
      4. 1.9.4. Availability
  5. 2. A First Application
    1. 2.1. Java Tools and Environment
    2. 2.2. HelloJava
      1. 2.2.1. Classes
      2. 2.2.2. The main() Method
      3. 2.2.3. Classes and Objects
      4. 2.2.4. Variables and Class Types
      5. 2.2.5. HelloComponent
      6. 2.2.6. Inheritance
      7. 2.2.7. The JComponent Class
      8. 2.2.8. Relationships and Finger Pointing
      9. 2.2.9. Package and Imports
      10. 2.2.10. The paintComponent() Method
    3. 2.3. HelloJava2: The Sequel
      1. 2.3.1. Instance Variables
      2. 2.3.2. Constructors
      3. 2.3.3. Events
      4. 2.3.4. The repaint() Method
      5. 2.3.5. Interfaces
    4. 2.4. HelloJava3: The Button Strikes!
      1. 2.4.1. Method Overloading
      2. 2.4.2. Components
      3. 2.4.3. Containers
      4. 2.4.4. Layout
      5. 2.4.5. Subclassing and Subtypes
      6. 2.4.6. More Events and Interfaces
      7. 2.4.7. Color Commentary
      8. 2.4.8. Static Members
      9. 2.4.9. Arrays
      10. 2.4.10. Our Color Methods
    5. 2.5. HelloJava4: Netscape’s Revenge
      1. 2.5.1. Threads
      2. 2.5.2. The Thread Class
      3. 2.5.3. The Runnable Interface
      4. 2.5.4. Starting the Thread
      5. 2.5.5. Running Code in the Thread
      6. 2.5.6. Exceptions
      7. 2.5.7. Synchronization
    6. 2.6. Troubleshooting
      1. 2.6.1. Compilation (javac) Errors
      2. 2.6.2. Runtime (java) Errors
      3. 2.6.3. Java Version Problems
      4. 2.6.4. The getContentPane() Error
  6. 3. Tools of the Trade
    1. 3.1. The Java VM
    2. 3.2. Running Java Applications
      1. 3.2.1. System Properties
    3. 3.3. The Classpath
      1. 3.3.1. javap
    4. 3.4. The Java Compiler
    5. 3.5. JAR Files
      1. 3.5.1. File Compression
      2. 3.5.2. The jar Utility
        1. 3.5.2.1. JAR manifests
        2. 3.5.2.2. Making a JAR file runnable
      3. 3.5.3. The pack200 Utility
    6. 3.6. Policy Files
      1. 3.6.1. The Default Security Manager
      2. 3.6.2. The policytool Utility
      3. 3.6.3. Using a Policy File with the Default Security Manager
  7. 4. The Java Language
    1. 4.1. Text Encoding
    2. 4.2. Comments
      1. 4.2.1. Javadoc Comments
        1. 4.2.1.1. Javadoc as metadata
    3. 4.3. Types
      1. 4.3.1. Primitive Types
        1. 4.3.1.1. Floating-point precision
        2. 4.3.1.2. Variable declaration and initialization
        3. 4.3.1.3. Integer literals
        4. 4.3.1.4. Floating-point literals
        5. 4.3.1.5. Character literals
      2. 4.3.2. Reference Types
      3. 4.3.3. A Word About Strings
    4. 4.4. Statements and Expressions
      1. 4.4.1. Statements
        1. 4.4.1.1. if/else conditionals
        2. 4.4.1.2. do/while loops
        3. 4.4.1.3. The for loop
        4. 4.4.1.4. The enhanced for loop
        5. 4.4.1.5. switch statements
        6. 4.4.1.6. break/continue
        7. 4.4.1.7. Unreachable statements
      2. 4.4.2. Expressions
        1. 4.4.2.1. Operators
        2. 4.4.2.2. Assignment
        3. 4.4.2.3. The null value
        4. 4.4.2.4. Variable access
        5. 4.4.2.5. Method invocation
        6. 4.4.2.6. Object creation
        7. 4.4.2.7. The instanceof operator
    5. 4.5. Exceptions
      1. 4.5.1. Exceptions and Error Classes
      2. 4.5.2. Exception Handling
      3. 4.5.3. Bubbling Up
      4. 4.5.4. Stack Traces
      5. 4.5.5. Checked and Unchecked Exceptions
      6. 4.5.6. Throwing Exceptions
        1. 4.5.6.1. Chaining exceptions
      7. 4.5.7. try Creep
      8. 4.5.8. The finally Clause
      9. 4.5.9. Performance Issues
    6. 4.6. Assertions
      1. 4.6.1. Enabling and Disabling Assertions
      2. 4.6.2. Using Assertions
    7. 4.7. Arrays
      1. 4.7.1. Array Types
      2. 4.7.2. Array Creation and Initialization
      3. 4.7.3. Using Arrays
      4. 4.7.4. Anonymous Arrays
      5. 4.7.5. Multidimensional Arrays
      6. 4.7.6. Inside Arrays
  8. 5. Objects in Java
    1. 5.1. Classes
      1. 5.1.1. Accessing Fields and Methods
      2. 5.1.2. Static Members
        1. 5.1.2.1. Constants versus enumerations
    2. 5.2. Methods
      1. 5.2.1. Local Variables
      2. 5.2.2. Shadowing
        1. 5.2.2.1. The “this” reference
      3. 5.2.3. Static Methods
      4. 5.2.4. Initializing Local Variables
      5. 5.2.5. Argument Passing and References
      6. 5.2.6. Wrappers for Primitive Types
      7. 5.2.7. Autoboxing and Unboxing of Primitives
        1. 5.2.7.1. Performance implications of boxing
      8. 5.2.8. Variable-Length Argument Lists
      9. 5.2.9. Method Overloading
    3. 5.3. Object Creation
      1. 5.3.1. Constructors
      2. 5.3.2. Working with Overloaded Constructors
      3. 5.3.3. Static and Nonstatic Initializer Blocks
    4. 5.4. Object Destruction
      1. 5.4.1. Garbage Collection
      2. 5.4.2. Finalization
      3. 5.4.3. Weak and Soft References
    5. 5.5. Enumerations
      1. 5.5.1. Enum Values
      2. 5.5.2. Customizing Enumerations
  9. 6. Relationships Among Classes
    1. 6.1. Subclassing and Inheritance
      1. 6.1.1. Shadowed Variables
      2. 6.1.2. Overriding Methods
        1. 6.1.2.1. @Override
        2. 6.1.2.2. Overridden methods and dynamic binding
        3. 6.1.2.3. Static method binding
        4. 6.1.2.4. final methods and performance
        5. 6.1.2.5. Compiler optimizations
        6. 6.1.2.6. Method selection revisited
        7. 6.1.2.7. Exceptions and overridden methods
        8. 6.1.2.8. Return types and overridden methods
      3. 6.1.3. Special References: this and super
      4. 6.1.4. Casting
        1. 6.1.4.1. Casting aspersions
      5. 6.1.5. Using Superclass Constructors
      6. 6.1.6. Full Disclosure: Constructors and Initialization
      7. 6.1.7. Abstract Methods and Classes
    2. 6.2. Interfaces
      1. 6.2.1. Interfaces as Callbacks
      2. 6.2.2. Interface Variables
        1. 6.2.2.1. Flag interfaces
      3. 6.2.3. Subinterfaces
        1. 6.2.3.1. Overlapping and conflicting methods
    3. 6.3. Packages and Compilation Units
      1. 6.3.1. Compilation Units
      2. 6.3.2. Package Names
      3. 6.3.3. Class Visibility
      4. 6.3.4. Importing Classes
        1. 6.3.4.1. The unnamed package
        2. 6.3.4.2. Static imports
    4. 6.4. Visibility of Variables and Methods
      1. 6.4.1. Basic Access Modifiers
      2. 6.4.2. Subclasses and Visibility
      3. 6.4.3. Interfaces and Visibility
    5. 6.5. Arrays and the Class Hierarchy
      1. 6.5.1.
        1. 6.5.1.1. ArrayStoreException
    6. 6.6. Inner Classes
      1. 6.6.1. Inner Classes as Adapters
      2. 6.6.2. Inner Classes Within Methods
        1. 6.6.2.1. Limitations on inner classes in methods
        2. 6.6.2.2. Static inner classes
        3. 6.6.2.3. Anonymous inner classes
        4. 6.6.2.4. Scoping of the “this” reference
        5. 6.6.2.5. How do inner classes really work?
        6. 6.6.2.6. Security implications
  10. 7. Working with Objects and Classes
    1. 7.1. The Object Class
      1. 7.1.1. Equality and Equivalence
      2. 7.1.2. Hashcodes
      3. 7.1.3. Cloning Objects
    2. 7.2. The Class Class
    3. 7.3. Reflection
      1. 7.3.1. Modifiers and Security
      2. 7.3.2. Accessing Fields
      3. 7.3.3. Accessing Methods
      4. 7.3.4. Accessing Constructors
      5. 7.3.5. What About Arrays?
      6. 7.3.6. Accessing Generic Type Information
      7. 7.3.7. Accessing Annotation Data
      8. 7.3.8. Dynamic Interface Adapters
      9. 7.3.9. What Is Reflection Good For?
        1. 7.3.9.1. The BeanShell Java scripting language
    4. 7.4. Annotations
      1. 7.4.1. Using Annotations
      2. 7.4.2. Standard Annotations
      3. 7.4.3. The apt Tool
  11. 8. Generics
    1. 8.1. Containers: Building a Better Mousetrap
      1. 8.1.1. Can Containers Be Fixed?
    2. 8.2. Enter Generics
      1. 8.2.1. Talking About Types
    3. 8.3. “There Is No Spoon”
      1. 8.3.1. Erasure
      2. 8.3.2. Raw Types
    4. 8.4. Parameterized Type Relationships
      1. 8.4.1. Why Isn’t a List<Date> a List<Object>?
    5. 8.5. Casts
    6. 8.6. Writing Generic Classes
      1. 8.6.1. The Type Variable
      2. 8.6.2. Subclassing Generics
      3. 8.6.3. Exceptions and Generics
        1. 8.6.3.1. No generic Throwables
      4. 8.6.4. Parameter Type Limitations
        1. 8.6.4.1. Using Class<T>
    7. 8.7. Bounds
      1. 8.7.1. Erasure and Bounds (Working with Legacy Code)
    8. 8.8. Wildcards
      1. 8.8.1. A Supertype of All Instantiations
      2. 8.8.2. Bounded Wildcards
      3. 8.8.3. Thinking Outside the Container
      4. 8.8.4. Lower Bounds
      5. 8.8.5. Reading, Writing, and Arithmetic
      6. 8.8.6. <?>, <Object>, and the Raw Type
      7. 8.8.7. Wildcard Type Relationships
    9. 8.9. Generic Methods
      1. 8.9.1. Generic Methods Introduced
      2. 8.9.2. Type Inference from Arguments
      3. 8.9.3. Type Inference from Assignment Context
      4. 8.9.4. Explicit Type Invocation
      5. 8.9.5. Wildcard Capture
      6. 8.9.6. Wildcard Types Versus Generic Methods
    10. 8.10. Arrays of Parameterized Types
      1. 8.10.1. Using Array Types
      2. 8.10.2. What Good Are Arrays of Generic Types?
      3. 8.10.3. Wildcards in Array Types
    11. 8.11. Case Study: The Enum Class
    12. 8.12. Case Study: The sort() Method
    13. 8.13. Conclusion
  12. 9. Threads
    1. 9.1. Introducing Threads
      1. 9.1.1. The Thread Class and the Runnable Interface
        1. 9.1.1.1. Creating and starting threads
        2. 9.1.1.2. A natural-born thread
        3. 9.1.1.3. Using an adapter
      2. 9.1.2. Controlling Threads
        1. 9.1.2.1. Deprecated methods
        2. 9.1.2.2. The sleep() method
        3. 9.1.2.3. The join() method
        4. 9.1.2.4. The interrupt() method
      3. 9.1.3. Death of a Thread
    2. 9.2. Threading an Applet
      1. 9.2.1.
        1. 9.2.1.1. Issues lurking
    3. 9.3. Synchronization
      1. 9.3.1. Serializing Access to Methods
      2. 9.3.2.
        1. 9.3.2.1. Accessing variables
        2. 9.3.2.2. Reentrant locking
      3. 9.3.3. The wait() and notify() Methods
        1. 9.3.3.1. Wait conditions
      4. 9.3.4. Passing Messages
        1. 9.3.4.1. Food for thought
      5. 9.3.5. ThreadLocal Objects
    4. 9.4. Scheduling and Priority
      1. 9.4.1. Thread State
      2. 9.4.2. Time-Slicing
      3. 9.4.3. Priorities
      4. 9.4.4. Native Threads
      5. 9.4.5. Yielding
    5. 9.5. Thread Groups
      1. 9.5.1. Working with ThreadGroups
      2. 9.5.2. Uncaught Exceptions
    6. 9.6. Thread Performance
      1. 9.6.1. The Cost of Synchronization
      2. 9.6.2. Thread Resource Consumption
    7. 9.7. Concurrency Utilities
      1. 9.7.1. Executors
        1. 9.7.1.1. Tasks with results: Callable and Future
        2. 9.7.1.2. ExecutorService
        3. 9.7.1.3. Collective tasks
        4. 9.7.1.4. Scheduled tasks
        5. 9.7.1.5. CompletionService
        6. 9.7.1.6. The ThreadPoolExecutor implementation
        7. 9.7.1.7. Thread production
      2. 9.7.2. Locks
        1. 9.7.2.1. Read and write locks
        2. 9.7.2.2. Conditions
      3. 9.7.3. Synchronization Constructs
        1. 9.7.3.1. CountDownLatch
        2. 9.7.3.2. Semaphore
        3. 9.7.3.3. CyclicBarrier
        4. 9.7.3.4. Exchanger
      4. 9.7.4. Atomic Operations
        1. 9.7.4.1. Weak implementations
        2. 9.7.4.2. Field updaters
    8. 9.8. Conclusion
  13. 10. Working with Text
    1. 10.1. Text-Related APIs
    2. 10.2. Strings
      1. 10.2.1. Constructing Strings
      2. 10.2.2. Strings from Things
      3. 10.2.3. Comparing Strings
        1. 10.2.3.1. The Collator class
      4. 10.2.4. Searching
      5. 10.2.5. Editing
      6. 10.2.6. String Method Summary
      7. 10.2.7. StringBuilder and StringBuffer
    3. 10.3. Internationalization
      1. 10.3.1. The java.util.Locale Class
      2. 10.3.2. Resource Bundles
    4. 10.4. Parsing and Formatting Text
      1. 10.4.1. Parsing Primitive Numbers
        1. 10.4.1.1. Working with alternate bases
        2. 10.4.1.2. Number formats
      2. 10.4.2. Tokenizing Text
        1. 10.4.2.1. StringTokenizer
    5. 10.5. Printf-Style Formatting
      1. 10.5.1. Formatter
      2. 10.5.2. The Format String
      3. 10.5.3. String Conversions
        1. 10.5.3.1. Width, precision, and justification
        2. 10.5.3.2. Uppercase
        3. 10.5.3.3. Numbered arguments
      4. 10.5.4. Primitive and Numeric Conversions
      5. 10.5.5. Flags
      6. 10.5.6. Miscellaneous
    6. 10.6. Formatting with the java.text Package
      1. 10.6.1. MessageFormat
    7. 10.7. Regular Expressions
      1. 10.7.1. Regex Notation
        1. 10.7.1.1. Write once, run away
        2. 10.7.1.2. Escaped characters
        3. 10.7.1.3. Characters and character classes
        4. 10.7.1.4. Custom character classes
        5. 10.7.1.5. Position markers
        6. 10.7.1.6. Iteration (multiplicity)
        7. 10.7.1.7. Grouping
        8. 10.7.1.8. Capture groups
        9. 10.7.1.9. Numbering
        10. 10.7.1.10. Alternation
        11. 10.7.1.11. Special options
        12. 10.7.1.12. Greediness
        13. 10.7.1.13. Lookaheads and lookbehinds
      2. 10.7.2. The java.util.regex API
        1. 10.7.2.1. Pattern
        2. 10.7.2.2. The Matcher
        3. 10.7.2.3. Splitting and tokenizing strings
        4. 10.7.2.4. Another look at Scanner
        5. 10.7.2.5. Replacing text
        6. 10.7.2.6. The simple template engine
  14. 11. Core Utilities
    1. 11.1. Math Utilities
      1. 11.1.1. The java.lang.Math Class
      2. 11.1.2. The java.math Package
      3. 11.1.3. Random Numbers
    2. 11.2. Dates and Times
      1. 11.2.1. Working with Calendars
      2. 11.2.2. Time Zones
        1. 11.2.2.1. Locale
      3. 11.2.3. Parsing and Formatting with DateFormat
      4. 11.2.4. Printf-Style Date and Time Formatting
    3. 11.3. Timers
    4. 11.4. Collections
      1. 11.4.1. The Collection Interface
        1. 11.4.1.1. Generics and collections
        2. 11.4.1.2. Runtime versus compile-time safety
        3. 11.4.1.3. Collections and arrays
      2. 11.4.2. Iteration
        1. 11.4.2.1. For-loop over collections
        2. 11.4.2.2. java.util.Enumeration
      3. 11.4.3. Collection Types
        1. 11.4.3.1. Set
        2. 11.4.3.2. List
        3. 11.4.3.3. Queue
        4. 11.4.3.4. BlockingQueue
      4. 11.4.4. The Map Interface
        1. 11.4.4.1. ConcurrentMap
      5. 11.4.5. Collection Implementations
        1. 11.4.5.1. Arrays
        2. 11.4.5.2. Linked lists
        3. 11.4.5.3. Trees
        4. 11.4.5.4. Hash maps
        5. 11.4.5.5. Java Collections implementations
      6. 11.4.6. Hash Codes and Key Values
      7. 11.4.7. Synchronized and Unsynchronized Collections
        1. 11.4.7.1. Synchronizing iterators
        2. 11.4.7.2. ConcurrentHashMap and ConcurrentLinkedQueue
      8. 11.4.8. Read-Only and Read-Mostly Collections
        1. 11.4.8.1. Copy on write (“read-mostly”) collections
      9. 11.4.9. WeakHashMap
      10. 11.4.10. EnumSet and EnumMap
      11. 11.4.11. Sorting Collections
      12. 11.4.12. A Thrilling Example
    5. 11.5. Properties
      1. 11.5.1. Loading and Storing
        1. 11.5.1.1. Storing as XML
      2. 11.5.2. System Properties
    6. 11.6. The Preferences API
      1. 11.6.1. Preferences for Classes
      2. 11.6.2. Preferences Storage
      3. 11.6.3. Change Notification
    7. 11.7. The Logging API
      1. 11.7.1. Overview
        1. 11.7.1.1. Loggers
        2. 11.7.1.2. Handlers
        3. 11.7.1.3. Filters
        4. 11.7.1.4. Formatters
      2. 11.7.2. Logging Levels
      3. 11.7.3. A Simple Example
      4. 11.7.4. Logging Setup Properties
      5. 11.7.5. The Logger
      6. 11.7.6. Performance
    8. 11.8. Observers and Observables
  15. 12. Input/Output Facilities
    1. 12.1. Streams
      1. 12.1.1. Terminal I/O
      2. 12.1.2. Character Streams
      3. 12.1.3. Stream Wrappers
        1. 12.1.3.1. Data streams
        2. 12.1.3.2. Buffered streams
        3. 12.1.3.3. PrintWriter and PrintStream
      4. 12.1.4. Pipes
      5. 12.1.5. Streams from Strings and Back
      6. 12.1.6. The rot13InputStream Class
    2. 12.2. Files
      1. 12.2.1. The java.io.File Class
        1. 12.2.1.1. File constructors
        2. 12.2.1.2. Path localization
        3. 12.2.1.3. File operations
      2. 12.2.2. File Streams
      3. 12.2.3. RandomAccessFile
      4. 12.2.4. Applets and Files
    3. 12.3. Serialization
      1. 12.3.1. Initialization with readObject()
      2. 12.3.2. SerialVersionUID
    4. 12.4. Data Compression
      1. 12.4.1. Archives and Compressed Data
      2. 12.4.2. Decompressing Data
    5. 12.5. The NIO Package
      1. 12.5.1. Asynchronous I/O
      2. 12.5.2. Performance
      3. 12.5.3. Mapped and Locked Files
      4. 12.5.4. Channels
      5. 12.5.5. Buffers
        1. 12.5.5.1. Buffer operations
        2. 12.5.5.2. Buffer types
        3. 12.5.5.3. Byte order
        4. 12.5.5.4. Allocating buffers
      6. 12.5.6. Character Encoders and Decoders
        1. 12.5.6.1. CharsetEncoder and CharsetDecoder
      7. 12.5.7. FileChannel
        1. 12.5.7.1. Concurrent access
        2. 12.5.7.2. File locking
        3. 12.5.7.3. Memory-mapped files
        4. 12.5.7.4. Direct transfer
      8. 12.5.8. Scalable I/O with NIO
  16. 13. Network Programming
    1. 13.1. Sockets
      1. 13.1.1. Clients and Servers
        1. 13.1.1.1. Clients
        2. 13.1.1.2. Servers
        3. 13.1.1.3. Sockets and security
      2. 13.1.2. The DateAtHost Client
      3. 13.1.3. The TinyHttpd Server
        1. 13.1.3.1. Do French web servers speak French?
        2. 13.1.3.2. Taming the daemon
        3. 13.1.3.3. Room for improvement
      4. 13.1.4. Socket Options
        1. 13.1.4.1. SO_TIMEOUT
        2. 13.1.4.2. TCP_NODELAY
        3. 13.1.4.3. SO_LINGER
        4. 13.1.4.4. TCP_KEEPALIVE
        5. 13.1.4.5. Half-close
      5. 13.1.5. Proxies and Firewalls
        1. 13.1.5.1. ProxySelector
    2. 13.2. Datagram Sockets
      1. 13.2.1. The HeartBeat Applet
        1. 13.2.1.1. The HeartBeat applet code
        2. 13.2.1.2. The Pulse server code
      2. 13.2.2. InetAddress
    3. 13.3. Simple Serialized Object Protocols
      1. 13.3.1. A Simple Object-Based Server
        1. 13.3.1.1. Limitations
    4. 13.4. Remote Method Invocation
      1. 13.4.1. Remote and Nonremote Objects
        1. 13.4.1.1. Stubs and skeletons (be gone!)
        2. 13.4.1.2. Remote interfaces
        3. 13.4.1.3. Exporting remote objects
        4. 13.4.1.4. The RMI registry
      2. 13.4.2. An RMI Example
        1. 13.4.2.1. Running the example
        2. 13.4.2.2. Dynamic class loading
        3. 13.4.2.3. Passing remote object references
      3. 13.4.3. RMI Object Activation
      4. 13.4.4. RMI and CORBA
    5. 13.5. Scalable I/O with NIO
      1. 13.5.1. Selectable Channels
      2. 13.5.2. Using Select
      3. 13.5.3. LargerHttpd
      4. 13.5.4. Nonblocking Client-Side Operations
  17. 14. Programming for the Web
    1. 14.1. Uniform Resource Locators (URLs)
    2. 14.2. The URL Class
      1. 14.2.1. Stream Data
      2. 14.2.2. Getting the Content as an Object
      3. 14.2.3. Managing Connections
      4. 14.2.4. Handlers in Practice
      5. 14.2.5. Other Handler Frameworks
      6. 14.2.6. Writing Content and Protocol Handlers
    3. 14.3. Talking to Web Applications
      1. 14.3.1. Using the GET Method
      2. 14.3.2. Using the POST Method
      3. 14.3.3. The HttpURLConnection
      4. 14.3.4. SSL and Secure Web Communications
      5. 14.3.5. URLs, URNs, and URIs
    4. 14.4. Web Services
      1. 14.4.1. XML-RPC
      2. 14.4.2. WSDL
      3. 14.4.3. The Tools
        1. 14.4.3.1. Installation and environment
      4. 14.4.4. The Temperature Service
  18. 15. Web Applications and Web Services
    1. 15.1. Web Application Technologies
      1. 15.1.1. JSPs
      2. 15.1.2. XML
      3. 15.1.3. Application Frameworks
    2. 15.2. Web Applications
      1. 15.2.1. The Servlet Life Cycle
      2. 15.2.2. Servlets
      3. 15.2.3. The HelloClient Servlet
        1. 15.2.3.1. ServletExceptions
        2. 15.2.3.2. Content type
      4. 15.2.4. The Servlet Response
      5. 15.2.5. Servlet Parameters
        1. 15.2.5.1. GET, POST, and the “extra path”
        2. 15.2.5.2. GET or POST: which one to use?
      6. 15.2.6. The ShowParameters Servlet
        1. 15.2.6.1. SnoopServlet
      7. 15.2.7. User Session Management
      8. 15.2.8. The ShowSession Servlet
      9. 15.2.9. The ShoppingCart Servlet
      10. 15.2.10. Cookies
      11. 15.2.11. The ServletContext API
    3. 15.3. WAR Files and Deployment
      1. 15.3.1. The web.xml File
      2. 15.3.2. URL Pattern Mappings
      3. 15.3.3. Deploying HelloClient
        1. 15.3.3.1. Reloading web apps
      4. 15.3.4. Error and Index Pages
      5. 15.3.5. Security and Authentication
      6. 15.3.6. Assigning Roles to Users
      7. 15.3.7. Secure Data Transport
      8. 15.3.8. Authenticating Users
      9. 15.3.9. Procedural Security
    4. 15.4. Servlet Filters
      1. 15.4.1. A Simple Filter
      2. 15.4.2. A Test Servlet
      3. 15.4.3. Declaring and Mapping Filters
      4. 15.4.4. Filtering the Servlet Request
      5. 15.4.5. Filtering the Servlet Response
    5. 15.5. Building WAR Files with Ant
      1. 15.5.1. A Development-Oriented Directory Layout
      2. 15.5.2. Deploying and Redeploying WARs with Ant
    6. 15.6. Implementing Web Services
      1. 15.6.1. XML-RPC in Action
      2. 15.6.2. Installation and Environment
      3. 15.6.3. Defining the Service
      4. 15.6.4. Our Echo Service
      5. 15.6.5. Data Types
        1. 15.6.5.1. Standard types
        2. 15.6.5.2. Value data objects
      6. 15.6.6. Deploying the Web Service
      7. 15.6.7. Using the Service
  19. 16. Swing
    1. 16.1. Components
      1. 16.1.1. Peers and Look-and-Feel
      2. 16.1.2. The MVC Framework
      3. 16.1.3. Painting
      4. 16.1.4. Enabling and Disabling Components
      5. 16.1.5. Focus, Please
      6. 16.1.6. Other Component Methods
        1. 16.1.6.1. Containers
      7. 16.1.7. Layout Managers
      8. 16.1.8. Insets
      9. 16.1.9. Z-Ordering (Stacking Components)
      10. 16.1.10. The revalidate() and doLayout() Methods
      11. 16.1.11. Managing Components
      12. 16.1.12. Listening for Components
      13. 16.1.13. Windows and Frames
      14. 16.1.14. Other Methods for Controlling Frames
      15. 16.1.15. Content Panes
    2. 16.2. Events
      1. 16.2.1. Event Receivers and Listener Interfaces
      2. 16.2.2. Event Sources
      3. 16.2.3. Event Delivery
      4. 16.2.4. Event Types
      5. 16.2.5. The java.awt.event.InputEvent Class
      6. 16.2.6. Mouse and Key Modifiers on InputEvents
        1. 16.2.6.1. Mouse-wheel events
      7. 16.2.7. Focus Events
    3. 16.3. Event Summary
      1. 16.3.1. Adapter Classes
      2. 16.3.2. Dummy Adapters
    4. 16.4. The AWT Robot!
    5. 16.5. Multithreading in Swing
  20. 17. Using Swing Components
    1. 17.1. Buttons and Labels
      1. 17.2. HTML Text in Buttons and Labels
    2. 17.3. Checkboxes and Radio Buttons
    3. 17.4. Lists and Combo Boxes
    4. 17.5. The Spinner
    5. 17.6. Borders
    6. 17.7. Menus
    7. 17.8. Pop-up Menus
      1. 17.9. Component-Managed Pop-ups
    8. 17.10. The JScrollPane Class
    9. 17.11. The JSplitPane Class
    10. 17.12. The JTabbedPane Class
    11. 17.13. Scrollbars and Sliders
    12. 17.14. Dialogs
      1. 17.15. File Selection Dialog
      2. 17.16. The Color Chooser
  21. 18. More Swing Components
    1. 18.1. Text Components
      1. 18.1.1. The TextEntryBox Application
      2. 18.1.2. Formatted Text
      3. 18.1.3. Filtering Input
        1. 18.1.3.1. DocumentFilter
      4. 18.1.4. Validating Data
      5. 18.1.5. Say the Magic Word
      6. 18.1.6. Sharing a Data Model
      7. 18.1.7. HTML and RTF for Free
      8. 18.1.8. Managing Text Yourself
    2. 18.2. Focus Navigation
      1. 18.2.1. Trees
      2. 18.2.2. Nodes and Models
      3. 18.2.3. Save a Tree
      4. 18.2.4. Tree Events
      5. 18.2.5. A Complete Example
    3. 18.3. Tables
      1. 18.3.1. A First Stab: Freeloading
      2. 18.3.2. Round Two: Creating a Table Model
      3. 18.3.3. Round Three: A Simple Spreadsheet
      4. 18.3.4. Printing JTables
    4. 18.4. Desktops
    5. 18.5. Pluggable Look-and-Feel
      1. 18.5.1. Synth, the Skinnable L&F
    6. 18.6. Creating Custom Components
      1. 18.6.1. Generating Events
      2. 18.6.2. A Dial Component
      3. 18.6.3. Model and View Separation
  22. 19. Layout Managers
    1. 19.1. FlowLayout
    2. 19.2. GridLayout
    3. 19.3. BorderLayout
    4. 19.4. BoxLayout
    5. 19.5. CardLayout
    6. 19.6. GridBagLayout
      1. 19.6.1. The GridBagConstraints Class
      2. 19.6.2. Grid Coordinates
      3. 19.6.3. The fill Constraint
      4. 19.6.4. Spanning Rows and Columns
      5. 19.6.5. Weighting
        1. 19.6.5.1. Calculating the weights of rows and columns
      6. 19.6.6. Anchoring
      7. 19.6.7. Padding and Insets
      8. 19.6.8. Relative Positioning
      9. 19.6.9. Composite Layouts
    7. 19.7. Nonstandard Layout Managers
    8. 19.8. Absolute Positioning
    9. 19.9. SpringLayout
  23. 20. Drawing with the 2D API
    1. 20.1. The Big Picture
    2. 20.2. The Rendering Pipeline
    3. 20.3. A Quick Tour of Java 2D
      1. 20.3.1. Filling Shapes
      2. 20.3.2. Drawing Shape Outlines
      3. 20.3.3. Convenience Methods
      4. 20.3.4. Drawing Text
      5. 20.3.5. Drawing Images
        1. 20.3.5.1. Transformations and rendering
      6. 20.3.6. The Whole Iguana
    4. 20.4. Filling Shapes
      1. 20.4.1. Solid Colors
      2. 20.4.2. Color Gradients
      3. 20.4.3. Textures
      4. 20.4.4. Desktop Colors
    5. 20.5. Stroking Shape Outlines
    6. 20.6. Using Fonts
      1. 20.6.1. Font Metrics
    7. 20.7. Displaying Images
      1. 20.7.1. The Image Class
      2. 20.7.2. Image Observers
        1. 20.7.2.1. Preloading images
      3. 20.7.3. Scaling and Size
    8. 20.8. Drawing Techniques
      1. 20.8.1. Double Buffering
      2. 20.8.2. Limiting Drawing with Clipping
      3. 20.8.3. Offscreen Drawing
    9. 20.9. Printing
  24. 21. Working with Images and Other Media
    1. 21.1. Loading Images
      1. 21.1.1. ImageObserver
      2. 21.1.2. MediaTracker
      3. 21.1.3. ImageIcon
      4. 21.1.4. ImageIO
    2. 21.2. Producing Image Data
      1. 21.2.1. Drawing Animations
      2. 21.2.2. BufferedImage Anatomy
      3. 21.2.3. Color Models
      4. 21.2.4. Creating an Image
      5. 21.2.5. Updating a BufferedImage
    3. 21.3. Filtering Image Data
      1. 21.3.1. How ImageProcessor Works
      2. 21.3.2. Converting an Image to a BufferedImage
      3. 21.3.3. Using the RescaleOp Class
      4. 21.3.4. Using the AffineTransformOp Class
    4. 21.4. Saving Image Data
    5. 21.5. Simple Audio
    6. 21.6. Java Media Framework
  25. 22. JavaBeans
    1. 22.1. What’s a Bean?
      1. 22.1.1. How Big Is a Bean?
    2. 22.2. The NetBeans IDE
      1. 22.2.1. Installing and Running NetBeans
        1. 22.2.1.1. Installing our example beans
        2. 22.2.1.2. Creating a project and file
        3. 22.2.1.3. The NetBeans workspace
    3. 22.3. Properties and Customizers
    4. 22.4. Event Hookups and Adapters
      1. 22.4.1. Taming the Juggler
        1. 22.4.1.1. Running the example
      2. 22.4.2. Molecular Motion
    5. 22.5. Binding Properties
      1. 22.5.1. Constraining Properties
    6. 22.6. Building Beans
      1. 22.6.1. The Dial Bean
      2. 22.6.2. Design Patterns for Properties
        1. 22.6.2.1. Bean patterns in NetBeans
      3. 22.6.3. A (Slightly) More Realistic Example
        1. 22.6.3.1. A bean for validating numeric data
        2. 22.6.3.2. An invisible multiplier
        3. 22.6.3.3. Putting them together
    7. 22.7. Limitations of Visual Design
    8. 22.8. Serialization Versus Code Generation
    9. 22.9. Customizing with BeanInfo
      1. 22.9.1. Getting Properties Information
        1. 22.9.1.1. Getting events information
        2. 22.9.1.2. Supplying icons
        3. 22.9.1.3. Creating customizers and property editors
    10. 22.10. Hand-Coding with Beans
      1. 22.10.1. Bean Instantiation and Type Management
      2. 22.10.2. Working with Serialized Beans
      3. 22.10.3. Runtime Event Hookups with Reflection
        1. 22.10.3.1. Safety implications
        2. 22.10.3.2. How it works
    11. 22.11. BeanContext and BeanContextServices
    12. 22.12. The Java Activation Framework
    13. 22.13. Enterprise JavaBeans
  26. 23. Applets
    1. 23.1. The Politics of Applets
    2. 23.2. The JApplet Class
      1. 23.2.1. Applet Life Cycle
      2. 23.2.2. The Applet Security Sandbox
        1. 23.2.2.1. Trusted applets
      3. 23.2.3. Getting Applet Resources
        1. 23.2.3.1. Applet parameters
        2. 23.2.3.2. Applet resources
        3. 23.2.3.3. Driving the browser
        4. 23.2.3.4. Inter-applet communication
        5. 23.2.3.5. Applet persistence and navigation
        6. 23.2.3.6. Applets versus standalone applications
      4. 23.2.4. Attributes
      5. 23.2.5. Parameters
      6. 23.2.6. ¿Habla Applet?
      7. 23.2.7. The Complete <applet> Tag
      8. 23.2.8. Loading Class Files
      9. 23.2.9. Packages
      10. 23.2.10. appletviewer
    3. 23.3. Using the Java Plug-in
      1. 23.3.1. What Is the Java Plug-in?
      2. 23.3.2. Messy Tags
        1. 23.3.2.1. Applets in Internet Explorer
      3. 23.3.3. Viewing Plug-in Applets
    4. 23.4. Java Web Start
    5. 23.5. Using Digital Signatures
      1. 23.5.1. Certificates
        1. 23.5.1.1. Certificate authority certificates
        2. 23.5.1.2. Site certificates
        3. 23.5.1.3. User (signer) certificates
      2. 23.5.2. The keytool Utility
        1. 23.5.2.1. What about Netscape and Internet Explorer?
        2. 23.5.2.2. The TestWrite example
      3. 23.5.3. Keystores, Keys, and Certificates
        1. 23.5.3.1. Public and private keys
        2. 23.5.3.2. Certificates
      4. 23.5.4. The jarsigner Utility
    6. 23.6. Conclusion
  27. 24. XML
    1. 24.1. A Bit of Background
      1. 24.1.1. Text Versus Binary
      2. 24.1.2. A Universal Parser
      3. 24.1.3. The State of XML
      4. 24.1.4. The XML APIs
      5. 24.1.5. XML and Web Browsers
    2. 24.2. XML Basics
      1. 24.2.1. Attributes
      2. 24.2.2. XML Documents
      3. 24.2.3. Encoding
      4. 24.2.4. Namespaces
      5. 24.2.5. Validation
      6. 24.2.6. HTML to XHTML
    3. 24.3. SAX
      1. 24.3.1. The SAX API
        1. 24.3.1.1. JAXP
        2. 24.3.1.2. SAX’s strengths and weaknesses
      2. 24.3.2. Building a Model Using SAX
        1. 24.3.2.1. Creating the XML file
        2. 24.3.2.2. The model
        3. 24.3.2.3. The SAXModelBuilder
        4. 24.3.2.4. Test drive
        5. 24.3.2.5. Limitations and possibilities
      3. 24.3.3. XMLEncoder/Decoder
        1. 24.3.3.1. Further thoughts
    4. 24.4. DOM
      1. 24.4.1. The DOM API
      2. 24.4.2. Test-Driving DOM
      3. 24.4.3. Generating XML with DOM
      4. 24.4.4. JDOM
    5. 24.5. XPath
      1. 24.5.1. Nodes
      2. 24.5.2. Predicates
      3. 24.5.3. Functions
      4. 24.5.4. The XPath API
      5. 24.5.5. XMLGrep
    6. 24.6. XInclude
      1. 24.6.1. Enabling XInclude
    7. 24.7. Validating Documents
      1. 24.7.1. Using Document Validation
      2. 24.7.2. DTDs
      3. 24.7.3. XML Schema
        1. 24.7.3.1. Simple types
        2. 24.7.3.2. Complex types
        3. 24.7.3.3. Trang
      4. 24.7.4. The Validation API
        1. 24.7.4.1. Alternative schema languages
    8. 24.8. JAXB and Code Generation
      1. 24.8.1. Generating the Model
        1. 24.8.1.1. Unmarshaling from XML
        2. 24.8.1.2. Marshaling to XML
    9. 24.9. Transforming Documents with XSL/XSLT
      1. 24.9.1. XSL Basics
      2. 24.9.2. Transforming the Zoo Inventory
      3. 24.9.3. XSLTransform
      4. 24.9.4. XSL in the Browser
    10. 24.10. Web Services
    11. 24.11. The End of the Book
  28. A. The Eclipse IDE
    1. A.1. The IDE Wars
    2. A.2. Getting Started with Eclipse
      1. A.2.1. Importing the Learning Java Examples
    3. A.3. Using Eclipse
      1. A.3.1. Getting at the Source
      2. A.3.2. The Lay of the Land
      3. A.3.3. Running the Examples
      4. A.3.4. Building the Ant-Based Examples
      5. A.3.5. Loner Examples
    4. A.4. Eclipse Features
      1. A.4.1. Coding Shortcuts
      2. A.4.2. Auto-Correction
      3. A.4.3. Refactoring
      4. A.4.4. Diff’ing Files
      5. A.4.5. Organizing Imports
      6. A.4.6. Formatting Source Code
    5. A.5. Conclusion
  29. B. BeanShell: Simple Java Scripting
    1. B.1. Running BeanShell
    2. B.2. Java Statements and Expressions
      1. B.2.1. Imports
    3. B.3. BeanShell Commands
    4. B.4. Scripted Methods and Objects
      1. B.4.1. Scripting Interfaces and Adapters
    5. B.5. Changing the Classpath
    6. B.6. Learning More . . .
  30. Glossary
  31. Index
  32. About the Authors
  33. Colophon
  34. Copyright