Java: An Introduction to Problem Solving and Programming, Global Edition

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Walter Savitch
Edition: 8
Publisher: Pearson Education Limited
Year: 2019

Language: English
Pages: 1056

Cover......Page 1
Inside Front Cover......Page 2
Title Page......Page 5
Copyright Page......Page 6
Preface for Instructors......Page 7
Preface for Students......Page 12
Acknowledgments......Page 17
Acknowledgments for the Global Edition......Page 20
Dependency Chart......Page 21
Brief Contents......Page 25
Contents......Page 27
Chapter 1 Introduction to Computers and Java......Page 39
1.1 COMPUTER BASICS......Page 40
Hardware and Memory......Page 41
Programs......Page 44
Programming Languages, Compilers, and Interpreters......Page 45
Java Bytecode......Page 47
Class Loader......Page 49
History of the Java Language......Page 50
Applications and Applets......Page 51
A First Java Application Program......Page 52
Writing, Compiling, and Running a Java Program......Page 57
Object-Oriented Programming......Page 59
Algorithms......Page 63
Testing and Debugging......Page 65
Software Reuse......Page 66
1.4 GRAPHICS SUPPLEMENT......Page 68
A Sample JavaFX Application......Page 69
Size and Position of Figures......Page 72
Drawing Ovals and Circles......Page 73
Drawing Arcs......Page 75
Chapter 2 Basic Computation......Page 87
2.1 VARIABLES AND EXPRESSIONS......Page 88
Variables......Page 89
Data Types......Page 91
Java Identifiers......Page 93
Assignment Statements......Page 95
Simple Input......Page 98
Constants......Page 100
Named Constants......Page 102
Assignment Compatibilities......Page 103
Type Casting......Page 105
Arithmetic Operators......Page 108
Parentheses and Precedence Rules......Page 111
Specialized Assignment Operators......Page 112
Case Study: Vending Machine Change......Page 114
Increment and Decrement Operators......Page 119
More About the Increment and Decrement Operators......Page 120
String Constants and Variables......Page 121
Concatenation of Strings......Page 122
String Methods......Page 123
String Processing......Page 125
Escape Characters......Page 128
The Unicode Character Set......Page 129
Screen Output......Page 131
Keyboard Input......Page 134
Other Input Delimiters (Optional)......Page 139
Formatted Output with printf (Optional)......Page 141
Meaningful Variable Names......Page 143
Comments......Page 144
Using Named Constants......Page 147
2.5 GRAPHICS SUPPLEMENT......Page 149
Style Rules Applied to a JavaFX Application......Page 150
Introducing the Class JOptionPane......Page 152
Reading Input as Other Numeric Types......Page 161
Programming Example: Change-Making Program with Windowing I/O......Page 162
Chapter 3 Flow of Control: Branching......Page 177
3.1 THE if-else STATEMENT......Page 178
The Basic if-else Statement......Page 179
Boolean Expressions......Page 186
Comparing Strings......Page 191
Nested if-else Statements......Page 196
Multibranch if-else Statements......Page 198
Programming Example: Assigning Letter Grades......Page 200
Case Study: Body Mass Index......Page 203
The exit Method......Page 206
3.2 THE TYPE boolean......Page 207
Boolean Variables......Page 208
Precedence Rules......Page 209
Input and Output of Boolean Values......Page 212
3.3 THE switch STATEMENT......Page 214
Enumerations......Page 220
3.4 GRAPHICS SUPPLEMENT......Page 221
Specifying a Drawing Color......Page 222
A Dialog Box for a Yes-or-No Question......Page 226
Chapter 4 Flow of Control: Loops......Page 239
4.1 JAVA LOOP STATEMENTS......Page 240
The while Statement......Page 241
The do-while Statement......Page 244
Programming Example: Bug Infestation......Page 249
Programming Example: Nested Loops......Page 255
The for Statement......Page 257
Declaring Variables Within a for Statement......Page 263
Using a Comma in a for Statement (Optional)......Page 264
4.2 PROGRAMMING WITH LOOPS......Page 266
The Loop Body......Page 267
Initializing Statements......Page 268
Controlling the Number of Loop Iterations......Page 269
Case Study: Using a Boolean Variable to End a Loop......Page 271
Programming Example: Spending Spree......Page 273
The break Statement and continue Statement in Loops (Optional)......Page 276
Loop Bugs......Page 279
Tracing Variables......Page 281
Assertion Checks......Page 283
Programming Example: A Multiface JavaFX Application......Page 285
Drawing Text......Page 290
Chapter 5 Defining Classes and Methods......Page 307
5.1 CLASS AND METHOD DEFINITIONS......Page 309
Programming Example: Implementing a Dog Class......Page 311
Instance Variables......Page 312
Methods......Page 315
Defining void Methods......Page 318
Defining Methods That Return a Value......Page 319
Programming Example: First Try at Implementing a Species Class......Page 324
The Keyword this......Page 328
Local Variables......Page 330
Blocks......Page 332
Parameters of a Primitive Type......Page 333
5.2 INFORMATION HIDING AND ENCAPSULATION......Page 339
Precondition and Postcondition Comments......Page 340
The public and private Modifiers......Page 342
Programming Example: A Demonstration of Why Instance Variables Should Be Private......Page 345
Programming Example: Another Implementation of a Class of Rectangles......Page 346
Accessor Methods and Mutator Methods......Page 348
Programming Example: A Purchase Class......Page 352
Methods Calling Methods......Page 356
Encapsulation......Page 362
Automatic Documentation with javadoc......Page 365
UML Class Diagrams......Page 366
5.3 OBJECTS AND REFERENCES......Page 367
Variables of a Class Type......Page 368
Defining an equals Method for a Class......Page 373
Programming Example: A Species Class......Page 377
Boolean-Valued Methods......Page 380
Case Study: Unit Testing......Page 382
Parameters of a Class Type......Page 384
Programming Example: Class-Type Parameters Versus Primitive-Type Parameters......Page 388
The GraphicsContext Class......Page 392
Programming Example: Multiple Faces, but with a Helping Method......Page 396
Adding Labels to a JavaFX Application......Page 400
Chapter 6 More About Objects and Methods......Page 421
Defining Constructors......Page 423
Calling Methods from Constructors......Page 432
Calling a Constructor from Other Constructors (Optional)......Page 435
Static Variables......Page 437
Static Methods......Page 438
Dividing the Task of a main Method into Subtasks......Page 445
Adding a main Method to a Class......Page 446
The Math Class......Page 448
Wrapper Classes......Page 451
Case Study: Formatting Output......Page 457
Decomposition......Page 463
Addressing Compiler Concerns......Page 464
Testing Methods......Page 466
Overloading Basics......Page 468
Overloading and Automatic Type Conversion......Page 471
Overloading and the Return Type......Page 474
Programming Example: A Class for Money......Page 476
Privacy Leaks......Page 483
6.6 ENUMERATION AS A CLASS......Page 487
6.7 PACKAGES......Page 489
Packages and Importing......Page 490
Package Names and Directories......Page 491
Name Clashes......Page 494
Adding Icons......Page 495
Chapter 7 Arrays......Page 515
7.1 ARRAY BASICS......Page 517
Creating and Accessing Arrays......Page 518
Array Details......Page 521
The Instance Variable length......Page 524
More About Array Indices......Page 527
Initializing Arrays......Page 530
Case Study: Sales Report......Page 532
Indexed Variables as Method Arguments......Page 540
Entire Arrays as Arguments to a Method......Page 543
Arguments for the Method main......Page 544
Array Assignment and Equality......Page 545
Methods That Return Arrays......Page 548
Programming Example: A Specialized List Class......Page 552
Partially Filled Arrays......Page 560
Selection Sort......Page 562
Other Sorting Algorithms......Page 566
Searching an Array......Page 568
7.5 MULTIDIMENSIONAL ARRAYS......Page 569
Multidimensional-Array Basics......Page 570
Multidimensional-Array Parameters and Returned Values......Page 573
Java’s Representation of Multidimensional Arrays......Page 576
Ragged Arrays (Optional)......Page 577
Programming Example: Employee Time Records......Page 579
Layout Panes......Page 585
Text Areas, Text Fields and Combining Layouts......Page 593
Drawing Polygons......Page 598
Chapter 8 Inheritance, Polymorphism, and Interfaces......Page 623
8.1 INHERITANCE BASICS......Page 624
Derived Classes......Page 626
Overriding Method Definitions......Page 630
The final Modifier......Page 631
Private Instance Variables and Private Methods of a Base Class......Page 632
UML Inheritance Diagrams......Page 634
Constructors in Derived Classes......Page 637
Calling an Overridden Method......Page 639
Programming Example: A Derived Class of a Derived Class......Page 640
Type Compatibility......Page 645
The Class Object......Page 650
A Better equals Method......Page 652
Dynamic Binding and Inheritance......Page 654
Dynamic Binding with toString......Page 657
Class Interfaces......Page 659
Java Interfaces......Page 660
Implementing an Interface......Page 661
An Interface as a Type......Page 663
Extending an Interface......Page 666
Case Study: Character Graphics......Page 667
Case Study: The Comparable Interface......Page 680
Abstract Classes......Page 684
8.5 GRAPHICS SUPPLEMENT......Page 686
Event-Driven Programming......Page 687
Event Handling in a Separate Class......Page 688
Event Handling in the Main GUI Application Class......Page 691
Event Handling in an Anonymous Inner Class......Page 693
Programming Example: Adding Numbers......Page 696
Chapter 9 Exception Handling......Page 711
9.1 BASIC EXCEPTION HANDLING......Page 712
Exceptions in Java......Page 713
Predefined Exception Classes......Page 723
9.2 DEFINING YOUR OWN EXCEPTION CLASSES......Page 725
Declaring Exceptions (Passing the Buck)......Page 735
Kinds of Exceptions......Page 738
Errors......Page 740
Multiple Throws and Catches......Page 741
The finally Block......Page 747
Rethrowing an Exception (Optional)......Page 748
Case Study: A Line-Oriented Calculator......Page 749
Additional User Interface Controls and Shapes......Page 761
Images and Shapes......Page 765
Handling Mouse Events......Page 767
The Timeline Class......Page 771
Chapter 10 Streams, File I/O, and Networking......Page 787
The Concept of a Stream......Page 789
Text Files and Binary Files......Page 790
Creating a Text File......Page 792
Appending to a Text File......Page 798
Reading from a Text File......Page 800
Programming Example: Reading a File Name from the Keyboard......Page 803
Using Path Names......Page 805
Methods of the Class File......Page 806
Defining a Method to Open a Stream......Page 808
Case Study: Processing a Comma-Separated Values File......Page 810
Creating a Binary File......Page 813
Writing Primitive Values to a Binary File......Page 815
Writing Strings to a Binary File......Page 818
Some Details About writeUTF......Page 819
Reading from a Binary File......Page 820
The Class EOFException......Page 826
Programming Example: Processing a File of Binary Data......Page 828
Binary-File I/O with Objects of a Class......Page 833
Some Details of Serialization......Page 837
Array Objects in Binary Files......Page 838
10.6 NETWORK COMMUNICATION WITH STREAMS......Page 841
Programming Example: A JavaFX GUI for Manipulating Files......Page 847
Chapter 11 Recursion......Page 869
11.1 THE BASICS OF RECURSION......Page 870
Case Study: Digits to Words......Page 873
How Recursion Works......Page 878
Infinite Recursion......Page 882
Recursive Methods Versus Iterative Methods......Page 884
Recursive Methods That Return a Value......Page 886
Programming Example: Insisting That User Input Be Correct......Page 890
Case Study: Binary Search......Page 892
Programming Example: Merge Sort—A Recursive Sorting Method......Page 900
Lambda Functions and Event Handlers......Page 904
Chapter 12 Dynamic Data Structures and Generics......Page 921
12.1 ARRAY-BASED DATA STRUCTURES......Page 923
Creating an Instance of ArrayList......Page 924
Using the Methods of ArrayList......Page 926
Programming Example: A To-Do List......Page 930
The Collection Interface......Page 933
The Class HashSet......Page 934
The Class HashMap......Page 936
The Class LinkedList......Page 939
Linked Lists......Page 940
Implementing the Operations of a Linked List......Page 943
A Privacy Leak......Page 950
Inner Classes......Page 951
Iterators......Page 952
Exception Handling with Linked Lists......Page 964
Variations on a Linked List......Page 966
Other Linked Data Structures......Page 968
The Basics......Page 969
Programming Example: A Generic Linked List......Page 972
Building JavaFX Applications with the Scene Builder......Page 977
Where to Go from Here......Page 983
1 Getting Java......Page 999
2 Running Applets......Page 1000
3 Protected and Package Modifiers......Page 1002
4 The DecimalFormat Class......Page 1003
Other Pattern Symbols......Page 1004
Commenting Classes for Use with javadoc......Page 1007
Running javadoc......Page 1008
Flow of Control......Page 1010
Files and Including Files......Page 1011
Arrays......Page 1012
Other Comparisons......Page 1013
7 Unicode Character Codes......Page 1014
8 Introduction to Java 8 Functional Programming......Page 1015
9 The Iterator Interface......Page 1019
10 Cloning......Page 1021
11 Java Reserved Keywords......Page 1025
CREDITS......Page 1026
A......Page 1029
B......Page 1031
C......Page 1032
D......Page 1035
E......Page 1036
F......Page 1037
G......Page 1038
I......Page 1039
J......Page 1041
L......Page 1042
M......Page 1043
N......Page 1044
O......Page 1045
P......Page 1046
R......Page 1048
S......Page 1049
T......Page 1052
V......Page 1053
Z......Page 1054
Inside Back Cover......Page 1055
Back Cover......Page 1056