ebook img

The Art & Science of Java: an introduction to computer science PDF

608 Pages·2008·75.9 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The Art & Science of Java: an introduction to computer science

The Art & Science of ava An Introduction ERIC S. ROBERTS to Computer Science The Art & Science of av a on SEEPS EERRE TT TSTT ‘An Introduction ERIC S$. ROBERTS | to Computer Science Stanford University Publisher Greg Tobin Executive Editor Michae Hirsch ‘Assistant Editor Lindsey Tete ‘Associate Managing Editor Jeffiey Holcomb ‘Senior Production Supervisor Marilyn Lloyd Cover Designer Joyce Cosentino Wells Photo Researcher eth Anderson Senior Maketing Manager Michelle Brown Marketing Assistant Seah Milmore Senior Technical An Specialist Joe Vetere Senior Manufacturing Buyer Carat Melville Developmental Editor Lares Rusk Photo credits: Cover image (ion at New York Public Library): © Rady Suan Corbis Pages 23 and 249 (Grace Hopper and Herman Holler): Betimann/Corbis Page 37 (George Boole): The image Works| Page 95 (Dennis Ritchie: Bel Labs Page 133 (David Pamas): Photo supplied by David Paras Page 177 (Kristen Nygaard and Ol-fohan Da): Universitat Klagenfurt age 221 Jay Forrester: © The Mite Corporatio. used by permision Page 295 (Ivan Sutherland): Phso supplied by Ivan Suterand age 49 (Alan Kay: Andi Enginering Society. In. age 409 (Dan Bricklin nd Bob Frankston) Sttting History of Computing Page 461 (C-A. Howe): University of Koblenz, Germany age 545 (Anita Borg: Anita Borg Inst for Women in Compt ‘Many of te designations used by manufacturers and seers o distinguish their products are claimed a trademarks, Whee those designations appear in hit book, lind Addison Wesley was aware ofa trademark claim. te designations have been red in inal caps o all eps. Library of Congress Cstalogins-n Publication Data is available upon request. Reproduced by Adion-Wesley from camer-ready copy spl by the author. ‘Copyright © 2008 Pearion Education, Ine. Al righs reserved. No pst ofthis Publication may be reproduced, stored na reticval system, or tarsi in any Formor by any mean, electronic, mechanical photocopying, recording ‘terse, without the por writen permission ofthe polisher. Pinte i the Unite Stites of Amerie. For information on obtaining permission for use of ‘material in his work, please submit a writen request o Pearson Education, In, Rights and Cootracs Deparment, 78 Arlington Sucet, Sue 30, Boston, MA (02116, fax your request to 617-848-7047, or e-mal at, up ea pearsoned com egal permissions hi ISBN-13:978-0.31-88612-7 ISBN-10:0:321-48612.9 456789 10—cRS—12 11 10 Dedicated tthe memory of Anita Borg (1949-2003) orher ils efor to big the excitement, of computing to wider auience To the Student Welcome! By picking up this book. you have taken 2 sep into the word of computer sciences field of sty tat has grown from almost nothing hall 3 ‘Seay ag0 tone ofthe mos Vitra and active disciplines of a ine, "Ove that ine, he computer has opened up extraordinary poses in alot very are of human endeavor. Busnes leaders today are able to manage glo “nerrnes on an unprecedented scale Because compas enable ther o tater ‘ita ayer na fraction of «second, Scene can now solve problems were beyond thelr reach in the days before computer made the necessary culations posible. The Word Wide Web puts vant amount of information # Sou fingertip and es tthe foundation of iba industry tha id exist ‘evade ago Fimmabers can use computer chaos) to crete animate features ta wou hve been unbikable in Walt Disney's time, Maer competition hos revolutionized many fie enabling biologists to sequence the haman genome, ‘conomins to model international markets and Mera chor to asst wheter ‘muted Elzabetan manascrp might ave hee penne by Shakespeare Comparing is 8 profoundly empowering technology. The computing indstry contin t grow, with more job vale today thn tthe eight ofthe Inet tom ofthe 199: But the advances we have ween op onow are seal compared 0 ht we wil experience in this entry. Those of yo who ae stents aay will soon inherit the responsiblity of guiding tht progress. No mater what Gel you ‘hse unerstanding how to se computing effect) wl eof nar vale ‘ke most sl tha are worth knowing. leasing ow compres wk and how ‘to contol ther enormous power takes ime. You wil not understand all atone. ‘You must sat somewhere. Twenty-five centuries ago, the Chinese pilsopher Lota observed that he longest journey begins with ingle sep Ts bok can be your bepmning For many of You, however the fst step canbe the hardest to take, Many student find computer over icing and imagine that compote sciences beyond their each, Learning the basis of programming, however, doesnot require vanced mathemati ea dete uncstanding of electronics, What mates in Programming is whether you can popes from the ssemet of «problem 1 ‘Slaton To do so you must be abet ink logical. You most have the necessary ‘acpi to express your loge ina frm hat he computer can undertaod, Perhaps most ipotantly, yu mst be abet sete tank thought competion without ting discouraged by difiutiesand setbacks, If you sick wth he proces, 0 ‘i iscover tat reaching the solton io extn that tore than aks wp Far any frasrations you encounter log the 3. Tish ou plese journey slong tat rad rc Robes Stnfrd Univenty Sanur 2007 To the Instructor ‘This exis intended fr ue in the ist programming course in apical college or university curiculum. I covers the materi ia tratonl CSI course, as dined inthe Curcan 78 repr pepe by the Ascciaton for Computing Machinery (ACM). Teabo iecades the fal cto topic specified forte CS101Q or CSI1I0, ‘couse inthe compute science volume ofthe tore ecent Comparing Cream 2001 rept The Art and cence of lava uss sini approach 0 that of my 1995 textbook, The Art and Science of . Each ofthese txts uses irate o make programming less complex and consequenly moce accesible wo the novice. Inthe Chased ‘eno, tose iain proved be extremely access wth stents no ony at Stanford, but at manyther nstiatons a wel. This book uses the ACM Java bares achieve the same gals the year sinc inal release in 1995, the Java programming language has tecme increasingly important san insrctonl language he pot that it now samehing fa slandad introductory computing couse. On the positive fide, Sav offers many advantages over earlier teaching languages rimaniy by ‘aking it possible for stodents o write highly iterative programs tat capture "heer and imagination Al the same ne Java far ore sophisticated han Ianguages that have taditoaly filled the oie of teaching languages, sch 3s [BASIC and Pascal. ‘The complet tht accompanies Jva's sopistiation can bea ‘gnfcamt barr to both teachers and stodents as they ty to understand the 2008 the ACM csublishod the Java Task Force and gave i the following charge! “To view te Jv angune, APS and ta fom the pepe of Int computing eda ad develop cation of ego eer ha wil mae evr otc eva fener Sating sents tho! vig ow sees vere Bs Sele ‘Over the nex two yeas the Java Task Fore developed 2 ne st of iraris Intended o support the us of Java athe inrctory level. AR eesing 80 ‘pelininary drafts to oti communityfedbac. the Java Task Fare publise final report inthe summer of 2006. ‘The ACM Java Libraries described i that ‘por ae alsin the flowing wed maps //setsem.org/ tn addon tothe ACM Java Libris themselves, the web site contain large <llecton of demo programs, a ftrial guide, an extensive discussion of the ‘tina bind the design ote varius packages and an executive summary that Menai the followings the greats strengths ofthe Mbris. The ACM Java [bares provi + Asinple object-oriented model for programs. The Program ls einen ‘he am. propran package offer a es) to-use model for writing simple ‘program. In addin to hiding the sac main mth he Programcliss nd its standard subclasses provice highly intuitive example of abject: ‘ented cls berchis, + Armode! for inp and ups tat reats ational console 10 and dialog 110 symmetricly. The acm. 49 package defines the clases YOconsole snd ootatog ta share common ieface for alinpwoutpt operas. This <esign addrescs Java's lack of simple input mechanism i 2 way tha “rphasires the vale of inerfce tase Sexpn + Amestensve library of graphical objects. The som.graphice package implement simple but extemely powerful mal for creating graphical pictures based onthe metapor ofa fel oar i which stents comtrct ‘raphial objets of various types and plac them ona cant. This eign ‘mphaszs the use of objects and frees the stadet fom having to Yespoad, xpi o epi requests. + A-minimal se of new clases to support development of graphical user imerfoces. ‘The aem. gut package icles 4 sal Sto clases 10 bing Java's extesive OU-sevelopment resources within the reach of novice programmes. ‘+ Backward conparbiliy for apples. Unie most Java code tay programs ‘developed using the ACM ava Libraries can typically be excuses ‘even on older eb browsers. This lability makes thee bras an eal foundation for web-based teaching tools and lecture demonstrations. (Given the enormoes numberof lasts and methods that ae available in Java's ven liars, neitabetat book of thi sot wl leave ot sme pric Feature of Java tis impossible wo cover everything snd stil produce a bok thats scone the average toent. In tem ofthe choice of tps, this book seeks to ote a caberent presentation that teaches the fundamentals of compute science rater tanto cove everything there i © haow about Java. Ia many ways, tbe viding peicipl forthe choice of tpi inthis bok comes from the flowing ‘shsrvaton fom Anoie de Suint-Exupéry nhs 1982 memoite Pte de Guerre (ier quoted by Tony Hoare in his 1980 Turing Award lester) eosin atid mt wen ig ef al, wen While this Book ceialy makes no claims t perfection, it would probably have een eter oleae mor opis oa than put more ois in. “Although the book coves tps in a ede hats proven sce ee at Stnford ou may wa vary the order of presentation fo wt your aun ad the goals of your course. The following noes prove at overview ofthe chaps andindcate some othe more imprint dependencies (Chaper I aces the history of computing and describes the programming process The chapter ees no programming pete bt provides the context rckround forthe est ofthe et ‘hae designed Chapter for stems wih lite or 8 computing background “This chaper conceptual in is approach and focuses om developing halisic nderaning of ob rete programming rattan onthe deta the Java language. Whea aw stlcts ar faced with dtaed rules of sta ad stricter, they concentrate on eaing the reise ofthe underiyng concep which ae vastly more important at this stage. If your stodents already Know some rogremming Sou can poly move quickly trough th matcria ‘Chaperj, 8, and offer relatively rations introductions to expressions, stscments and thos 0 that stents derstand thee bai onset. ‘Chapters 6 and 7 then 0 on 1 ingoduce the fundamentals of objects and clases. (Chapter 6 provides the high-level view, fcising on bow to we objects and clases ‘ater thin on thir onderyingsractore Chaper 7 then frm to the low-level ‘ells involved of how objects are presented ia memory. Although Chapter 7 ‘ot absolutely require, stants who ean pct the internal scar ofan objet {Sc auch moe ley to uderstand theese cone ofa ference. ‘The net thee chaps inoue pric elses from che Java's Standard litres or the ACM packages. Chapir § cover the Beng clas, which i ‘resumaly an important tpi in any introductory course. Chap 9 describes the (ben. graphies plage in detail which makes possible fo stds to write fat ‘more exciting proms. Pas of the aen-graphies package rine in earier ‘haps and ts cenainly poset cover oly some of the topic in Chapter 9, CChaper 10 offers a similar overview of event driven programming. ‘The fist several sections in Chapter 10 focus on mone ad keyboard events tbe eaining Sectons provide an inroduton graphical wer ineraces (GU) an the standard ineraco lasses rom javax-eving. This econ part ofthe cher is alae you wet to have andes design GULEased programs, but it tbo acesty 1 ‘dersiand subsequent chaps. ‘Chapters 11 and 12 addres the Hea of arrays, but do 30 from different ‘penpectves. Chapter 11 intodces bth the built-in aay type and the Acree bility clas fromthe Javan et package. Both af thse topics sem esenial © ‘my Jvabuscdinroduton course. Chapter 12 fos on algorithms for searching nd sori aay The chapter also icles aie dscssan of computational ‘Somplxity tht wil belp tons unetnd the iporane of sporti deen “Chaplet 13desrbes the Java Collections Framework, which is perbaps more often presented ina ecod programing couse. However-becaus ava takes cae ff so tany ofthe underlying deta, tf actually quite resonable to teach Inrdetory stents how fo we these clases even if thy can't understand thei Implementation. The oly ese clas frm the Java Cllections Framework Arrapiist, whic as ely appeared ia Chpter 1 ‘Chapter 1 nclaes four important topics tat sometines appear ina fest programming course: recursion. concurency. etWorking. and programming artes. At Sanford, which son the quarter system, we tach these opis ia he Second coune. Ifyou decide to teach recursion inthe fist course, 1 sonaly fecommend that yu do 50 esly enough to allow todents ine to ait the fae One posit sto dca ecusive fncions immediately afer Chapter ‘Sand ecu algorithms athe ed of Chapter 12 Supplemental Resources For students “Te following items ae avalabe tall ees of this book atthe Addison-Wesley ‘ve ie eps / ma. com/camepport/ > + Source code files foreach example program inthe bok {allo PDF version of smple ron Answer to evew questions For instructors “The following items are wail o qualified instructors from Addison Wesey’s Instr Resource Center neem. com/ ee): ‘Soure cade ils for ech example propa in the book Falcolor PDF versions of smple rns “Aneverst review quetons Solution to posrarsming exercises ‘Apple bsed lestre sie tht nla animations of he rogram examples For adopters of the ACM Java Libraries ‘The Associaton foe Computing Machinery maintains an extensive web sit on the ‘ACM Java Litres developed by the Java Task Focce (eeps//3ef.0n.0r9) “That st clades he lllwing resources: An executive summary outing he purpose of he ACM Java Libates DDonlonsbl copies of ACM irre im both ote and compiled orm ‘Atexeasive demo galley icuding source code forthe examples ‘An inductor tata using the ACM irares ‘Ncomprehensve dncusson of the rationale ind the design

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.