"This book is a tremendous achievement. You owe it to yourself to have a copy on your shelf. The chapter on iostreams is the most comprehensive and understandable treatment of that subject Ive seen to date." - Al Stevens Contributing Editor, Doctor Dobbs Journal" Eckels book is the only one to so clearly explain how to rethink program construction for object orientation. That the book is also an excellent tutorial on the ins and outs of C++ is an added bonus." - Andrew Binstock Editor, Unix Review"Bruce continues to amaze me with his insight into C++, and Thinking in C++ is his best collection of ideas yet. If you want clear answers to difficult questions about C++, buy this outstanding book." - Gary Entsminger Author, The Tao of Objects"Thinking in C++ patiently and methodically explores the issues of when and how to use inlines, references, operator overloading, inheritance, and dynamic objects, as well as advanced topics such as the proper use of templates, exceptions and multiple inheritance. The entire effort is woven in a fabric that includes Eckels own philosophy of object and program design. A must for every C++ developers bookshelf, Thinking in C++ is the one C++ you must have if youre doing serious development with C++." - Richard Hale Shaw Contributing Editor, PC Magazine
(NOTE: Each chapter concludes with Summary and Exercises.
)1. Introduction to Objects.
The Progress of Abstraction. An Object Has an Interface. The Hidden Implementation. Reusing the Implementation. Inheritance: Reusing the Interface. Is-A vs. Is-Like-A Relationships. Interchangeable Objects with Polymorphism. Abstract Base Classes and Interfaces. Object Landscapes and Lifetimes. Collections and Iterators. The Singly Rooted Hierarchy. Collection Libraries and Support for Easy Collection Use. Downcasting vs. Templates/Generics. The Housekeeping Dilemma: Who Should Clean Up? Garbage Collectors vs. Efficiency and Flexibility. Exception Handling: Dealing with Errors. Multithreading. Persistence. Java and the Internet. What Is the Web? Client/Server Computing. The Web as a Giant Server. Client-Side Programming. Plug-Ins. Scripting Languages. Java. Activex. Security. Internet vs. Intranet. Server-Side Programming. A Separate Arena: Applications. Analysis and Design. Phase 0: Make a Plan. The Mission Statement. Phase 1: What Are We Making? Phase 2: How Will We Build It? Five Stages of Object Design. Guidelines for Object Development. Phase 3: Build the Core. Phase 4: Iterate the Use Cases. Phase 5: Evolution. Plans Pay Off. Extreme Programming. Write Tests First. Pair Programming. Why Java Succeeds. Systems Are Easier to Express and Understand. Maximal Leverage with Libraries. Error Handling. Programming in the Large. Strategies for Transition. Guidelines. 1. Training. 2. Low-Risk Project. 3. Model from Success. 4. Use Existing Class Libraries. 5. Don't Rewrite Existing Code in Java. Management Obstacles. Startup Costs. Performance Issues. Common Design Errors. Java vs. C++?2. Everything Is an Object.
You Manipulate Objects with References. You Must Create All the Objects. Where Storage Lives. Special Case: Primitive Types. High-Precision Numbers. Arrays in Java. You Never Need to Destroy an Object. Scoping. Scope of Objects. Creating New Data Types: Class. Fields and Methods. Default Values for Primitive Members. Methods, Arguments, and Return Values. The Argument List. Building a Java Program. Name Visibility. Using Other Components. The Static Keyword. Your First Java Program. Compiling and Running. Comments and Embedded Documentation. Comment Documentation. Syntax. Embedded HTML. @See: Referring to Other Classes. Class Documentation Tags. @Version. @Author. @Since. Variable Documentation Tags. Method Documentation Tags. @Param. @Return. @Throws. @Deprecated. Documentation Example. Coding Style.3. Controlling Program Flow.
Using Java Operators. Precedence. Assignment. Aliasing during Method Calls. Mathematical Operators. Unary Minus and Plus Operators. Auto Increment and Decrement. Relational Operators. Testing Object Equivalence. Logical Operators. Short-Circuiting. Bitwise Operators. Shift Operators. Ternary If-Else Operator. The Comma Operator. String Operator +. Common Pitfalls When Using Operators. Casting Operators. Literals. Promotion. Java Has No "Sizeof." Precedence Revisited. A Compendium of Operators. Execution Control. True and False. If-Else. Return. Iteration. Do-While. For. The Comma Operator. Break and Continue. The Infamous "Goto." Switch. Calculation Details.4. Initialization & Cleanup.
Guaranteed Initialization with the Constructor. Method Overloading. Distinguishing Overloaded Methods. Overloading with Primitives. Overloading on Return Values. Default Constructors. The This Keyword. Calling Constructors from Constructors. The Meaning of Static. Cleanup: Finalization and Garbage Collection. What Is Finalize( ) For? You Must Perform Cleanup. The Death Condition. How a Garbage Collector Works. Member Initialization. Specifying Initialization. Constructor Initialization. Order of Initialization. Static Data Initialization. Explicit Static Initialization. Non-Static Instance Initialization. Array Initialization. Multidimensional Arrays.5. Hiding the Implementation.
Package: The Library Unit. Creating Unique Package Names. Collisions. A Custom Tool Library. Using Imports to Change Behavior. Package Caveat. Java Access Specifiers. "Friendly." Public: Interface Access. The Default Package. Private: You Can't Touch That! Protected: "Sort of Friendly." Interface and Implementation. Class Access.6. Reusing Classes.
Composition Syntax. Inheritance Syntax. Initializing the Base Class. Constructors with Arguments. Catching Base Constructor Exceptions. Combining Composition and Inheritance. Guaranteeing Proper Cleanup. Order of Garbage Collection. Name Hiding. Choosing Composition vs. Inheritance. Protected. Incremental Development. Upcasting. Why "Upcasting"? Composition vs. Inheritance Revisited. The Final Keyword. Final Data. Blank Finals. Final Arguments. Final Methods. Final and Private. Final Classes. Final Caution. Initialization and Class Loading. Initialization with Inheritance.7. Polymorphism.
Upcasting Revisited. Forgetting the Object Type. The Twist. Method-Call Binding. Producing the Right Behavior. Extensibility. Overriding vs. Overloading. Abstract Classes and Methods. Constructors and Polymorphism. Order of Constructor Calls. Inheritance and Finalize( ). Behavior of Polymorphic Methods Inside Constructors. Designing with Inheritance. Pure Inheritance vs. Extension. Downcasting and Run-Time Type Identification.8. Interfaces & Inner Classes.
Interfaces. "Multiple Inheritance" in Java. Name Collisions When Combining Interfaces. Extending an Interface with Inheritance. Grouping Constants. Initializing Fields in Interfaces. Nesting Interfaces. Inner Classes. Inner Classes and Upcasting. Inner Classes in Methods and Scopes. Anonymous Inner Classes. The Link to the Outer Class. Static Inner Classes. Referring to the Outer Class Object. Reaching Outward from a Multiply-Nested Class. Inheriting from Inner Classes. Can Inner Classes Be Overridden? Inner Class Identifiers. Why Inner Classes? Closures & Callbacks. Inner Classes & Control Frameworks.9. Holding Your Objects.
Arrays. Arrays are First-Class Objects. Containers of Primitives. Returning an Array. The Arrays Class. Filling an Array. Copying an Array. Comparing Arrays. Array Element Comparisons. Sorting an Array. Searching a Sorted Array. Array Summary. Introduction to Containers. Printing Containers. Filling Containers. Container Disadvantage: Unknown Type. Sometimes It Works Anyway. Making a Type-Conscious Arraylist. Parameterized Types. Iterators. Unintended Recursion. Container Taxonomy. Collection Functionality. List Functionality. Making a Stack from a Linkedlist. Making a Queue from a Linkedlist. Set Functionality. Sortedset. Map Functionality. Sortedmap. Hashing and Hash Codes. Understanding Hashcode( ). Hashmap Performance Factors. Overriding Hashcode( ). Holding References. The Weakhashmap. Iterators Revisited. Choosing an Implementation. Choosing between Lists. Choosing between Sets. Choosing between Maps. Sorting and Searching Lists. Utilities. Making a Collection or Map Unmodifiable. Synchronizing a Collection or Map. Fail Fast. Unsupported Operations. Java 1.0/1.1 Containers. Vector & Enumeration. Hashtable. Stack. Bitset.10. Error Handling with Exceptions.
Basic Exceptions. Exception Arguments. Catching an Exception. The Try Block. Exception Handlers. Termination vs. Resumption. Creating Your Own Exceptions. The Exception Specification. Catching Any Exception. Rethrowing an Exception. Standard Java Exceptions. The Special Case of Runtimeexception. Performing Cleanup with Finally. What's Finally For? Pitfall: The Lost Exception. Exception Restrictions. Constructors. Exception Matching. Exception Guidelines.11. The Java I/O System.
The File Class. A Directory Lister. Anonymous Inner Classes. Checking for and Creating Directories. Input and Output. Types of Inputstream. Types of Outputstream. Adding Attributes and Useful Interfaces. Reading from an Inputstream with Filterinputstream. Writing to an Outputstream with Filteroutputstream. Readers & Writers. Sources and Sinks of Data. Modifying Stream Behavior. Unchanged Classes. Off by Itself: Randomaccessfile. Typical Uses of I/O Streams. Input Streams: 1. Buffered Input File.2. Input from Memory.3. Formatted Memory Input.4. File Output. Output Streams:5. Storing and Recovering Data.6. Reading and Writing Random Access Files. A Bug? Piped Streams. Standard I/O. Reading from Standard Input. Changing System.Out to a Printwriter. Redirecting Standard I/O. Compression. Simple Compression with GZIP. Multifile Storage with Zip. Java Archives (Jars). Object Serialization. Finding the Class. Controlling Serialization. The Transient Keyword. An Alternative to Externalizable. Versioning. Using Persistence. Tokenizing Input. Streamtokenizer. Stringtokenizer. Checking Capitalization Style.12. Run-Time Type Identification.
The Need for RTTI. The Class Object. Class Literals. Checking before a Cast. Using Class Literals. A Dynamic Instanceof. Instanceof vs. Class Equivalence. RTTI Syntax. Reflection: Run-Time Class Information. A Class Method Extractor.13. Creating Windows & Applets.
The Basic Applet. Applet Restrictions. Applet Advantages. Application Frameworks. Running Applets inside a Web Browser. Using Appletviewer. Testing Applets. Running Applets From The Command Line. A Display Framework. Using the Windows Explorer. Making a Button. Capturing an Event. Text Areas. Controlling Layout. Borderlayout. Flowlayout. Gridlayout. Gridbaglayout. Absolute Positioning. Boxlayout. The Best Approach? The Swing Event Model. Event and Listener Types. Using Listener Adapters for Simplicity. Tracking Multiple Events. A Catalog of Swing Components. Buttons. Button Groups. Icons. Tool Tips. Text Fields. Borders. Jscrollpanes. A Mini-Editor. Check Boxes. Radio Buttons. Combo Boxes (Drop-Down Lists). List Boxes. Tabbed Panes. Message Boxes. Menus. Pop-Up Menus. Drawing. Dialog Boxes. File Dialogs. HTML on Swing Components. Sliders and Progress Bars. Trees. Tables. Selecting Look & Feel. The Clipboard. Packaging an Applet into a JAR File. Programming Techniques. Binding Events Dynamically. Separating Business Logic from UI Logic. A Canonical Form. Visual Programming and Beans. What Is a Bean? Extracting Beaninfo with the Introspector. A More Sophisticated Bean. Packaging a Bean. More Complex Bean Support. More to Beans.14. Multiple Threads.
Responsive User Interfaces. Inheriting from Thread. Threading for a Responsive Interface. Combining the Thread with the Main Class. Making Many Threads. Daemon Threads. Sharing Limited Resources. Improperly Accessing Resources. How Java Shares Resources. Synchronizing the Counters. Synchronized Efficiency. Javabeans Revisited. Blocking. Becoming Blocked. Sleeping. Suspending and Resuming. Wait and Notify. Blocking On I/O. Testing. Deadlock. The Deprecation of Stop( ), Suspend( ), Resume( ), and Destroy( ) in Java. Priorities. Reading and Setting Priorities. Thread Groups. Controlling Thread Groups. Runnable Revisited. Too Many Threads.15. Distributed Computing.
Network Programming. Identifying a Machine. Servers and Clients. Testing Programs without a Network. Port: A Unique Place within the Machine. Sockets. A Simple Server and Client. Serving Multiple Clients. Datagrams. Using Urls from within an Applet. Reading a File from the Server. More to Networking. Java Database Connectivity (JDBC). Getting the Example to Work. Step 1: Find the JDBC Driver. Step 2: Configure the Database. Step 3: Test the Configuration. Step 4: Generate Your SQL Query. Step 5: Modify and Paste in Your Query. A GUI Version of the Lookup Program. Why the JDBC API Seems So Complex. A More Sophisticated Example. Servlets. The Basic Servlet. Servlets and Multithreading. Handling Sessions with Servlets. The Cookie Class. The Session Class. Running the Servlet Examples. Java Server Pages. Implicit Objects. JSP Directives. JSP Scripting Elements. Extracting Fields and Values. JSP Page Attributes and Scope. Manipulating Sessions in JSP. Creating and Modifying Cookies. JSP Summary. RMI (Remote Method Invocation). Remote Interfaces. Implementing the Remote Interface. Setting Up the Registry. Creating Stubs and Skeletons. Using the Remote Object. CORBA. CORBA Fundamentals. CORBA Interface Definition Language (IDL). The Naming Service. An Example. Writing The IDL Source. Creating Stubs and Skeletons. Implementing the Server and the Client. Some CORBA Services. Activating the Name Service Process. Activating the Server and the Client. Java Applets and CORBA. CORBA vs. RMI. Enterprise Javabeans. Javabeans vs. Ejbs. The EJB Specification. EJB Components. EJB Container & Server. Java Naming and Directory Interface (JNDI). Java Transaction API/Java Transaction Service (JTA/JTS). CORBA and RMI/IIOP. The Pieces of an EJB Component. Enterprise Bean. Home Interface. Remote Interface. Deployment Descriptor. EJB-Jar File. EJB Operation. Types of Ejbs. Session Beans. Entity Beans. Developing an EJB. EJB Summary. Jini: Distributed Services. Jini in Context. What Is Jini? How Jini Works. The Discovery Process. The Join Process. The Lookup Process. Separation of Interface and Implementation. Abstracting Distributed Systems.Appendix A: Passing & Returning Objects.
Passing References Around. Aliasing. Making Local Copies. Pass by Value. Cloning Objects. Adding Cloneability to a Class. Using a Trick with Protected. Implementing the Cloneable Interface. Successful Cloning. The Effect of Object.Clone( ). Cloning a Composed Object. A Deep Copy with Arraylist. Deep Copy via Serialization. Adding Cloneability Further Down a Hierarchy. Why This Strange Design? Controlling Cloneability. The Copy Constructor. Why Does It Work in C++ and Not Java? Read-Only Classes. Creating Read-Only Classes. The Drawback to Immutability. Immutable Strings. Implicit Constants. Overloading `+' and the Stringbuffer. The String and Stringbuffer Classes. Strings are Special.Appendix B: The Java Native Interface (JNI).
Calling a Native Method. The Header File Generator: Javah. Name Mangling and Function Signatures. Implementing Your DLL. Accessing JNI Functions: The Jnienv Argument. Accessing Java Strings. Passing and Using Java Objects. JNI and Java Exceptions. JNI and Threading. Using a Preexisting Code Base. Additional Information.Appendix C: Java Programming Guidelines.
Design. Implementation.Appendix D: Resources.
Software. Books. Analysis & Design. Python. My Own List of Books.Index.