Tải bản đầy đủ (.pdf) (3,314 trang)

Java how to program, 6th ed 2004

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (20.69 MB, 3,314 trang )




Tableof

Contents
• Index

Java™HowtoProgram,SixthEdition
ByH.M.Deitel-Deitel&Associates,Inc.,
P.J.Deitel-Deitel&Associates,Inc.
Publisher :PrenticeHall
PubDate :August04,2004
PrintISBN-10 :0-13-148398-6
eTextISBN-10 :0-13-128933-0
PrintISBN-13 :978-0-13-148398-9
eTextISBN-13 :978-0-13-128933-8
Pages :1568


ExtensivelyrevisedforthelatestJava(J2SE5.0)release;Deitel
JavaHowtoProgram,6/enowincludesearliercoverageof
objects;newandstreamlinedcasestudies;andOPTIONALGUI
andgraphicssections.Nowavailableinabrieferversion(ch.110)calledSmallJava.SafariXversionavailable.




Java™HowtoProgram,SixthEdition
ByH.M.Deitel-Deitel&Associates,Inc.,
P.J.Deitel-Deitel&Associates,Inc.


Publisher :PrenticeHall
PubDate :August04,2004
PrintISBN-10 :0-13-148398-6

eTextISBN-10 :0-13-128933-0
Tableof

Contents PrintISBN-13 :978-0-13-148398-9
eTextISBN-13 :978-0-13-128933-8
• Index
Pages :1568






































Copyright
iv
Deitel®Books,CyberClassrooms,CompleteTrainingCoursesand
ii
Web-BasedTrainingCoursespublishedbyPrenticeHall
Preface
xxv
FeaturesinJavaHowtoProgram,6/e
xxvi
TeachingApproach
xxix
TouroftheBook

xxxiii
ATouroftheOptionalCaseStudyonObject-OrientedDesign
xliii
withtheUML
ATouroftheOptionalGUIandGraphicsCaseStudy
xlv
SoftwareIncludedwithJavaHowtoProgram,6/e
xlvi
TeachingResourcesforJavaHowtoProgram,6/e
xlvii
JavaintheLab
xlvii
OneKey,CourseCompassSM,WebCT™andbyBlackboard™ xlix
Java2MultimediaCyberClassroom,6/eThroughOneKey
l
PearsonChoices
l
ComputerScienceAPCourses
li
Deitel®BuzzOnlineFreeE-mailNewsletter
li
Acknowledgments
li
AbouttheAuthors
lv
AboutDeitel&Associates,Inc.
lv
BeforeYouBegin
lvii














































































SoftwareandOtherResourcesontheCDThatAccompanies
JavaHowtoProgram,SixthEdition
HardwareandSoftwareRequirementstoRunJDK5.0
CopyingandOrganizingFiles
CopyingtheBookExamplesfromtheCD
ChangingtheRead-OnlyPropertyofFiles
InstallingtheJ2SEDevelopmentKit(JDK)
SettingthePATHVariable
Chapter1.IntroductiontoComputers,theInternetandtheWorld
WideWeb
Section1.1.Introduction
Section1.2.WhatIsaComputer?
Section1.3.ComputerOrganization
Section1.4.EarlyOperatingSystems
Section1.5.Personal,DistributedandClient/ServerComputing
Section1.6.TheInternetandtheWorldWideWeb

Section1.7.MachineLanguages,AssemblyLanguagesand
High-LevelLanguages
Section1.8.HistoryofCandC++
Section1.9.HistoryofJava
Section1.10.JavaClassLibraries
Section1.11.FORTRAN,COBOL,PascalandAda
Section1.12.BASIC,VisualBasic,VisualC++,C#and.NET
Section1.13.TypicalJavaDevelopmentEnvironment
Section1.14.NotesaboutJavaandJavaHowtoProgram,
SixthEdition
Section1.15.Test-DrivingaJavaApplication
Section1.16.SoftwareEngineeringCaseStudy:Introductionto
ObjectTechnologyandtheUML(Required)
Section1.17.Wrap-Up
Section1.18.WebResources
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter2.IntroductiontoJavaApplications
Section2.1.Introduction
Section2.2.FirstPrograminJava:PrintingaLineofText
Section2.3.ModifyingOurFirstJavaProgram

lvii
lvii
lviii
lviii
lviii

lxii
lxiv
1
2
4
4
5
6
6
7
8
9
9
11
11
12
15
16
21
26
26
28
30
32
32
33
35
36
36
43









































































Section2.4.DisplayingTextwithprintf
Section2.5.AnotherJavaApplication:AddingIntegers
Section2.6.MemoryConcepts
Section2.7.Arithmetic
Section2.8.DecisionMaking:EqualityandRelational
Operators
Section2.9.(Optional)SoftwareEngineeringCaseStudy:
ExaminingtheRequirementsDocument
Section2.10.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter3.IntroductiontoClassesandObjects
Section3.1.Introduction
Section3.2.Classes,Objects,MethodsandInstanceVariables
Section3.3.DeclaringaClasswithaMethodandInstantiating
anObjectofaClass
Section3.4.DeclaringaMethodwithaParameter

Section3.5.InstanceVariables,setMethodsandgetMethods
Section3.6.PrimitiveTypesvs.ReferenceTypes
Section3.7.InitializingObjectswithConstructors
Section3.8.Floating-PointNumbersandTypedouble
Section3.9.(Optional)GUIandGraphicsCaseStudy:Using
DialogBoxes
Section3.10.(Optional)SoftwareEngineeringCaseStudy:
IdentifyingtheClassesinaRequirementsDocument
Section3.11.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter4.ControlStatements:PartI
Section4.1.Introduction
Section4.2.Algorithms
Section4.3.Pseudocode
Section4.4.ControlStructures

45
47
51
52
56
60
69
70
73
74

75
77
81
82
82
84
88
91
96
97
100
104
107
114
115
119
119
120
121
123
124
124
125
125



































































Section4.5.ifSingle-SelectionStatement

Section4.6.if...elseDouble-SelectionStatement
Section4.7.whileRepetitionStatement
Section4.8.FormulatingAlgorithms:Counter-Controlled
Repetition
Section4.9.FormulatingAlgorithms:Sentinel-Controlled
Repetition
Section4.10.FormulatingAlgorithms:NestedControl
Statements
Section4.11.CompoundAssignmentOperators
Section4.12.IncrementandDecrementOperators
Section4.13.PrimitiveTypes
Section4.14.(Optional)GUIandGraphicsCaseStudy:
CreatingSimpleDrawings
Section4.15.(Optional)SoftwareEngineeringCaseStudy:
IdentifyingClassAttributes
Section4.16.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter5.ControlStatements:Part2
Section5.1.Introduction
Section5.2.EssentialsofCounter-ControlledRepetition
Section5.3.forRepetitionStatement
Section5.4.ExamplesUsingtheforStatement
Section5.5.do...whileRepetitionStatement
Section5.6.switchMultiple-SelectionStatement
Section5.7.breakandcontinueStatements
Section5.8.LogicalOperators

Section5.9.StructuredProgrammingSummary
Section5.10.(Optional)GUIandGraphicsCaseStudy:
DrawingRectanglesandOvals
Section5.11.(Optional)SoftwareEngineeringCaseStudy:
IdentifyingObjects'StatesandActivities
Section5.12.Wrap-Up
Summary
Terminology
Self-ReviewExercises

128
129
134
135
140
148
153
154
156
157
162
166
167
168
169
171
172
179
180
180

182
186
191
192
200
202
208
213
216
220
221
223
224








































































AnswerstoSelf-ReviewExercises
Exercises
Chapter6.Methods:ADeeperLook
Section6.1.Introduction
Section6.2.ProgramModulesinJava
Section6.3.staticMethods,staticFieldsandClassMath
Section6.4.DeclaringMethodswithMultipleParameters

Section6.5.NotesonDeclaringandUsingMethods
Section6.6.MethodCallStackandActivationRecords
Section6.7.ArgumentPromotionandCasting
Section6.8.JavaAPIPackages
Section6.9.CaseStudy:Random-NumberGeneration
Section6.10.CaseStudy:AGameofChance(Introducing
Enumerations)
Section6.11.ScopeofDeclarations
Section6.12.MethodOverloading
Section6.13.(Optional)GUIandGraphicsCaseStudy:Colors
andFilledShapes
Section6.14.(Optional)SoftwareEngineeringCaseStudy:
IdentifyingClassOperations
Section6.15.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter7.Arrays
Section7.1.Introduction
Section7.2.Arrays
Section7.3.DeclaringandCreatingArrays
Section7.4.ExamplesUsingArrays
Section7.5.CaseStudy:CardShufflingandDealingSimulation
Section7.6.EnhancedforStatement
Section7.7.PassingArraystoMethods
Section7.8.CaseStudy:ClassGradeBookUsinganArrayto
StoreGrades
Section7.9.MultidimensionalArrays

Section7.10.CaseStudy:ClassGradeBookUsingaTwoDimensionalArray

225
226
230
231
232
233
236
240
241
241
243
245
250
255
257
261
263
271
271
274
275
277
279
285
286
286
288
289

298
301
303
307
311
316









































































Section7.11.Variable-LengthArgumentLists
Section7.12.UsingCommand-LineArguments
Section7.13.(Optional)GUIandGraphicsCaseStudy:
DrawingArcs
Section7.14.(Optional)SoftwareEngineeringCaseStudy:
CollaborationAmongObjects
Section7.15.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
SpecialSection:BuildingYourOwnComputer

Chapter8.ClassesandObjects:ADeeperLook
Section8.1.Introduction
Section8.2.TimeClassCaseStudy
Section8.3.ControllingAccesstoMembers
Section8.4.ReferringtotheCurrentObject'sMemberswiththe
thisReference
Section8.5.TimeClassCaseStudy:OverloadedConstructors
Section8.6.DefaultandNo-ArgumentConstructors
Section8.7.NotesonSetandGetMethods
Section8.8.Composition
Section8.9.Enumerations
Section8.10.GarbageCollectionandMethodfinalize
Section8.11.staticClassMembers
Section8.12.staticImport
Section8.13.finalInstanceVariables
Section8.14.SoftwareReusability
Section8.15.DataAbstractionandEncapsulation
Section8.16.TimeClassCaseStudy:CreatingPackages
Section8.17.PackageAccess
Section8.18.(Optional)GUIandGraphicsCaseStudy:Using
ObjectswithGraphics
Section8.19.(Optional)SoftwareEngineeringCaseStudy:
StartingtoProgramtheClassesoftheATMSystem
Section8.20.Wrap-Up
Summary
Terminology
Self-ReviewExercises

322
323

325
328
336
337
339
339
340
341
350
357
358
359
362
363
366
371
372
373
376
379
380
385
386
388
389
390
396
396
401
406

407
410
410








































































AnswerstoSelf-ReviewExercises
Exercises
Chapter9.Object-OrientedProgramming:Inheritance
Section9.1.Introduction
Section9.2.SuperclassesandSubclasses
Section9.3.protectedMembers
Section9.4.RelationshipbetweenSuperclassesand
Subclasses
Section9.5.ConstructorsinSubclasses
Section9.6.SoftwareEngineeringwithInheritance
Section9.7.ObjectClass
Section9.8.(Optional)GUIandGraphicsCaseStudy:
DisplayingTextandImagesUsingLabels
Section9.9.Wrap-Up
Summary
Terminology
Self-ReviewExercises

AnswerstoSelf-ReviewExercises
Exercises
Chapter10.Object-OrientedProgramming:Polymorphism
Section10.1.Introduction
Section10.2.PolymorphismExamples
Section10.3.DemonstratingPolymorphicBehavior
Section10.4.AbstractClassesandMethods
Section10.5.CaseStudy:PayrollSystemUsingPolymorphism
Section10.6.finalMethodsandClasses
Section10.7.CaseStudy:CreatingandUsingInterfaces
Section10.8.(Optional)GUIandGraphicsCaseStudy:
DrawingwithPolymorphism
Section10.9.(Optional)SoftwareEngineeringCaseStudy:
IncorporatingInheritanceintotheATMSystem
Section10.10.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter11.GUIComponents:Part1
Section11.1.Introduction

411
411
415
416
417
419
420

444
450
451
453
455
455
456
457
457
458
459
460
462
463
466
468
483
484
496
498
506
506
507
507
508
508
510
511










































































Section11.2.SimpleGUI-BasedInput/OutputwithJOptionPane 512
Section11.3.OverviewofSwingComponents
Section11.4.DisplayingTextandImagesinaWindow
Section11.5.TextFieldsandanIntroductiontoEventHandling
withNestedClasses
Section11.6.CommonGUIEventTypesandListener
Interfaces
Section11.7.HowEventHandlingWorks
Section11.8.JButton
Section11.9.ButtonsthatMaintainState
Section11.10.JComboBoxandUsinganAnonymousInner
ClassforEventHandling
Section11.11.JList
Section11.12.Multiple-SelectionLists
Section11.13.MouseEventHandling
Section11.14.AdapterClasses
Section11.15.JPanelSubclassforDrawingwiththeMouse
Section11.16.Key-EventHandling
Section11.17.LayoutManagers
Section11.18.UsingPanelstoManageMoreComplexLayouts
Section11.19.JTextArea

Section11.20.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter12.GraphicsandJava2D™
Section12.1.Introduction
Section12.2.GraphicsContextsandGraphicsObjects
Section12.3.ColorControl
Section12.4.FontControl
Section12.5.DrawingLines,RectanglesandOvals
Section12.6.DrawingArcs
Section12.7.DrawingPolygonsandPolylines
Section12.8.Java2DAPI
Section12.9.Wrap-Up
Summary
Terminology

515
518
522
529
530
533
536
543
546
549
551

556
559
563
567
576
578
581
581
587
589
590
590
595
596
598
599
606
611
616
618
622
629
629
631




Self-ReviewExercises


632



AnswerstoSelf-ReviewExercises

633


Exercises

Chapter13.ExceptionHandling

Section13.1.Introduction

Section13.2.Exception-HandlingOverview

Section13.3.Example:DivideByZeroWithoutException

Handling

Section13.4.Example:HandlingArithmeticExceptionsand

InputMismatchExceptions

Section13.5.WhentoUseExceptionHandling

Section13.6.JavaExceptionHierarchy

Section13.7.finallyblock


Section13.8.StackUnwinding

Section13.9.printStackTrace,getStackTraceandgetMessage

Section13.10.ChainedExceptions

Section13.11.DeclaringNewExceptionTypes

Section13.12.PreconditionsandPostconditions

Section13.13.Assertions

Section13.14.Wrap-Up

Summary

Terminology

Self-ReviewExercises

AnswerstoSelf-ReviewExercises

Exercises

Chapter14.FilesandStreams

Section14.1.Introduction

Section14.2.DataHierarchy


Section14.3.FilesandStreams

Section14.4.ClassFile

Section14.5.Sequential-AccessTextFiles

Section14.6.ObjectSerialization

Section14.7.Random-AccessFiles

Section14.8.Additionaljava.ioClasses

Section14.9.OpeningFileswithJFileChooser

Section14.10.Wrap-Up

Summary

633
638
639
640



735

Terminology


641
643
648
649
652
656
658
660
662
663
664
666
666
668
669
670
670
672
673
674
675
678
682
697
706
727
729
733
733















































































Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter15.Recursion
Section15.1.Introduction
Section15.2.RecursionConcepts
Section15.3.ExampleUsingRecursion:Factorials
Section15.4.ExampleUsingRecursion:FibonacciSeries
Section15.5.RecursionandtheMethodCallStack
Section15.6.Recursionvs.Iteration
Section15.7.StringPermutations
Section15.8.TowersofHanoi
Section15.9.Fractals
Section15.10.RecursiveBacktracking
Section15.11.Wrap-Up

Section15.12.InternetandWebResources
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter16.SearchingandSorting
Section16.1.Introduction
Section16.2.SearchingAlgorithms
Section16.3.SortingAlgorithms
Section16.4.Invariants
Section16.5.Wrap-up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter17.DataStructures
Section17.1.Introduction
Section17.2.Type-WrapperClassesforPrimitiveTypes
Section17.3.AutoboxingandAuto-Unboxing
Section17.4.Self-ReferentialClasses
Section17.5.DynamicMemoryAllocation

737
738
739
744
745
745

747
750
753
754
756
761
763
774
775
775
776
778
779
780
780
785
786
786
796
810
812
812
814
814
814
814
817
818
819
819

820
821




Section17.6.LinkedLists

821




Section17.7.Stacks
Section17.8.Queues

832
836




































































Section17.9.Trees
Section17.10.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises

Exercises
SpecialSection:BuildingYourOwnCompiler
Chapter18.Generics
Section18.1.Introduction
Section18.2.MotivationforGenericMethods
Section18.3.GenericMethods:ImplementationandCompileTimeTranslation
Section18.4.AdditionalCompile-TimeTranslationIssues:
MethodsThatUseaTypeParameterastheReturnType
Section18.5.OverloadingGenericMethods
Section18.6.GenericClasses
Section18.7.RawTypes
Section18.8.WildcardsinMethodsThatAcceptType
Parameters
Section18.9.GenericsandInheritance:Notes
Section18.10.Wrap-Up
Section18.11.InternetandWebResources
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter19.Collections
Section19.1.Introduction
Section19.2.CollectionsOverview
Section19.3.ClassArrays
Section19.4.InterfaceCollectionandClassCollections
Section19.5.Lists
Section19.6.CollectionsAlgorithms
Section19.7.StackClassofPackagejava.util


838
845
846
847
848
849
850
855
869
870
871
873
876
879
879
890
891
898
898
899
899
901
901
902
902
904
905
906
907
910

911
922
935




Section19.8.ClassPriorityQueueandInterfaceQueue

938




Section19.9.Sets
Section19.10.Maps

939
942










































































Section19.11.PropertiesClass
Section19.12.SynchronizedCollections
Section19.13.UnmodifiableCollections
Section19.14.AbstractImplementations
Section19.15.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter20.IntroductiontoJavaApplets
Section20.1.Introduction
Section20.2.SampleAppletsProvidedwiththeJDK
Section20.3.SimpleJavaApplet:DrawingaString
Section20.4.AppletLife-CycleMethods
Section20.5.InitializinganInstanceVariablewithMethodinit
Section20.6.SandboxSecurityModel
Section20.7.InternetandWebResources
Section20.8.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter21.Multimedia:AppletsandApplications
Section21.1.Introduction
Section21.2.Loading,DisplayingandScalingImages
Section21.3.AnimatingaSeriesofImages
Section21.4.ImageMaps
Section21.5.LoadingandPlayingAudioClips

Section21.6.PlayingVideoandOtherMediawithJavaMedia
Framework
Section21.7.Wrap-Up
Section21.8.InternetandWebResources
Summary
Terminology

946
949
950
950
951
951
954
955
955
956
958
959
959
964
968
970
972
972
973
973
975
975
975

975
977
978
979
982
987
987
993
997
998
999
1000




Self-ReviewExercises

1001



AnswerstoSelf-ReviewExercises

1001
































































Exercises
SpecialSection:ChallengingMultimediaProjects
Chapter22.GUIComponents:Part2

Section22.1.Introduction
Section22.2.JSlider
Section22.3.Windows:AdditionalNotes
Section22.4.UsingMenuswithFrames
Section22.5.JPopupMenu
Section22.6.PluggableLook-and-Feel
Section22.7.JDesktopPaneandJInternalFrame
Section22.8.JTabbedPane
Section22.9.LayoutManagers:BoxLayoutandGridBagLayout
Section22.10.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter23.Multithreading
Section23.1.Introduction
Section23.2.ThreadStates:LifeCycleofaThread
Section23.3.ThreadPrioritiesandThreadScheduling
Section23.4.CreatingandExecutingThreads
Section23.5.ThreadSynchronization
Section23.6.Producer/ConsumerRelationshipwithout
Synchronization
Section23.7.Producer/ConsumerRelationshipwith
Synchronization
Section23.8.Producer/ConsumerRelationship:CircularBuffer
Section23.9.Producer/ConsumerRelationship:
ArrayBlockingQueue
Section23.10.MultithreadingwithGUI
Section23.11.OtherClassesandInterfacesin

java.util.concurrent
Section23.12.MonitorsandMonitorLocks
Section23.13.Wrap-Up

1001
1002
1005
1006
1006
1010
1011
1019
1022
1026
1030
1032
1046
1046
1048
1049
1050
1050
1052
1053
1055
1056
1058
1062
1064
1071

1076
1084
1087
1093
1093
1100






































































Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter24.Networking
Section24.1.Introduction
Section24.2.ManipulatingURLs
Section24.3.ReadingaFileonaWebServer
Section24.4.EstablishingaSimpleServerUsingStream
Sockets
Section24.5.EstablishingaSimpleClientUsingStream
Sockets
Section24.6.Client/ServerInteractionwithStreamSocket
Connections
Section24.7.ConnectionlessClient/ServerInteractionwith

Datagrams
Section24.8.Client/ServerTic-Tac-ToeUsingaMultithreaded
Server
Section24.9.SecurityandtheNetwork
Section24.10.CaseStudy:DeitelMessengerServerandClient
Section24.11.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter25.AccessingDatabaseswithJDBC
Section25.1.Introduction
Section25.2.RelationalDatabases
Section25.3.RelationalDatabaseOverview:Thebooks
Database
Section25.4.SQL
Section25.5.InstructionstoinstallMySQLandMySQL
Connector/J
Section25.6.InstructionsonSettingMySQLUserAccount
Section25.7.CreatingDatabasebooksinMySQL
Section25.8.ManipulatingDatabaseswithJDBC
Section25.9.StoredProcedures
Section25.10.RowSetInterface

1100
1102
1103
1104
1104

1106
1107
1108
1114
1117
1119
1119
1132
1139
1154
1155
1181
1181
1183
1184
1185
1185
1189
1190
1191
1192
1196
1206
1206
1207
1207
1224
1224





Section25.11.Wrap-Up

1227




Section25.12.InternetandWebResources
RecommendedReadings

1227
1228









































































Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises

Chapter26.Servlets
Section26.1.Introduction
Section26.2.ServletOverviewandArchitecture
Section26.3.SettingUptheApacheTomcatServer
Section26.4.HandlingHTTPgetRequests
Section26.5.HandlingHTTPgetRequestsContainingData
Section26.6.HandlingHTTPpostRequests
Section26.7.RedirectingRequeststoOtherResources
Section26.8.MultitierApplications:UsingJDBCfromaServlet
Section26.9.WelcomeFiles
Section26.10.Wrap-Up
Section26.11.InternetandWebResources
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter27.JavaServerPages(JSP)
Section27.1.Introduction
Section27.2.JavaServerPagesOverview
Section27.3.FirstJSPExample
Section27.4.ImplicitObjects
Section27.5.Scripting
Section27.6.StandardActions
Section27.7.Directives
Section27.8.CaseStudy:GuestBook
Section27.9.Wrap-Up
Section27.10.InternetandWebResources
Summary
Terminology


1229
1232
1234
1234
1234
1236
1237
1239
1243
1246
1255
1258
1261
1265
1270
1274
1274
1275
1277
1277
1278
1278
1280
1281
1282
1283
1285
1286
1291

1305
1309
1321
1321
1321
1323




Self-ReviewExercises

1324




AnswerstoSelf-ReviewExercises
Exercises

1325
1325








































































Chapter28.FormattedOutput
Section28.1.Introduction
Section28.2.Streams
Section28.3.FormattingOutputwithprintf
Section28.4.PrintingIntegers
Section28.5.PrintingFloating-PointNumbers
Section28.6.PrintingStringsandCharacters
Section28.7.PrintingDatesandTimes
Section28.8.OtherConversionCharacters
Section28.9.PrintingwithFieldWidthsandPrecisions
Section28.10.UsingFlagsintheprintfFormatString
Section28.11.PrintingwithArgumentIndices
Section28.12.PrintingLiteralsandEscapeSequences
Section28.13.FormattingOutputwithClassFormatter
Section28.14.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises
Chapter29.Strings,CharactersandRegularExpressions
Section29.1.Introduction
Section29.2.FundamentalsofCharactersandStrings
Section29.3.ClassString
Section29.4.ClassStringBuffer
Section29.5.ClassCharacter
Section29.6.ClassStringTokenizer
Section29.7.RegularExpressions,ClassPatternandClass
Matcher

Section29.8.Wrap-Up
Summary
Terminology
Self-ReviewExercises
AnswerstoSelf-ReviewExercises
Exercises

1326
1327
1327
1328
1328
1329
1330
1331
1335
1335
1337
1342
1342
1342
1344
1344
1346
1346
1347
1348
1350
1351
1352

1352
1364
1372
1376
1378
1387
1387
1391
1391
1392
1392




SpecialSection:AdvancedString-ManipulationExercises

1393


SpecialSection:ChallengingString-ManipulationProjects

AppendixA.OperatorPrecedenceChart

SectionA.1.OperatorPrecedence

1396
1398
1398

































1400
1401
1402
1403
1416
1427
1427
1428
1437
1449
1464
1489
1492
1494
1515
EULA-1
EULA-1
EULA-2
EULA-4
EULA-7
EULA-11
EULA-12
EULA-17
InsideBackCover
InsideBackCover
InsideBackCover
InsideBackCover
InsideBackCover

















AppendixB.ASCIICharacterSet
AppendixC.KeywordsandReservedWords
AppendixD.PrimitiveTypes
AppendixE.(OnCD)NumberSystems
AppendixF.(OnCD)Unicode®
AppendixG.UsingtheJavaAPIDocumentation
SectionG.1.Introduction
SectionG.2.NavigatingtheJavaAPI
AppendixH.(OnCD)CreatingDocumentationwithjavadoc
AppendixI.(OnCD)BitManipulation
AppendixJ.(OnCD)ATMCaseStudyCode
AppendixK.(OnCD)LabeledbreakandcontinueStatements
AppendixL.(OnCD)UML2:AdditionalDiagramTypes
AppendixM.(OnCD)DesignPatterns
AppendixN.UsingtheDebugger
EndUserLicenseAgreements

PrenticeHallLicenseAgreementandLimitedWarranty
ApacheTomcatLicenseAgreement
JCreator™LicenseAgreement
jEditLicenseAgreement
jGRASP™LicenseAgreement
NetBeans™LicenseAgreement
MySQL®OpenSourceLicense
InsideBackCover
LicenseAgreementandLimitedWarranty
UsingtheCD-ROM
ContentsoftheCD-ROM
SoftwareandHardwareSystemRequirements
Index


[Pageiv]


Copyright
LibraryofCongressCataloging-in-PublicationData
Onfile
VicePresidentandEditorialDirector,ECS:MarciaJ.
Horton
SeniorAcquisitionsEditor:KateHargett
AssociateEditor:JenniferCappello
AssistantEditor:SarahParker
EditorialAssistant:MichaelGiacobbe
VicePresidentandDirectorofProductionand
Manufacturing,ESM:DavidW.Riccardi
ExecutiveManagingEditor:VinceO'Brien

ManagingEditor:TomManshreck
ProductionEditor:JohnF.Lovell
ProductionEditor,Media:BobEngelhardt
ProductionAssistant:AshaRohra
DirectorofCreativeServices:PaulBelfanti
A/VProductionEditor:XiaohongZhu


ArtStudio:Artworks,York,PA
ArtDirector:GeoffreyCassar
CoverDesign:HarveyM.Deitel,ShawnMurphy,
GeoffreyCassar
InteriorDesign:HarveyM.Deitel,GeoffreyCassar
ManufacturingManager:TrudyPisciotti
ManufacturingBuyer:LisaMcDowell
MarketingManager:PamelaHersperger
MarketingAssistant:BarrieReinhold
©2005byPearsonEducation,Inc.
UpperSaddleRiver,NewJersey07458
Theauthorsandpublisherofthisbookhaveusedtheirbest
effortsinpreparingthisbook.Theseeffortsincludethe
development,research,andtestingofthetheoriesand
programstodeterminetheireffectiveness.Theauthorsand
publishermakenowarrantyofanykind,expressedorimplied,
withregardtotheseprogramsortothedocumentation
containedinthisbook.Theauthorsandpublishershallnotbe
liableinanyeventforincidentalorconsequentialdamagesin
connectionwith,orarisingoutof,thefurnishing,performance,
oruseoftheseprograms.
Manyofthedesignationsusedbymanufacturersandsellersto

distinguishtheirproductsareclaimedastrademarksand
registeredtrademarks.Wherethosedesignationsappearinthis
book,andPrenticeHallandtheauthorswereawareofa


trademarkclaim,thedesignationshavebeenprintedininitial
capsorallcaps.Allproductnamesmentionedremain
trademarksorregisteredtrademarksoftheirrespectiveowners.
Allrightsreserved.Nopartofthisbookmaybereproduced,in
anyformorbyanymeans,withoutpermissioninwritingfrom
thepublisher.
PrintedintheUnitedStatesofAmerica
10987654321
PearsonEducationLtd.,London
PearsonEducationAustraliaPty.Ltd.,Sydney
PearsonEducationSingapore,Pte.Ltd.
PearsonEducationNorthAsiaLtd.,HongKong
PearsonEducationCanada,Inc.,Toronto
PearsonEducaciondeMexico,S.A.deC.V.
PearsonEducationJapan,Tokyo
PearsonEducationMalaysia,Pte.Ltd.
PearsonEducation,Inc.,UpperSaddleRiver,NewJersey

[Pagevi]

Trademarks
JavaandallJava-basedmarksaretrademarksorregistered
trademarksofSunMicrosystems,Inc.intheUnitedStatesand
othercountries.PearsonEducationisindependentofSun
Microsystems,Inc.

Microsoft,Microsoft®InternetExplorerandtheWindowslogo
areeitherregisteredtrademarksortrademarksofMicrosoft
CorporationintheUnitedStatesand/orothercountries.


Netscapebrowserwindow©2004NetscapeCommunications
Corporation.Usedwithpermission.NetscapeCommunications
hasnotauthorized,sponsored,endorsed,orapprovedthis
publicationandisnotresponsibleforitscontent.
MySQLisaregisteredtrademarkofMySQLABintheUnited
States,theEuropeanUnionandothercountries.
Copyright®19992002TheApacheSoftwareFoundation.All
RightsReserved.

[Pagevii]

Dedication
InmemoryofEdsgerW.Dijkstra:
Wecontinuetolearnfromyourwritingseveryday.
HarveyM.DeitelandPaulJ.Deitel


[Pageii]


Deitel®Books,CyberClassrooms,
CompleteTrainingCoursesandWebBasedTrainingCoursespublishedby
PrenticeHall
HowToProgramSeries
AdvancedJava™2PlatformHowtoProgram

CHowtoProgram,4/E
C++HowtoProgram,4/E
C#HowtoProgram
e-Businessande-CommerceHowtoProgram
InternetandWorldWideWebHowtoProgram,3/E
JavaHowtoProgram,6/E
SmallJava™HowtoProgram,6/E
PerlHowtoProgram
PythonHowtoProgram
VisualC++®.NETHowtoProgram
VisualBasic®6HowtoProgram


×