Preface Who this book is for What's in this book? Platform Notes Other Books Conventions Used in This Book We'd like to Hear from You Acknowledgements 1.Getting Started: Compiling, Running and Debugging Compiling and running Java Compiling Co-Dependant Classes Running Applets Dealing with Deprecation Warnings Conditional Debugging without #ifdef Debugging Printouts Using a debugger Avoid the need for debuggers Decompiling Java class files Preventing others from decompiling your Java files Getting readable tracebacks: Disabling JIT Where to find more Java source code 2.Interacting with the environment Environment Variables? System Properties Writing JDK-Release-dependent Code Writing Operating-System-dependent Code Effective use of CLASSPATH Parsing Command-line arguments 3.Strings and Things Taking Strings Apart with Substrings Taking Strings Apart with StringTokenizer Putting Strings together: + and StringBuffer Converting Between Unicode Characters and Values Processing a String One Character at a Time Reversing a String by Word or Character Expanding and Compressing Tabs Controlling Case Indenting Text Documents Entering Unprintable Characters Trimming Blanks from the Ends of a String Program: A simple text formatter Program: Soundex Name Comparisons 4.Pattern Matching with Regular Expressions Regular Expression Syntax How do they work in practice? How do they work in Theory? Using regular expressions in Java Reusing the compiled pattern Matching newlines in text Matching text throughout files Finding the text that matched Replacing the Text that Matched Program: Full Grep 5.Numbers Checking Whether a String Is a Valid Number Storing a larger number in a smaller. Taking a fraction of an integer without using floating point Ensuring the Accuracy of Floating-Point Numbers Comparing Floating Point Numbers Rounding Floating-Point Numbers Formatting Numbers: Commas or Periods, Leading Zeros, and other issues Converting Between Binary, Octal, Decimal and Hexadecimal Operating on a Series of Integers Working with Roman Numerals Formatting with Correct Plurals Generating Random Numbers Generating Different Random Numbers Making Numbers Even More Random Calculating More Trigonometric Functions Taking Logarithms Multiplying Matrices Using Complex Numbers Handling very large numbers Program: TempConverter Program: Palindromes of a Number 6.Dates and Times Introduction Finding Today's Date Printing the Date/Time in a specified format Representing the Date in Other Locales Converting YMDHMS to a Calendar and/or to Epoch seconds. Parsing Strings into Dates Converting Epoch Seconds to DMYHMS Adding to or Subtracting from a Date or Calendar Difference between Two Dates Day of Week/Month/Year or Week Number Calendar Page High-Resolution Timers Sleeping for a While Program: ReminderService 7.Structuring Data with Java Introduction Data Structuring using Arrays Resizing an array Like an Array, but More Dynamic Data-independant access with Iterators Structuring Data in a Linked List: CS101 Mapping with Hashtable and Hashmap Storing Strings in Properties & Preferences Sorting a Collection Avoiding that Urge to Sort Sets Finding an Object in a Collection Rolling Your Own Enumeration/Iterator Stack Multi-Dimensional Structures Finally, Collections Program 8.Object Oriented Techniques in Java Advice, or Mantras Subclass early and often Use Design Patterns Public, Private or Protected? Printing your objects: formatting with toString() Overriding the equals method The Hashcode Method The clone Method The finalize method Passing a built-in and returning its value back other than via return Program - Plotter 9.Input and Output with Java Overview Reading Standard Input Writing Standard output Opening a file by name Copying a file Reassigning the standard streams Duplicating a stream as it is written - the UNIX tee command as a Stream Reading/writing a different character set Those darned end-of-line characters Beware Platform-dependant file code Reading "continued" lines Scanning a File Binary Data Seeking Writing DataStreams from C Saving & Restoring "serialized" objects Reading/Writing Zip Archives Reading/Writing Compressed Files Program: TarList 10.Programming Serial and Parallel Ports Introduction. Choosing a Port Preparing and Opening a Serial Port Preparing and Opening a Parallel Port Resolving Port Conflicts Reading and Writing: lock step Reading and Writing: Event-driven Reading and Writing: Threads Program: Penman Plotter Program: JModem 11.Directory and Filesystem Operations Getting File Information Creating a file Renaming a file Deleting a file Creating a Transient File Changing File Attributes Listing a Directory Making new directories Program 12.Graphics Introduction Painting with a Graphics Objects Drawing Text Drawing a Drop Shadow effect Drawing an Image Playing a Sound File Displaying a Moving Image via Animation Displaying a Moving Image via Video Drawing Text With 2D Transformations, Rotations, etc. Printing - JDK1.1 Printing - Java 2 Program - PlotterAWT Program - Grapher 13.Graphical User Interfaces Introduction Displaying GUI components Designing a Window Layout A Tabbed View of Life Making a button push do something Making "Window Close" terminate a program. When later just won't do Choosing a File with JFileChooser Choosing a Color Centering a Main Window Changing the Look and Feel Program: Custom Font Chooser Program: Custom Layout Manager See Also 14.Internationalization and Localization The Global Reach of Software Creating a Button with I18N Resources Creating a Menu with I18N Resources Writing Internationalization Convenience Routines Creating a Dialog with I18N Resources Creating a Resource Bundle JILTing your code Using a Particular Locale Setting the Default Locale within your program Formatting Messages Program: MenuIntl Program: BusCard 15.Network Clients Introduction Contacting a server Handling Network Errors Reading and Writing textual data Reading and Writing binary data Reading and Writing serialized data Datagrams Program: Telnet client Program: Chat Client 16.Server-side Java: Sockets Introduction Opening a Server for Business Returning a response (String or binary) Returning Object information Handling Multiple Clients Program: A Java Chat server 17.Network Clients II: Web Clients Introduction Embedding Java in a Web Page Applet Techniques Contacting a Server on the Applet Host Making an Applet show a Document Making an Applet run a CGI script Getting the content of a URL Extracting HTML from a URL Extracting URLs from a file Creating a URL for a local file Automation: MkIndex Automation: LinkChecker 18.Web Server Java: Servlets and JSP Introduction First Servlet: How to generate a page of HTML Servlets: Processing Form Parameters Cookies Session Tracking Generating PDF from a Servlet HTML Meets Java: Java Server Pages Java Server Pages Include/Forward Java Server Pages Using a Servlet Simplifying your JSP with a JavaBean Simplifying your JSP further with Custom Tags Java Server Pages Syntax Summary Program: JabaDot Web News Portal 19.Java and Electronic Mail Introduction Sending email - browser version Sending email - for real Sending MIME Mail Providing Mail settings Reading email Mail it yourself, without using JavaMail Program: MailClient 20.Database Databases, Accessors and JDBC Text-file "databases" DBM databases JDBC Setup and Connection Connecting to a JDBC Database Sending a JDBC Query and Getting Results Using JDBC Parameterized Statements Using Stored Procedures with JDBC Creating and filling a table Finding JDBC Metadata Program: JDAdmin 21.XML: The eXtensible Markup Language About XML Transforming XML with XSLF Transforming XML with XSLT Parsing XML with SAX Parsing XML with DOM Verifying Structure with a DTD Generating your own XML with DOM Applying XML: SOAP Program: xml2mif 22.Distributed Java: RMI Introducing Distributed Java Defining the RMI contract RMI client RMI server Deploying RMI across a network Program: RMI Callbacks Program: RMIWatch 23.Packages and Packaging Introduction Making a package Documenting your classes with javadoc Archiving with Jar Running an Applet from a Jar Running an Applet with a specific JDK: The Java Plugin Running a Program from a Jar "Write Once, Install Anywhere" Signing your Jar 24.JavaBeans: The Universal Component Architecture Introduction Making a Class Usable as a JavaBean Writing a Bean Descriptor Pickling your Bean into a Jar Using Visual JavaBean Components Using JavaBeans in ActiveX containers Migrating ActiveX controls to JavaBeans Program - ChartBean 25.Threaded Java Threaded Java: Enabling Livelier Applications How to run code in a different thread Animation Stopping a Thread Rendezvous and Timeouts Catching exceptions in multiple threads Threaded Network Server Program: Background saving in an editor Program: Threaded Web Server 26.Introspection, or, "A Class named Class" Introduction Getting a Class descriptor Finding & Calling Methods (and finding Fields) Loading a Class dynamically Constructing a class from scratch Program: MyJavaP Program: CrossRef Program: AppletViewer 27.Writing Efficient Java Programs Introduction Avoiding Memory Leaks Performance Measurement: Time Measurement Performance Measurement: -Xrunhprof Using Efficient Algorithms 28.Dealing with Other Languages Introduction Running a program Mixing Java and Scripts: Java's Bean Scripting Framework (BSF) Blending In Native Code (C/C++) Calling Java from Native Code Program: DBM 29.Afterwords