Register your product to gain access to bonus material or receive a coupon.
The Definitive Introduction to Object-Oriented Programming in the Language of the World-Wide Web
Full text updates and code at HTTP://WWW.BRUCEECKEL.COM
JavaWorld Reader's Choice Award for best book, 2000
Java Developer's Journal Editor's Choice Award for best book, 1999
Software Development Magazine Productivity Award, 1999
From the fundamentals of Java syntax to its most advanced features (distributed computing, advanced object-oriented capabilities, multithreading), "Thinking in Java" is designed to teach. Bruce Eckel's readable style and small, direct programming examples make even the most arcane concepts clear.
What People Are Saying: "The best book on Java... Your depth is amazing," "Definitely the thinking person's choice in a Java book," "One of the absolutely best programming tutorials I've seen, for any language."
Click here for a sample chapter for this book: 0130273635.pdf
(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++?
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Design. Implementation.
Software. Books. Analysis & Design. Python. My Own List of Books.
I suggested to my brother Todd,who is making the leap from hardware into programming, that the next bigrevolution will be in genetic engineering.
We'll have microbes designed tomake food, fuel, and plastic; they'll clean up pollution and in generalallow us to master the manipulation of the physical world for a fraction of whatit costs now. I claimed that it would make the computer revolution look small incomparison.
Then I realized I was making a mistakecommon to science fiction writers: getting lost in the technology (which is ofcourse easy to do in science fiction). An experienced writer knows that thestory is never about the things; it's about the people. Genetics will havea very large impact on our lives, but I'm not so sure it will dwarf thecomputer revolution (which enables the genetic revolution)or at least theinformation revolution. Information is about talking to each other: yes, carsand shoes and especially genetic cures are important, but in the end those arejust trappings. What truly matters is how we relate to the world. And so much ofthat is about communication.
This book is a case in point. A majorityof folks thought I was very bold or a little crazy to put the entire thing up onthe Web. "Why would anyone buy it?" they asked. If I had been of amore conservative nature I wouldn't have done it, but I reallydidn't want to write another computer book in the same old way. Ididn't know what would happen but it turned out to be the smartest thingI've ever done with a book.
For one thing, people started sending incorrections. This has been an amazing process, because folks have looked intoevery nook and cranny and caught both technical and grammatical errors, andI've been able to eliminate bugs of all sorts that I know would haveotherwise slipped through. People have been simply terrific about this, veryoften saying "Now, I don't mean this in a critical way..." andthen giving me a collection of errors I'm sure I never would have found. Ifeel like this has been a kind of group process and it has really made the bookinto something special.
But then I started hearing "OK,fine, it's nice you've put up an electronic version, but I want aprinted and bound copy from a real publisher." I tried very hard to makeit easy for everyone to print it out in a nice looking format but thatdidn't stem the demand for the published book. Most people don'twant to read the entire book on screen, and hauling around a sheaf of papers, nomatter how nicely printed, didn't appeal to them either. (Plus, I thinkit's not so cheap in terms of laser printer toner.) It seems that thecomputer revolution won't put publishers out of business, after all.However, one student suggested this may become a model for future publishing:books will be published on the Web first, and only if sufficient interestwarrants it will the book be put on paper. Currently, the great majority of allbooks are financial failures, and perhaps this new approach could make thepublishing industry more profitable.
This book became an enlighteningexperience for me in another way. I originally approached Java as "justanother programming language," which in many senses it is. But as timepassed and I studied it more deeply, I began to see that the fundamentalintention of this language is different from all the other languages I haveseen.
Programming is about managing complexity:the complexity of the problem you want to solve, laid upon the complexity of themachine in which it is solved. Because of this complexity, most of ourprogramming projects fail. And yet, of all the programming languages of which Iam aware, none of them have gone all-out and decided that their main design goalwould be to conquer the complexity of developing and maintainingprograms.1 Ofcourse, many language design decisions were made with complexity in mind, but atsome point there were always some other issues that were considered essential tobe added into the mix. Inevitably, those other issues are what cause programmersto eventually "hit the wall" with that language. For example, C++had to be backwards-compatible with C (to allow easy migration for Cprogrammers), as well as efficient. Those are both very useful goals and accountfor much of the success of C++, but they also expose extra complexity thatprevents some projects from being finished (certainly, you can blame programmersand management, but if a language can help by catching your mistakes, whyshouldn't it?). As another example, Visual Basic (VB) was tied to BASIC,which wasn't really designed to be an extensible language, so all theextensions piled upon VB have produced some truly horrible and unmaintainablesyntax. Perl is backwards-compatible with Awk, Sed, Grep, and other Unix toolsit was meant to replace, and as a result is often accused of producing"write-only code" (that is, after a few months you can't readit). On the other hand, C++, VB, Perl, and other languages like Smalltalk hadsome of their design efforts focused on the issue of complexity and as a resultare remarkably successful in solving certain types of problems.
What has impressed me most as I have cometo understand Java is what seems like an unflinching goal of reducing complexityfor the programmer. As if to say "we don't care aboutanything except reducing the time and difficulty of producing robustcode." In the early days, this goal has resulted in code thatdoesn't run very fast (although there have been many promises made abouthow quickly Java will someday run) but it has indeed produced amazing reductionsin development time; half or less of the time that it takes to create anequivalent C++ program. This result alone can save incredible amounts of timeand money, but Java doesn't stop there. It goes on to wrap all the complextasks that have become important, such as multithreading and networkprogramming, in language features or libraries that can at times make thosetasks trivial. And finally, it tackles some really big complexity problems:cross-platform programs, dynamic code changes, and even security, each of whichcan fit on your complexity spectrum anywhere from "impediment" to"show-stopper." So despite the performance problems we'veseen, the promise of Java is tremendous: it can make us significantly moreproductive programmers.
One of the places I see the greatestimpact for this is on the Web. Network programming has always been hard, andJava makes it easy (and the Java language designers are working on making iteven easier). Network programming is how we talk to each other more effectivelyand cheaper than we ever have with telephones (email alone has revolutionizedmany businesses). As we talk to each other more, amazing things begin to happen,possibly more amazing even than the promise of geneticengineering.
In all ways—creating the programs,working in teams to create the programs, building user interfaces so theprograms can communicate with the user, running the programs on different typesof machines, and easily writing programs that communicate across theInternet—Java increases the communication bandwidth between people.I think that perhaps the results of the communication revolution will not beseen from the effects of moving large quantities of bits around; we shall seethe true revolution because we will all be able to talk to each other moreeasily: one-on-one, but also in groups and, as a planet. I've heard it suggestedthat the next revolution is the formation of a kind of global mind that resultsfrom enough people and enough interconnectedness. Java may or may not be thetool that foments that revolution, but at least the possibility has made me feellike I'm doing something meaningful by attempting to teach thelanguage.
People have made many, many wonderfulcomments about the first edition of this book, which has naturally been verypleasant for me. However, every now and then someone will have complaints, andfor some reason one complaint that comes up periodically is "the book istoo big." In my mind it is faint damnation indeed if "too manypages" is your only complaint. (One is reminded of the Emperor ofAustria's complaint about Mozart's work: "Too manynotes!" Not that I am in any way trying to compare myself to Mozart.) Inaddition, I can only assume that such a complaint comes from someone who is yetto be acquainted with the vastness of the Java language itself, and has not seenthe rest of the books on the subject—for example, my favorite reference isCay Horstmann & Gary Cornell's Core Java (Prentice-Hall), whichgrew so big it had to be broken into two volumes. Despite this, one of thethings I have attempted to do in this edition is trim out the portions that havebecome obsolete, or at least nonessential. I feel comfortable doing this becausethe original material remains on the Web site and the CD ROM that accompaniesthis book, in the form of the freely-downloadable first edition of the book (atwww.BruceEckel.com
). If you want the old stuff, it's still there,and this is a wonderful relief for an author. For example, you may notice thatthe original last chapter, "Projects," is no longer here; two of theprojects have been integrated into other chapters, and the rest were no longerappropriate. Also, the "Design Pattens" chapter became too big andhas been moved into a book of its own (also downloadable at the Web site). So,by all rights the book should be thinner.
But alas, it is not tobe.
The biggest issue is the continuingdevelopment of the Java language itself, and in particular the expanding APIsthat promise to provide standard interfaces for just about everythingyou'd like to do (and I won't be surprised to see the"JToaster" API eventually appear). Covering all these APIs isobviously beyond the scope of this book and is a task relegated to otherauthors, but some issues cannot be ignored. The biggest of these includeserver-side Java (primarily Servlets & Java Server pages, or JSPs),which is truly an excellent solution to the World Wide Web problem, whereinwe've discovered that the various Web browser platforms are just notconsistent enough to support client-side programming. In addition, there is thewhole problem of easily creating applications to interact with databases,transactions, security, and the like, which is involved with Enterprise JavaBeans (EJBs). These topics are wrapped into the chapter formerly called"Network Programming" and now called "DistributedComputing," a subject that is becoming essential to everyone. You'llalso find this chapter has been expanded to include an overview of Jini(pronounced "genie," and it isn't an acronym, just a name),which is a cutting-edge technology that allows us to change the way we thinkabout interconnected applications. And of course the book has been changed touse the Swing GUI library throughout. Again, if you want the old Java 1.0/1.1stuff you can get it from the freely-downloadable book atwww.BruceEckel.com
(it is also included on this edition's new CDROM, bound into the book; more on that a little later).
Aside from additional small languagefeatures added in Java 2 and corrections made throughout the book, the othermajor change is in the collections chapter (9), which now focuses on the Java 2collections used throughout the book. I've also improved that chapter tomore deeply go into some of the important issues of collections, in particularhow a hash function works (so that you can know how to properly create one).There have been other movements and changes, including a rewrite of Chapter 1,and removal of some appendices and other material that I consider no longernecessary for the printed book, but those are the bulk of them. In general,I've tried to go over everything, remove from the 2nd editionwhat is no longer necessary (but which still exists in the electronic firstedition), include changes, and improve everything I could. As the languagecontinues to change—albeit not quite at the same breakneck pace asbefore—there will no doubt be further editions of thisbook.
For those of you who still can'tstand the size of the book, I do apologize. Believe it or not, I have workedhard to keep it small. Despite the bulk, I feel like there may be enoughalternatives to satisfy you. For one thing, the book is available electronically(from the Web site, and also on the CD ROM that accompanies this book), so ifyou carry your laptop you can carry the book on that with no extra weight. Ifyou're really into slimming down, there are actually Palm Pilot versionsof the book floating around. (One person told me he would read the book in bedon his Palm with the backlighting on to keep from annoying his wife. I can onlyhope that it helps send him to slumberland.) If you need it on paper, I know ofpeople who print a chapter at a time and carry it in their briefcase to read onthe train.
At this writing, the release ofSun's Java Development Kit (JDK) 1.3 is imminent, and the proposedchanges for JDK 1.4 have been publicized. Although these version numbers arestill in the "ones," the standard way to refer to any version of thelanguage that is JDK 1.2 or greater is to call it "Java 2." Thisindicates the very significant changes between "oldJava"—which had many warts that I complained about in the firstedition of this book—and this more modern and improved version of thelanguage, which has far fewer warts and many additions and nicedesigns.
This book is written for Java 2. I havethe great luxury of getting rid of all the old stuff and writing to only thenew, improved language because the old information still exists in theelectronic 1st edition on the Web and on the CD ROM (which is whereyou can go if you're stuck using a pre-Java-2 version of the language).Also, because anyone can freely download the JDK from java.sun.com, it meansthat by writing to Java 2 I'm not imposing a financial hardship on someoneby forcing them to upgrade.
There is a bit of a catch, however. JDK1.3 has some improvements that I'd really like to use, but the version ofJava that is currently being released for Linux is JDK 1.2.2. Linux (seewww.Linux.org) is a very important development in conjunction with Java, becauseit is fast becoming the most important server platform out there—fast,reliable, robust, secure, well-maintained, and free, a true revolution in thehistory of computing (I don't think we've ever seen all of thosefeatures in any tool before). And Java has found a very important niche inserver-side programming in the form of Servlets, a technology that is ahuge improvement over the traditional CGI programming (this is covered in the"Distributed Programming" chapter).
So although I would like to only use thevery newest features, it's critical that everything compiles under Linux,and so when you unpack the source code and compile it under that OS (with thelatest JDK) you'll discover that everything will compile. However, youwill find that I've put notes about features in JDK 1.3 here andthere.
Another bonus with this edition is the CDROM that is packaged in the back of the book. I've resisted putting CDROMs in the back of my books in the past because I felt the extra charge for afew Kbytes of source code on this enormous CD was not justified, preferringinstead to allow people to download such things from my Web site. However,you'll soon see that this CD ROM is different.
The CD does contain the source code fromthe book, but it also contains the book in its entirety, in several electronicformats. My favorite of these is the HTML format, because it is fast and fullyindexed—you just click on an entry in the index or table of contents andyou're immediately at that portion of the book.
The bulk of the 300+ Megabytes of the CD,however, is a full multimedia course called Thinking in C: Foundations forC++ & Java. I originally commissioned Chuck Allison to create thisseminar-on-CD ROM as a stand-alone product, but decided to include it with thesecond editions of both Thinking in C++ and Thinking in Javabecause of the consistent experience of having people come to seminars withoutan adequate background in C. The thinking apparently goes "I'm asmart programmer and I don't want to learn C, but rather C++ orJava, so I'll just skip C and go directly to C++/Java." Afterarriving at the seminar, it slowly dawns on folks that the prerequisite ofunderstanding C syntax is there for a very good reason. By including the CD ROMwith the book, we can ensure that everyone attends a seminar with adequatepreparation.
The CD also allows the book to appeal toa wider audience. Even though Chapter 3 (Controlling program flow) does coverthe fundamentals of the parts of Java that come from C, the CD is a gentlerintroduction, and assumes even less about the student's programmingbackground than does the book. It is my hope that by including the CD morepeople will be able to be brought into the fold of Javaprogramming.
1I take this back on the 2nd edition: I believe that the Pythonlanguage comes closest to doing exactly that. Seewww.Python.org