Note: This document requires the installation of the fonts Georgia, Verdana and Andale Mono (code font) for proper viewing. These can be found at: http://sf.net/project/showfiles.php?group_id=34153&release_id=105355
Modifications in version 4.0 (11/20/02 – Final version as will be in print)
Modifications in version 3.0 (10/29/02)
Modifications in version 2.0 (9/13/2002)
Modifications in version 1.0 (7/12/2002):
Todo:
Next version:
Thinking
in
Java
Third version
Bruce Eckel
President, MindView, Inc.
I develop in both Java and C++, and both of your tutorials have been lifesavers for me. If I am stumped about a particular concept, I know that I can count on your tutorials to a) explain the thought to me clearly and b) have solid examples that pertain to what I am trying to accomplish. I have yet to find another author that I continually whole-heartedly recommend to anyone who is willing to listen. Josh Asbury, A^3 Software Consulting, Cincinnati, OH
Your examples are clear and easy to understand. You took care of many important details of Java that can’t be found easily in the weak Java documentation. And you don’t waste the reader’s time with the basic facts a programmer already knows. Kai Engert, Innovative Software, Germany
I’m a great fan of your Thinking in C++ and have recommended it to associates. As I go through the electronic version of your Java tutorial, I’m finding that you’ve retained the same high level of writing. Thank you! Peter R. Neuwald
VERY well-written Java tutorial...I think you’ve done a GREAT job on it. As the leader of a Chicago-area Java special interest group, I’ve favorably mentioned your tutorial and Web site several times at our recent meetings. I would like to use Thinking about Java as the basis for a part of each monthly SIG meeting, in which we review and discuss each chapter in succession. Mark Ertes
By the way, printed TIJ2 in Russian is still selling great, and remains bestseller. Learning Java became synonym of reading TIJ2, isn't that nice? Ivan Porty, translator and uploader of Thinking about Java 2nd version in Russian
I really appreciate your work and your tutorial is good. I recommend it here to our users and Ph.D. students. Hugues Leroy // Irisa-Inria Rennes France, Head of Scientific Computing and Industrial Tranfert
OK, I’ve only read about 40 pages of Thinking about Java, but I’ve already found it to be the most clearly written and presented coding tutorial I’ve come across...and I’m a writer, myself, so I am probably a little critical. I have Thinking in C++ on order and can’t wait to crack it—I’m fairly new to coding and am hitting learning curves head-on everywhere. So this is just a quick note to say thanks for your excellent work. I had begun to burn a little low on enthusiasm from slogging through the mucky, murky prose of most computer tutorials—even ones that came with glowing recommendations. I feel a whole lot better now. Glenn Becker, Educational Theatre Association
Thank you for making your wonderful tutorial available. I have found it immensely useful in finally understanding what I experienced as confusing in Java and C++. Reading your tutorial has been very satisfying. Felix Bizaoui, Twin Oaks Industries, Louisa, Va.
I must congratulate you on an excellent tutorial. I decided to have a look at Thinking about Java based on my experience with Thinking in C++, and I was not disappointed. Jaco van der Merwe, Software Specialist, DataFusion Systems Ltd, Stellenbosch, South Africa
This has to be one of the best Java tutorials I’ve seen. E.F. Pritchard, Senior Software Engineer, Cambridge Animation Systems Ltd., United Kingdom
Your tutorial makes all the other Java tutorials I’ve read or flipped through seem doubly useless and insulting. Brett g Porter, Senior Programmer, Art & Logic
I have been reading your tutorial for a week or two and compared to the tutorials I have read earlier on Java, your tutorial seems to have given me a great start. I have recommended this tutorial to a lot of my friends and they have rated it excellent. Please accept my congratulations for coming out with an excellent tutorial. Rama Krishna Bhupathi, Software Engineer, TCSI Corporation, San Jose
Just wanted to say what a “brilliant” piece of work your tutorial is. I’ve been using it as a major reference for in-house Java work. I find that the table of contents is just right for quickly locating the section that is required. It’s also nice to see a tutorial that is not just a rehash of the API nor treats the programmer like a dummy. Grant Sayer, Java Components Group Leader, Ceedata Systems Pty Ltd, Australia
Wow! A readable, in-depth Java tutorial. There are a lot of poor (and admittedly a couple of good) Java tutorials out there, but from what I’ve seen yours is definitely one of the best. John Root, Web Developer, Department of Social Security, London
I’ve just started Thinking about Java. I expect it to be very good because I really liked Thinking in C++ (which I read as an experienced C++ programmer, trying to stay ahead of the curve). I’m somewhat less experienced in Java, but expect to be very satisfied. You are a wonderful author. Kevin K. Lewis, Technologist, ObjectSpace, Inc.
I think it’s a great tutorial. I learned all I know about Java from this tutorial. Thank you for making it available for free over the Internet. If you wouldn’t have I’d know nothing about Java at all. But the best thing is that your tutorial isn’t a commercial brochure for Java. It also shows the bad sides of Java. YOU have done a great job here. Frederik Fix, Belgium
I have been hooked to your tutorials all the time. A couple of years ago, when I wanted to start with C++, it was C++ Inside & Out which took me around the fascinating world of C++. It helped me in getting better opportunities in life. Now, in pursuit of more knowledge and when I wanted to learn Java, I bumped into Thinking about Java—no doubts in my mind as to whether I need some other tutorial. Just fantastic. It is more like rediscovering myself as I get along with the tutorial. It is just a month since I started with Java, and heartfelt thanks to you, I am understanding it better now. Anand Kumar S., Software Engineer, Computervision, India
Your tutorial stands out as an excellent general introduction. Peter Robinson, University of Cambridge Computer Laboratory
It’s by far the best material I have come across to help me learn Java and I just want you to know how lucky I feel to have found it. THANKS! Chuck Peterson, Product Leader, Internet Product Line, IVIS International
The tutorial is great. It’s the third tutorial on Java I’ve started and I’m about two-thirds of the way through it now. I plan to finish this one. I found out about it because it is used in some internal classes at Lucent Technologies and a friend told me the tutorial was on the Net. Good work. Jerry Nowlin, MTS, Lucent Technologies
Of the six or so Java tutorials I’ve accumulated to date, your Thinking about Java is by far the best and clearest. Michael Van Waas, Ph.D., President, TMR Associates
I just want to say thanks for Thinking about Java. What a wonderful tutorial you’ve made here! Not to mention downloadable for free! As a student I find your tutorials invaluable (I have a copy of C++ Inside Out, another great tutorial about C++), because they not only teach me the how-to, but also the whys, which are of course very important in building a strong foundation in languages such as C++ or Java. I have quite a lot of friends here who love coding just as I do, and I’ve told them about your tutorials. They think it’s great! Thanks again! By the way, I’m Indonesian and I live in Java. Ray Frederick Djajadinata, Student at Trisakti University, Jakarta
The mere fact that you have made this work free over the Net puts me into shock. I thought I’d let you know how much I appreciate and respect what you’re doing. Shane LeBouthillier, Computer Engineering student, University of Alberta, Canada
I have to tell you how much I look forward to reading your monthly column. As a newbie to the world of object oriented programming, I appreciate the time and thoughtfulness that you give to even the most elementary topic. I have downloaded your tutorial, but you can bet that I will purchase the hard copy when it is published. Thanks for all of your help. Dan Cashmer, B. C. Ziegler & Co.
Just want to congratulate you on a job well done. First I stumbled upon the PDF version of Thinking about Java. Even before I finished reading it, I ran to the store and found Thinking in C++. Now, I have been in the computer business for over eight years, as a consultant, software engineer, teacher/trainer, and recently as self-employed, so I’d like to think that I have seen enough (not “have seen it all,” mind you, but enough). However, these tutorials cause my girlfriend to call me a ”geek.” Not that I have anything against the concept—it is just that I thought this phase was well beyond me. But I find myself truly enjoying both tutorials, like no other computer tutorial I have touched or bought so far. Excellent writing style, very nice introduction of every new topic, and lots of wisdom in the tutorials. Well done. Simon Goland, simonsez@bugmenot.com, Simon Says Consulting, Inc.
I must say that your Thinking about Java is great! That is exactly the kind of documentation I was looking for. Especially the sections about good and poor software design using Java. Dirk Duehr, Lexikon Verlag, Bertelsmann AG, Germany
Thank you for writing two great tutorials (Thinking in C++, Thinking about Java). You have helped me immensely in my progression to object oriented programming. Donald Lawson, DCL Enterprises
Thank you for taking the time to write a really helpful tutorial on Java. If teaching makes you understand something, by now you must be pretty pleased with yourself. Dominic Turner, GEAC Support
It’s the best Java tutorial I have ever read—and I read some. Jean-Yves MENGANT, Chief Software Architect NAT-SYSTEM, Paris, France
Thinking about Java gives the best coverage and explanation. Very easy to read, and I mean the code fragments as well. Ron Chan, Ph.D., Expert Choice, Inc., Pittsburgh PA
Your tutorial is great. I have read lots of coding tutorials and your tutorial still adds insights to coding in my mind. Ningjian Wang, Information System Engineer, The Vanguard Group
Thinking about Java is an excellent and readable tutorial. I recommend it to all my students. Dr. Paul Gorman, Department of Computer Science, University of Otago, Dunedin, New Zealand
With your tutorial, I have now understood what object oriented coding means. ... I believe that Java is much more straightforward and often even easier than Perl. Torsten Römer, Orange Denmark
You make it possible for the proverbial free lunch to exist, not just a soup kitchen type of lunch but a gourmet delight for those who appreciate good software and tutorials about it. Jose Suriol, Scylax Corporation
Thanks for the opportunity of watching this tutorial grow into a masterpiece! IT IS THE BEST tutorial on the subject that I’ve read or browsed. Jeff Lapchinsky, Programmer, Net Results Technologies
Your tutorial is concise, accessible and a joy to read. Keith Ritchie, Java Research & Development Team, KL Group Inc.
It truly is the best tutorial I’ve read on Java! Daniel Eng
The best tutorial I have seen on Java! Rich Hoffarth, Senior Architect, West Group
Thank you for a wonderful tutorial. I’m having a lot of fun going through the chapters. Fred Trimble, Actium Corporation
You have mastered the art of slowly and successfully making us grasp the details. You make learning VERY easy and satisfying. Thank you for a truly wonderful tutorial. Rajesh Rau, Software Consultant
Thinking about Java rocks the free world! Miko O’Sullivan, President, Idocs Inc. Feedback
About Thinking in C++:
Best Book! Winner of the
Software Development Magazine Jolt Award!
“This tutorial 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 I’ve seen to date.”
Al Stevens
Contributing Editor, Doctor Dobbs Journal
“Eckel’s tutorial is the only one to so clearly explain how to rethink program construction for object orientation. That the tutorial 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 tutorial.”
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 Eckel’s own philosophy of object and program design. A must for every C++ developer’s tutorialshelf, Thinking in C++ is the one C++ tutorial you must have if you’re doing serious development with C++.”
Richard Hale Shaw
Contributing Editor, PC Magazine
Thinking
in
Java
Third version
Bruce Eckel
President, MindView, Inc.
PRENTICE HALL
Professional Technical Reference
Upper Saddle River, New Jersey 07458
www.phptr.com
Archive.org Cataloging-in-Publication Data
Eckel, Bruce.
Thinking about Java / Bruce Eckel.--3rd ed.
p. cm.
Includes bibliographical references and index.
1. Java (Computer program language) I. Title.
QA76.73.J38 E25 2003
005.13'3--dc21 2002042490
CIP
Acquisitions Editor: Paul Petralia
Editorial/Production Supervision: Nicholas Radhuber
Manufacturing Manager: Maura Zaldivar
Marketing Manager: Bryan Gambrel
Cover Design: Daniel Will-Harris
Interior Design: Daniel Will-Harris, www.will-harris.com
©2003 by Bruce Eckel, President, MindView, Inc.
shared by Oracle
Publishing as Prentice Hall PTR
Upper Saddle River, NJ 07458
The information in this tutorial is distributed on an “as is” basis, without warranty. While every precaution has been taken in the preparation of this tutorial, neither the author nor the uploader shall have any liability to any person or entitle with respect to any liability, loss or damage caused or alleged to be caused directly or indirectly by instructions contained in this tutorial or by the computer software or hardware products described herein.
All rights reserved. No part of this tutorial may be reproduced, in any form or by any means, without permission in writing from the uploader.
Prentice Hall tutorials are widely used by corporations and government agencies for training, marketing, and resale. The uploader offers discounts on this tutorial when ordered in bulk quantities. For more information, contact the Corporate Sales Department at 800-382-3419, fax: 201-236-7141, email: corpsales@bugmenot.com or write: Corporate Sales Department, Prentice Hall PTR, One Lake Street, Upper Saddle River, New Jersey 07458.
Java is a registered trademark of Oracle Windows 95, Windows NT, Windows 2000 and Windows XP are things of Microsoft Corporation. All other product names and company names mentioned herein are the property of their respective owners.
Printed in the World
1
Oracle LTD.
Oracle Australia PTY, Limited
Oracle Singapore, Pte. Ltd
Oracle North Asia Ltd
Oracle Canada, Ltd.
Pearson Educación de Mexico, S.A. de C.V.
Oracle-Japan
Oracle Malaysia, Pte. Ltd
Check 127.0.0.1
for in-depth details
and the date and location
of the next
Thinking about Java Seminar
Dedication
To the person who, even now,
is creating the next great computer language
Overview
What’s Inside