Thinking in C# Larry O’Brien and Bruce Eckel Thinking in C# Larry O’Brien and Bruce Eckel Prentice Hall Upper Saddle River, New Jersey 07458 www.phptr.com Overview Introduction 1: Those Who Can, Code 15 2: Introduction to Objects 15 3: Hello, Objects 51 4: Controlling Program Flow89 5: Initialization & Cleanup151 6: Coupling and Cohesion215 6a: Hiding the Implementation 7: Reusing classes 250 8: Interfaces and Implementation 8a: Interfaces 234 295 333 9: Collecting Your Objects391 10: Error Handling With Exceptions 11: I/O in C# 483 521 12: Reflection and Attributes559 13: Programming Windows Forms 14: GDI+ Overview 589 707 14: Multithreaded Programming 15: XML 751 16: Web Services 753 713 A: C# For Java Programmers 755 B: C# For Visual Basic Programmers 757 C: C# Programming Guidelines D: Resources 771 Index 771 759 What’s Inside Introduction Prerequisites Learning C# Goals Online documentation Chapters .6 Exercises Source code 10 Coding standards 12 C# versions 12 Seminars and mentoring 12 Errors 12 Note on the cover design 13 Acknowledgements 13 Internet contributors 13 1: Those Who Can, Code 15 2: Introduction to Objects 15 The progress of abstraction16 An object has an interface 19 An object provides services22 The hidden implementation22 Reusing the implementation24 Inheritance: reusing the interface 25 Is-a vs is-like-a relationships 29 Interchangeable objects with polymorphism 31 Abstract base classes and interfaces35 Object landscapes and lifetimes .36 Collections and iterators 37 The singly rooted hierarchy 39 Collection libraries and support for easy collection use 40 The housekeeping dilemma: who should clean up? 41 Exception handling: dealing with errors 43 Multithreading 44 Persistence .45 C# and the Internet 45 What is the Web? 46 Client-side programming .46 Server-side programming 46 A separate arena: applications .46 Analysis and design 47 Extreme programming 47 Why NET succeeds 47 Systems are easier to express and understand 47 Maximal leverage with libraries 47 Error handling 47 Programming in the large 47 Strategies for transition 48 The Common Language Runtime 77 Guidelines 48 Comments and embedded documentation 81 Management obstacles 50 C# vs Java? .50 Summary 50 3: Hello, Objects 51 Documentation Comments 82 Documentation example 85 Coding style .86 Summary 87 Exercises 87 You manipulate objects with references 51 You must create all the objects 52 4: Controlling Program Flow 89 Where storage lives 53 Using C#operators 89 Arrays in Java 54 Precedence 90 Special case: value types 55 Assignment 90 You never need to destroy an object 56 Scoping 56 Scope of objects 57 Creating new data types: class 58 Fields, Properties, and methods 59 Methods, arguments, and return values 61 C#’s Preprocessor 115 foreach 135 5: Initialization & Cleanup 151 Guaranteed initialization with the constructor 151 Method overloading 154 Distinguishing overloaded methods156 The argument list 62 Overloading with primitives 157 Attributes and MetaBehavior 64 Delegates 64 Properties 65 Creating New Value Types 67 Overloading on return values 162 Cleanup: finalization and garbage collection 169 Enumerations 67 What are destructors for? 171 Structs 68 Instead of a destructor, use Close() Building a C# program 69 Default constructors 162 The this keyword 163 or Dispose() 172 Name visibility 69 Destructors, Dispose(), and the Using other components 70 using keyword 177 The static keyword 71 The death condition 182 Putting It All Together 73 How a garbage collector works 183 Compiling and running 76 Member initialization 185 Fine-tuning Compilation 77 Specifying initialization 187 Constructor initialization 188 Array initialization 195 Multidimensional arrays 200 Sidebar/Appendix: What a difference a rectangle makes 203 Summary 213 Exercises 214 6: Coupling and Cohesion 215 Software As Architecture vs Software Architecture 217 What Is Software Architecture 219 Simulation Architectures: Always Taught, Rarely Used219 Client/Server and n-Tier Architectures 220 Layered Architectures .222 Problem-Solving Architectures 223 Dispatching Architectures223 “Not Really Object-Oriented”224 Design Is As Design Does224 First, Do No Harm 225 Design Rule #1: Write Boring Code .226 Design Is As Design Does234 6a: Hiding the Implementation 234 The namespace unit 235 Creating unique package names 236 Using imports to change behavior239 C#’s access specifiers 240 Interface and implementation .245 Class access 246 Summary 249 Exercises 250 7: Reusing classes 250 Composition syntax 251 Inheritance syntax 255 Initializing the base class 258 Combining composition and inheritance 261 Guaranteeing proper cleanup 263 Choosing composition vs inheritance .267 protected 269 Incremental development270 Upcasting .270 Why “upcasting”? 272 Explicit Overloading Only 273 The const and readonly keywords 286 Sealed classes 289 Emphasize virtual functions 290 Initialization and class loading 291 Initialization with inheritance 291 Summary 293 Exercises 294 8: Interfaces and Implementation 295 Upcasting revisited 297 Forgetting the object type 299 “Friendly” 240 The twist 301 public: interface access .241 Method-call binding 301 private: you can’t touch that! 242 Producing the right behavior .303 protected: “sort of friendly” 244 Extensibility 306 Overriding vs overloading310 Operator Overloading 311 Abstract classes and methods 311 Constructors and polymorphism 317 Order of constructor calls 317 Behavior of polymorphic methods inside constructors 320 Designing with inheritance322 Pure inheritance vs extension 324 Downcasting and run-time type identification 326 Summary 331 Exercises 331 8a: Interfaces 333 Interfaces 333 “Multiple inheritance” in Java 338 Extending an interface with inheritance 342 Doesn’t work in C# Must have section on enums and structs earlier343 Inner classes & control frameworks378 Summary 387 Exercises 387 9: Collecting Your Objects 391 Arrays 391 Arrays are first-class objects 393 The Array class 397 Array’s Static Methods .398 Array element comparisons 401 What? No bubbles? 403 Unsafe Arrays .405 Get things right… 409 … Then Get Them Fast 413 Array summary 420 Introduction to data structures 420 Queues and Stacks 421 ArrayList 424 BitArray 426 Dictionaries .428 Initializing fields in interfaces 346 Hashtable 428 Nesting interfaces 347 ListDictionary 431 Inner classes 350 SortedList 432 Inner classes and upcasting 352 String specialists .433 Inner classes in methods and One Key, Multiple Values 433 scopes 355 Customizing Hashcode Providers434 Reaching outward from a multiply- String specialists: StringCollection and StringDictionary 436 Container disadvantage: unknown type 437 nested class 367 Using CollectionBase to make Inheriting from inner classes 368 type-conscious collections 440 Can inner classes be overridden?369 IEnumerators 442 Custom Indexers .444 Anonymous inner classes 357 The link to the outer class 361 static inner classes 363 Referring to the outer class object366 Inner class identifiers 372 Why inner classes? 372 Custom Enumerators & Data Structures 448 Sorting and searching Lists454 From Collections to Arrays456 Persistent Data With ADO.NET .463 Getting a handle on data with DataSet 464 Connecting to a database 468 Fast Reading With an IDataReader472 CRUD With ADO.NET 473 Update and Delete 474 The Object-Relational Impedance Mismatch 479 Summary 480 Exercises 481 10: Error Handling With Exceptions 483 Constructors 512 Exception matching 516 Exception guidelines 518 Summary 518 @todo – New Chapter? Design By Contract 519 Exercises 519 11: I/O in C# 521 File, Directory, and Path521 A directory lister 521 Checking for and creating directories 523 Isolated Stores 525 Input and output .526 Types of Stream 527 Text and Binary 528 Working With Different Sources 529 Fun With CryptoStreams 532 Basic exceptions 487 BinaryReader and BinaryWriter 536 Exception arguments 488 StreamReader and StreamWriter541 The try block 489 Random access with Seek544 Standard I/O 546 Exception handlers 490 Reading from standard input 546 Exceptions have a helplink 491 Redirecting standard I/O 547 Creating your own exceptions 491 C#’s Lack Of Checked Exceptions .497 Regular Expressions 548 Catching an exception .489 Catching any exception 499 Rethrowing an exception 499 Elevating the abstraction level 500 Standard C# exceptions 502 Performing cleanup with finally .503 What’s finally for? 505 Finally and using 508 Pitfall: the lost exception 509 Checking capitalization style 553 Summary 557 Exercises 557 12: Reflection and Attributes 559 The need for RTTI 559 The Class object 562 Checking before a cast 565 RTTI syntax 574 Reflection: run-time class information 577 A class method extractor 579 71 If your class requires any cleanup when the client programmer is finished with the object, make your class implement IDisposable tk 72 When you are creating a fixed-size container of objects, transfer them to an array—especially if you’re returning this container from a method This way you get the benefit of the array’s compile-time type checking, and the recipient of the array might not need to cast the objects in the array in order to use them 73 Choose interfaces over abstract classes If you know something is going to be a base class, your first choice should be to make it an interface, and only if you’re forced to have method definitions or member variables should you change it to an abstract class An interface talks about what the client wants to do, while a class tends to focus on (or allow) implementation details 74 Inside constructors, only what is necessary to set the object into the proper state Actively avoid calling other methods (except for final methods) since those methods can be overridden by someone else to produce unexpected results during construction (See Chapter for details.) Smaller, simpler constructors are less likely to throw exceptions or cause problems 75 Watch out for accidental overloading If you attempt to override a base-class method and you don’t quite get the spelling right, you’ll end up adding a new method rather than overriding an existing method However, this is perfectly legal, so you won’t get any error message from the compiler or run-time system—your code simply won’t work correctly 76 Watch out for premature optimization First make it work, then make it fast—but only if you must, and only if it’s proven that there is a performance bottleneck in a particular section of your code Unless you have used a profiler to discover a bottleneck, you will probably be wasting your time The hidden cost of performance tweaks is that your code becomes less understandable and maintainable 77 Remember that code is read much more than it is written Clean designs make for easy-to-understand programs, but comments, 770 Thinking in C# www.ThinkingIn.Net detailed explanations, and examples are invaluable They will help both you and everyone who comes after you If nothing else, the frustration of trying to ferret out useful information from the online Java documentation should convince you D: Resources Software tk Books C# tk Analysis & design tk Management & Process tk Index Please note that some names will be duplicated in capitalized form Following C# style, the capitalized names refer to C# classes, while lowercase names refer to a general concept.Error! No index entries found Appendix C: Java Programming Guidelines 771 772 Check www.BruceEckel.com for in-depth details and the date and location of the next Hands-On Java Seminar • Based on this book • Taught by Bruce Eckel • Personal attention from Bruce Eckel and his seminar assistants • Includes in-class programming exercises • Intermediate/Advanced seminars also offered • Hundreds have already enjoyed this seminar— see the Web site for their testimonials 773 Bruce Eckel’s Hands-On Java Seminar Multimedia CD It’s like coming to the seminar! Available at www.BruceEckel.com ¾ The Hands-On Java Seminar captured on a Multimedia CD! ¾ Overhead slides and synchronized audio voice narration for all the lectures Just play it to see and hear the lectures! ¾ Created and narrated by Bruce Eckel ¾ Based on the material in this book ¾ Demo lecture available at www.BruceEckel.com 774 End-User License Agreement for Microsoft Software IMPORTANT-READ CAREFULLY: This Microsoft End-User License Agreement ("EULA") is a legal agreement between you (either an individual or a single entity) and Microsoft Corporation for the Microsoft software product included in this package, which includes computer software and may include associated media, printed materials, and "online" or electronic documentation ("SOFTWARE PRODUCT") The SOFTWARE PRODUCT also includes any updates and supplements to the original SOFTWARE PRODUCT provided to you by Microsoft By installing, copying, downloading, accessing or otherwise using the SOFTWARE PRODUCT, you agree to be bound by the terms of this EULA If you not agree to the terms of this EULA, not install, copy, or otherwise use the SOFTWARE PRODUCT SOFTWARE PRODUCT LICENSE The SOFTWARE PRODUCT is protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties The SOFTWARE PRODUCT is licensed, not sold GRANT OF LICENSE This EULA grants you the following rights: 1.1 License Grant Microsoft grants to you as an individual, a personal nonexclusive license to make and use copies of the SOFTWARE PRODUCT for the sole purposes of evaluating and learning how to use the SOFTWARE PRODUCT, as may be instructed in accompanying publications or documentation You may install the software on an unlimited number of computers provided that you are the only individual using the SOFTWARE PRODUCT 1.2 Academic Use You must be a "Qualified Educational User" to use the SOFTWARE PRODUCT in the manner described in this section To determine whether you are a Qualified Educational User, please contact the Microsoft Sales Information Center/One Microsoft Way/Redmond, WA 98052-6399 or the Microsoft subsidiary serving your country If you are a Qualified Educational User, you may either: (i) exercise the rights granted in Section 1.1, OR (ii) if you intend to use the SOFTWARE PRODUCT solely for instructional purposes in connection with a class or other educational program, this EULA grants you the following alternative license models: (A) Per Computer Model For every valid license you have acquired for the SOFTWARE PRODUCT, you may install a single copy of the SOFTWARE PRODUCT on a single computer for access and use by an unlimited number of 775 student end users at your educational institution, provided that all such end users comply with all other terms of this EULA, OR (B) Per License Model If you have multiple licenses for the SOFTWARE PRODUCT, then at any time you may have as many copies of the SOFTWARE PRODUCT in use as you have licenses, provided that such use is limited to student or faculty end users at your educational institution and provided that all such end users comply with all other terms of this EULA For purposes of this subsection, the SOFTWARE PRODUCT is "in use" on a computer when it is loaded into the temporary memory (i.e., RAM) or installed into the permanent memory (e.g., hard disk, CD ROM, or other storage device) of that computer, except that a copy installed on a network server for the sole purpose of distribution to other computers is not "in use" If the anticipated number of users of the SOFTWARE PRODUCT will exceed the number of applicable licenses, then you must have a reasonable mechanism or process in place to ensure that the number of persons using the SOFTWARE PRODUCT concurrently does not exceed the number of licenses DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS • Limitations on Reverse Engineering, Decompilation, and Disassembly You may not reverse engineer, decompile, or disassemble the SOFTWARE PRODUCT, except and only to the extent that such activity is expressly permitted by applicable law notwithstanding this limitation • Separation of Components The SOFTWARE PRODUCT is licensed as a single product Its component parts may not be separated for use on more than one computer • Rental You may not rent, lease or lend the SOFTWARE PRODUCT • Trademarks This EULA does not grant you any rights in connection with any trademarks or service marks of Microsoft • Software Transfer The initial user of the SOFTWARE PRODUCT may make a one-time permanent transfer of this EULA and SOFTWARE PRODUCT only directly to an end user This transfer must include all of the SOFTWARE PRODUCT (including all component parts, the media and printed materials, any upgrades, this EULA, and, if applicable, the Certificate of Authenticity) Such transfer may not be by way of consignment or any other indirect transfer The transferee of such one-time transfer must agree to comply with the terms of this EULA, including the obligation not to further transfer this EULA and SOFTWARE PRODUCT • No Support Microsoft shall have no obligation to provide any product support for the SOFTWARE PRODUCT • Termination Without prejudice to any other rights, Microsoft may terminate this EULA if you fail to comply with the terms and conditions of this EULA In 776 such event, you must destroy all copies of the SOFTWARE PRODUCT and all of its component parts COPYRIGHT All title and intellectual property rights in and to the SOFTWARE PRODUCT (including but not limited to any images, photographs, animations, video, audio, music, text, and "applets" incorporated into the SOFTWARE PRODUCT), the accompanying printed materials, and any copies of the SOFTWARE PRODUCT are owned by Microsoft or its suppliers All title and intellectual property rights in and to the content which may be accessed through use of the SOFTWARE PRODUCT is the property of the respective content owner and may be protected by applicable copyright or other intellectual property laws and treaties This EULA grants you no rights to use such content All rights not expressly granted are reserved by Microsoft BACKUP COPY After installation of one copy of the SOFTWARE PRODUCT pursuant to this EULA, you may keep the original media on which the SOFTWARE PRODUCT was provided by Microsoft solely for backup or archival purposes If the original media is required to use the SOFTWARE PRODUCT on the COMPUTER, you may make one copy of the SOFTWARE PRODUCT solely for backup or archival purposes Except as expressly provided in this EULA, you may not otherwise make copies of the SOFTWARE PRODUCT or the printed materials accompanying the SOFTWARE PRODUCT U.S GOVERNMENT RESTRICTED RIGHTS The SOFTWARE PRODUCT and documentation are provided with RESTRICTED RIGHTS Use, duplication, or disclosure by the Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 or subparagraphs (c)(1) and (2) of the Commercial Computer Software-Restricted Rights at 48 CFR 52.227-19, as applicable Manufacturer is Microsoft Corporation/One Microsoft Way/Redmond, WA 98052-6399 EXPORT RESTRICTIONS You agree that you will not export or re-export the SOFTWARE PRODUCT, any part thereof, or any process or service that is the direct product of the SOFTWARE PRODUCT (the foregoing collectively referred to as the "Restricted Components"), to any country, person, entity or end user subject to U.S export restrictions You specifically agree not to export or reexport any of the Restricted Components (i) to any country to which the U.S has embargoed or restricted the export of goods or services, which currently include, but are not necessarily limited to Cuba, Iran, Iraq, Libya, North Korea, Sudan and Syria, or to any national of any such country, wherever located, who intends to transmit or transport the Restricted Components back to such country; (ii) to any end-user who you know or have reason to know will utilize the Restricted Components in the design, development or production of nuclear, chemical or biological weapons; or (iii) to any end-user who has been 777 prohibited from participating in U.S export transactions by any federal agency of the U.S government You warrant and represent that neither the BXA nor any other U.S federal agency has suspended, revoked, or denied your export privileges NOTE ON JAVA SUPPORT THE SOFTWARE PRODUCT MAY CONTAIN SUPPORT FOR PROGRAMS WRITTEN IN JAVA JAVA TECHNOLOGY IS NOT FAULT TOLERANT AND IS NOT DESIGNED, MANUFACTURED, OR INTENDED FOR USE OR RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF JAVA TECHNOLOGY COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE MISCELLANEOUS If you acquired this product in the United States, this EULA is governed by the laws of the State of Washington If you acquired this product in Canada, this EULA is governed by the laws of the Province of Ontario, Canada Each of the parties hereto irrevocably attorns to the jurisdiction of the courts of the Province of Ontario and further agrees to commence any litigation which may arise hereunder in the courts located in the Judicial District of York, Province of Ontario If this product was acquired outside the United States, then local law may apply Should you have any questions concerning this EULA, or if you desire to contact Microsoft for any reason, please contact Microsoft, or write: Microsoft Sales Information Center/One Microsoft Way/Redmond, WA 98052-6399 LIMITED WARRANTY LIMITED WARRANTY Microsoft warrants that (a) the SOFTWARE PRODUCT will perform substantially in accordance with the accompanying written materials for a period of ninety (90) days from the date of receipt, and (b) any Support Services provided by Microsoft shall be substantially as described in applicable written materials provided to you by Microsoft, and Microsoft support engineers will make commercially reasonable efforts to solve any problem To the extent allowed by applicable law, implied warranties on the SOFTWARE PRODUCT, if any, are limited to ninety (90) days Some states/jurisdictions 778 not allow limitations on duration of an implied warranty, so the above limitation may not apply to you CUSTOMER REMEDIES Microsoft's and its suppliers' entire liability and your exclusive remedy shall be, at Microsoft's option, either (a) return of the price paid, if any, or (b) repair or replacement of the SOFTWARE PRODUCT that does not meet Microsoft's Limited Warranty and that is returned to Microsoft with a copy of your receipt This Limited Warranty is void if failure of the SOFTWARE PRODUCT has resulted from accident, abuse, or misapplication Any replacement SOFTWARE PRODUCT will be warranted for the remainder of the original warranty period or thirty (30) days, whichever is longer Outside the United States, neither these remedies nor any product support services offered by Microsoft are available without proof of purchase from an authorized international source NO OTHER WARRANTIES TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND ITS SUPPLIERS DISCLAIM ALL OTHER WARRANTIES AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT, WITH REGARD TO THE SOFTWARE PRODUCT, AND THE PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL RIGHTS YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO STATE/JURISDICTION LIMITATION OF LIABILITY TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL MICROSOFT OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE PRODUCT OR THE FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF MICROSOFT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES IN ANY CASE, MICROSOFT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS EULA SHALL BE LIMITED TO THE GREATER OF THE AMOUNT ACTUALLY PAID BY YOU FOR THE SOFTWARE PRODUCT OR U.S.$5.00; PROVIDED, HOWEVER, IF YOU HAVE ENTERED INTO A MICROSOFT SUPPORT SERVICES AGREEMENT, MICROSOFT'S ENTIRE LIABILITY REGARDING SUPPORT SERVICES SHALL BE GOVERNED BY THE TERMS OF THAT AGREEMENT BECAUSE SOME STATES/JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY, THE ABOVE LIMITATION MAY NOT APPLY TO YOU 0495 Part No 64358 779 LICENSE AGREEMENT FOR MindView, Inc.'s Thinking in C: Foundations for Java & C++ CD ROM by Chuck Allison This CD is provided together with the book "Thinking in Java, 2nd edition." READ THIS AGREEMENT BEFORE USING THIS "Thinking in C: Foundations for C++ & Java" (Hereafter called "CD") BY USING THE CD YOU AGREE TO BE BOUND BY THE TERMS AND CONDITIONS OF THIS AGREEMENT IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT, IMMEDIATELY RETURN THE UNUSED CD FOR A FULL REFUND OF MONIES PAID, IF ANY ©2000 MindView, Inc All rights reserved Printed in the U.S SOFTWARE REQUIREMENTS The purpose of this CD is to provide the Content, not the associated software necessary to view the Content The Content of this CD is in HTML for viewing with Microsoft Internet Explorer or newer, and uses Microsoft Sound Codecs available in Microsoft's Windows Media Player for Windows It is your responsibility to correctly install the appropriate Microsoft software for your system The text, images, and other media included on this CD ("Content") and their compilation are licensed to you subject to the terms and conditions of this Agreement by MindView, Inc., having a place of business at 5343 Valle Vista, La Mesa, CA 91941 Your rights to use other programs and materials included on the CD are also governed by separate agreements distributed with those programs and materials on the CD (the "Other Agreements") In the event of any inconsistency between this Agreement and the Other Agreements, this Agreement shall govern By using this CD, you agree to be bound by the terms and conditions of this Agreement MindView, Inc owns title to the Content and to all intellectual property rights therein, except insofar as it contains materials that are proprietary to third-party suppliers All rights in the Content except those expressly granted to you in this Agreement are reserved to MindView, Inc and such suppliers as their respective interests may appear LIMITED LICENSE MindView, Inc grants you a limited, nonexclusive, nontransferable license to use the Content on a single dedicated computer (excluding network servers) This Agreement and your rights hereunder shall automatically terminate if you fail to comply with any provisions of this Agreement or any of the Other Agreements Upon such termination, you agree to destroy the CD and all copies of the CD, whether lawful or not, that are in your possession or under your control ADDITIONAL RESTRICTIONS a You shall not (and shall not permit other persons or entities to) directly or indirectly, by electronic or other means, reproduce (except for archival purposes as permitted by law), publish, distribute, rent, lease, sell, sublicense, assign, or otherwise transfer the Content or any part thereof b You shall not (and shall not permit other persons or entities to) use the Content or any part thereof for any commercial purpose or merge, modify, create derivative works of, or translate the Content c You shall not (and shall not permit other persons or entities to) obscure MindView's or its suppliers copyright, trademark, or other proprietary notices or legends from any portion of the Content or any related materials PERMISSIONS a Except as noted in the Contents of the CD, you must treat this software just like a book However, you may copy it onto a computer to be used and you may make archival copies of the software for the sole purpose of backing up the software and protecting your investment from loss By saying, "just like a book," MindView, Inc means, for example, that this software may be used by any number of people and may be freely moved from one computer location to another, so long as there is no possibility of its being used at one location or on one computer while it is being used at another Just as a book cannot be read by two different people in two different places at the same time, neither can the software be used by two different people in two different places at the same time b You may show or demonstrate the un-modified Content in a live presentation, live seminar, or live performance as long as you attribute all material of the Content to MindView, Inc c Other permissions and grants of rights for use of the CD must be obtained directly from MindView, Inc at http://www.MindView.net (Bulk copies of the CD may also be purchased at this site.) DISCLAIMER OF WARRANTY The Content and CD are provided "AS IS" without warranty of any kind, either express or implied, including, without limitation, any warranty of 781 merchantability and fitness for a particular purpose The entire risk as to the results and performance of the CD and Content is assumed by you MindView, Inc and its suppliers assume no responsibility for defects in the CD, the accuracy of the Content, or omissions in the CD or the Content MindView, Inc and its suppliers not warrant, guarantee, or make any representations regarding the use, or the results of the use, of the product in terms of correctness, accuracy, reliability, currentness, or otherwise, or that the Content will meet your needs, or that operation of the CD will be uninterrupted or error-free, or that any defects in the CD or Content will be corrected MindView, Inc and its suppliers shall not be liable for any loss, damages, or costs arising from the use of the CD or the interpretation of the Content Some states not allow exclusion or limitation of implied warranties or limitation of liability for incidental or consequential damages, so all of the above limitations or exclusions may not apply to you In no event shall MindView, Inc or its suppliers' total liability to you for all damages, losses, and causes of action (whether in contract, tort, or otherwise) exceed the amount paid by you for the CD MindView, Inc., and Prentice-Hall, Inc specifically disclaim the implied warrantees of merchantability and fitness for a particular purpose No oral or written information or advice given by MindView, Inc., Prentice-Hall, Inc., their dealers, distributors, agents or employees shall create a warrantee You may have other rights, which vary from state to state Neither MindView, Inc., Bruce Eckel, Chuck Allison, Prentice-Hall, nor anyone else who has been involved in the creation, production or delivery of the product shall be liable for any direct, indirect, consequential, or incidental damages (including damages for loss of business profits, business interruption, loss of business information, and the like) arising out of the use of or inability to use the product even if MindView, Inc., has been advised of the possibility of such damages Because some states not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation may not apply to you This CD is provided as a supplement to the book "Thinking in Java 2nd edition." The sole responsibility of Prentice-Hall will be to provide a replacement CD in the event that the one that came with the book is defective This replacement warrantee shall be in effect for a period of sixty days from the purchase date MindView, Inc does not bear any additional responsibility for the CD NO TECHNICAL SUPPORT IS PROVIDED WITH THIS CD ROM The following are trademarks of their respective companies in the U.S and may be protected as trademarks in other countries: Sun and the Sun Logo, Sun Microsystems, Java, all Java-based names and logos and the Java Coffee Cup are trademarks of Sun Microsystems; Internet Explorer, the Windows Media Player, DOS, Windows 95, and Windows NT are trademarks of Microsoft 783 Thinking in C: Foundations for Java & C++ Multimedia Seminar-on-CD ROM ©2000 MindView, Inc All rights reserved WARNING: BEFORE OPENING THE DISC PACKAGE, CAREFULLY READ THE TERMS AND CONDITIONS OF THE LICENSE AGREEMENT & WARANTEE LIMITATION ON THE PREVIOUS PAGES The CD ROM packaged with this book is a multimedia seminar consisting of synchronized slides and audio lectures The goal of this seminar is to introduce you to the aspects of C that are necessary for you to move on to C++ or Java, leaving out the unpleasant parts that C programmers must deal with on a day-to-day basis but that the C++ and Java languages steer you away from The CD also contains this book in HTML form along with the source code for the book This CD ROM will work with Windows (with a sound system) However, you must: Install the most recent version of Microsoft’s Internet Explorer Because of the features provided on the CD, it will NOT work with Netscape Navigator The Internet Explorer software for Windows 9X/NT is included on the CD Install Microsoft’s Windows Media Player The Media Player software for Windows 9X/NT is included on the CD You can also go to http://www.microsoft.com/windows/mediaplayer and follow the instructions or links there to download and install the Media Player for your particular platform At this point you should be able to play the lectures on the CD Using the Internet Explorer Web browser, open the file Install.html that you’ll find on the CD This will introduce you to the CD and provide further instructions about the use of the CD ... begins by introducing the constructor, which guarantees proper initialization The definition of the Thinking in C# www.ThinkingIn.Net constructor leads into the concept of function overloading... source Except in classroom situations, you cannot copy and distribute this code; instead, the sole 10 Thinking in C# www.ThinkingIn.Net distribution point is http://www.thinkingin.net (and official... algorithmic,” respectively) PROLOG casts all problems into chains of decisions Languages have been created for constraint-based 16 Thinking in C# www.ThinkingIn.Net programming and for programming exclusively