CITATION

Schildt, Herbert. Herb Schildt's Java Programming Cookbook. McGraw-Hill Osborne Media, 2007.

Herb Schildt's Java Programming Cookbook

Published:  November 2007

eISBN: 9780071596442 0071596445 | ISBN: 9780072263152
  • Contents
  • Preface
  • 1 Overview
  • What’s Inside
  • How the Recipes Are Organized
  • A Few Words of Caution
  • Java Experience Required
  • What Version of Java?
  • 2 Working with Strings and Regular Expressions
  • An Overview of Java’s String Classes
  • Java’s Regular Expression API
  • An Introduction to Regular Expressions
  • Normal Characters
  • Character Classes
  • The Wildcard Character
  • Quantifiers
  • Greedy, Reluctant, and Possessive Quantifiers
  • Boundary Matchers
  • The OR Operator
  • Groups
  • Flag Sequences
  • Remember to Escape the \ in Java Strings
  • Sort an Array of Strings in Reverse Order
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Ignore Case Differences when Sorting an Array of Strings
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Ignore Case Differences when Searching for or Replacing Substrings
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Split a String into Pieces by Using split( )
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Retrieve Key/Value Pairs from a String
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Match and Extract Substrings Using the Regular Expression API
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Tokenize a String Using the Regular Expression API
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example
  • Options and Alternatives
  • 3 File Handling
  • An Overview of File Handling
  • Streams
  • The RandomAccessFile Class
  • The File Class
  • The I/O Interfaces
  • The Compressed File Streams
  • Tips for Handling Errors
  • Read Bytes from a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Write Bytes to a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Buffer Byte-Based File I/O
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Read Characters from a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Write Characters to a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Buffer Character-Based File I/O
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Read and Write Random-Access Files
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Obtain File Attributes
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Set File Attributes
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • List a Directory
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example
  • Options and Alternatives
  • Compress and Decompress Data
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a ZIP File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Decompress a ZIP File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Serialize Objects
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 4 Formatting Data
  • An Overview of Formatter
  • Formatting Basics
  • Specifying a Minimum Field Width
  • Specifying Precision
  • Using the Format Flags
  • The Uppercase Option
  • Using an Argument Index
  • Overview of NumberFormat and DateFormat
  • Four Simple Numeric Formatting Techniques Using Formatter
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Vertically Align Numeric Data Using Formatter
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Center Data
  • Options and Alternatives
  • Left-Justify Output Using Formatter
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Time and Date Using Formatter
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Specify a Locale with Formatter
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use Streams with Formatter
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use printf( ) to Display Formatted Data
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example
  • Options and Alternatives
  • Format Time and Date with DateFormat
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Time and Date with Patterns Using SimpleDateFormat
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Numeric Values with NumberFormat
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Currency Values Using NumberFormat
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Numeric Values with Patterns Using DecimalFormat
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 5 Working with Collections
  • Collections Overview
  • Three Recent Changes
  • The Collection Interfaces
  • The Collection Classes
  • The ArrayList Class
  • The LinkedList Class
  • The HashSet Class
  • The LinkedHashSet Class
  • The TreeSet Class
  • The PriorityQueue Class
  • The ArrayDeque Class
  • The EnumSet Class
  • An Overview of Maps
  • The Map Interfaces
  • The Map Classes
  • Algorithms
  • Basic Collection Techniques
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Work with Lists
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Work with Sets
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example
  • Options and Alternatives
  • Use Comparable to Store Objects in a Sorted Collection
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use a Comparator with a Collection
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Iterate a Collection
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Queue or a Stack Using Deque
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Reverse, Rotate, and Shuffle a List
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Sort and Search a List
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Checked Collection
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Synchronized Collection
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create an Immutable Collection
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Basic Map Techniques
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Convert a Properties List into a HashMap
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 6 Applets and Servlets
  • Applet Overview
  • The Applet Class
  • Applet Architecture
  • The Applet Life Cycle
  • The AppletContext, AudioClip, and AppletStub Interfaces
  • Servlet Overview
  • The javax.servlet Package
  • The javax.servlet.http Package
  • The HttpServlet Class
  • The Cookie Class
  • The Servlet Life Cycle
  • Using Tomcat for Servlet Development
  • Create an AWT-Based Applet Skeleton
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Swing-Based Applet Skeleton
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a GUI and Handle Events in a Swing Applet
  • Step-by-Step
  • Discussion
  • Historical Note: getContentPane( )
  • Example
  • Bonus Example
  • Options and Alternatives
  • Paint Directly to the Surface of an Applet
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Pass Parameters to Applets
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use AppletContext to Display a Web Page
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Simple Servlet Using GenericServlet
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Handle HTTP Requests in a Servlet
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example
  • Options and Alternatives
  • Use a Cookie with a Servlet
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 7 Multithreading
  • Multithreading Fundamentals
  • The Runnable Interface
  • The Thread Class
  • Create a Thread by Implementing Runnable
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Thread by Extending Thread
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use a Thread's Name and ID
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Wait for a Thread to End
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Synchronize Threads
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Communicate Between Threads
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Suspend, Resume, and Stop a Thread
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use a Daemon Thread
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: A Simple Reminder Class
  • Options and Alternatives
  • Interrupt a Thread
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Set and Obtain a Thread's Priority
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Monitor a Thread's State
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: A Real-Time Thread Monitor
  • Options and Alternatives
  • Use a Thread Group
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 8 Swing
  • Overview of Swing
  • Components and Containers
  • Components
  • Containers
  • The Top-Level Container Panes
  • Layout Manager Overview
  • Event Handling
  • Events
  • Event Sources
  • Event Listeners
  • Create a Simple Swing Application
  • Step-by-Step
  • Discussion
  • Historical Note: getContentPane( )
  • Example
  • Options and Alternatives
  • Set the Content Pane's Layout Manager
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Work with JLabel
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Simple Push Button
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use Icons, HTML, and Mnemonics with JButton
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Toggle Button
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create Check Boxes
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create Radio Buttons
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Input Text with JTextField
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Cut, Copy, and Paste
  • Options and Alternatives
  • Work with JList
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use a Scroll Bar
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use JScrollPane to Handle Scrolling
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Display Data in a JTable
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Handle JTable Events
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Display Data in a JTree
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Main Menu
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 9 Potpourri
  • Access a Resource via an HTTP Connection
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use a Semaphore
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Return a Value from a Thread
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use Reflection to Obtain Information about a Class at Runtime
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: A Reflection Utility
  • Options and Alternatives
  • Use Reflection to Dynamically Create an Object and Call Methods
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Custom Exception Class
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Schedule a Task for Future Execution
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Index