Introduction to Programming With JAVA: A problem solving approach

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): John Dean, Raymond Dean
Edition: 2
Publisher: McGraw-Hill
Year: 2014

Language: English
Pages: 961
City: New York

Cover......Page 1
Title......Page 2
Copyright......Page 3
Contents......Page 6
Preface......Page 11
Project Summary......Page 26
1.1. Introduction......Page 40
1.2. Hardware Terminology......Page 41
1.3. Program Development......Page 49
1.4. Source Code......Page 51
1.5. Compiling Source Code into Object Code......Page 52
1.6. Portability......Page 53
1.7. Emergence of Java......Page 54
1.8. Computer Ethics......Page 56
1.9. First Program—Hello World......Page 57
1.10. GUI Track: Hello World and Look and Feel (Optional)......Page 61
2.1. Introduction......Page 68
2.2. Output......Page 69
2.3. Variables......Page 70
2.4. Operators and Assignment Statements......Page 71
2.5. Input......Page 72
2.6. Flow of Control and Flowcharts......Page 73
2.7. if Statements......Page 74
2.8. Loops......Page 79
2.9. Loop Termination Techniques......Page 81
2.10. Nested Looping......Page 84
2.11. Tracing......Page 87
2.12. Problem Solving: Other Pseudocode Formats and an Asset Management Example......Page 91
CHAPTER 3 Java Basics......Page 101
3.2. "I Have a Dream" Program......Page 102
3.3. Comments and Readability......Page 103
3.5. The main Method's Heading......Page 105
3.6. Braces......Page 106
3.7. System.out.println......Page 107
3.9. Identifiers......Page 109
3.10. Variables......Page 110
3.11. Assignment Statements......Page 111
3.12. Initialization Statements......Page 113
3.13. Numeric Data Types—int, long, float, double......Page 114
3.14. Constants......Page 116
3.15. Arithmetic Operators......Page 119
3.16. Expression Evaluation and Operator Precedence......Page 122
3.17. More Operators: Increment, Decrement, and Compound Assignment......Page 124
3.19. Type Casting......Page 126
3.20. char Type and Escape Sequences......Page 129
3.21. Primitive Variables Versus Reference Variables......Page 131
3.22. Strings......Page 132
3.23. Input—the Scanner Class......Page 136
3.24. Simple File Input for Repetitive Testing During Program Development......Page 141
3.25. GUI Track: Input and Output with JOptionPane (Optional)......Page 143
CHAPTER 4 Control Statements......Page 154
4.2. Conditions and Boolean Values......Page 155
4.3. if Statements......Page 156
4.4. && Logical Operator......Page 159
4.5. | | Logical Operator......Page 164
4.6. ! Logical Operator......Page 166
4.7. switch Statement......Page 167
4.8. while Loop......Page 171
4.9. do Loop......Page 174
4.10. for Loop......Page 175
4.11. Solving the Problem of Which Loop to Use......Page 180
4.12. Nested Loops......Page 181
4.13. boolean Variables......Page 183
4.14. Input Validation......Page 187
4.15. Problem Solving with Boolean Logic (Optional)......Page 188
CHAPTER 5 Using Prebuilt Methods......Page 201
5.1. Introduction......Page 202
5.2. The API Library......Page 203
5.3. Math Class......Page 206
5.4. Wrapper Classes for Primitive Types......Page 211
5.5. Character Class......Page 215
5.6. String Methods......Page 217
5.7. Formatted Output with the printf Method......Page 223
5.8. Problem Solving with Random Numbers (Optional)......Page 227
5.9. GUI Track: Drawing Images, Lines, Rectangles, and Ovals in Java Applets (Optional)......Page 232
5.10. GUI Track: Decorating an Image by Covering It With a Tinted Pane (Optional)......Page 239
Multiple-Method Programs in a Non-Object-Oriented Environment......Page 248
CHAPTER 6 Object-Oriented Programming......Page 252
6.2. Object-Oriented Programming Overview......Page 253
6.3. First OOP Class......Page 256
6.4. Driver Class......Page 260
6.5. Calling Object, this Reference......Page 263
6.6. Instance Variables......Page 266
6.7. Tracing an OOP Program......Page 267
6.8. UML Class Diagrams......Page 272
6.9. Local Variables......Page 273
6.10. The return Statement......Page 275
6.11. Argument Passing......Page 279
6.12. Specialized Methods—Accessors, Mutators, and Boolean Methods......Page 281
6.13. Problem Solving with Simulation (Optional)......Page 284
CHAPTER 7 Object-Oriented Programming—Additional Details......Page 301
7.2. Object Creation—A Detailed Analysis......Page 302
7.3. Assigning a Reference......Page 304
7.4. Testing Objects for Equality......Page 308
7.5. Passing References as Arguments......Page 313
7.6. Method-Call Chaining......Page 316
7.7. Overloaded Methods......Page 318
7.8. Constructors......Page 322
7.9. Overloaded Constructors......Page 328
7.10. Class Variables......Page 332
7.11. Class Methods......Page 335
7.12. Named Constants......Page 341
7.13. Problem Solving with Multiple Driven Classes......Page 343
CHAPTER 8 Software Engineering......Page 356
8.2. Coding-Style Conventions......Page 357
8.3. Documentation for Outsiders......Page 366
8.4. Helper Methods......Page 369
8.5. Encapsulation (with Instance Variables and Local Variables)......Page 374
8.6. Recognizing the User's Point of View......Page 376
8.7. Design Philosophy......Page 377
8.8. Top-Down Design......Page 381
8.9. Bottom-Up Design......Page 390
8.11. Iterative Enhancement......Page 392
8.12. Merging the Driver Method into the Driven Class......Page 394
8.14. Writing Your Own Utility Class......Page 396
8.15. Problem Solving with the API Calendar Class (Optional)......Page 399
8.16. GUI Track: Problem Solving with CRC Cards (Optional)......Page 401
CHAPTER 9 Arrays......Page 415
9.2. Array Basics......Page 416
9.3. Array Declaration and Creation......Page 418
9.4. Array length Property and Partially Filled Arrays......Page 422
9.5. Copying an Array......Page 424
9.6. Problem Solving with Array Case Studies......Page 427
9.7. Searching an Array......Page 432
9.8. Sorting an Array......Page 439
9.9. Two-Dimensional Arrays......Page 443
9.10. Arrays of Objects......Page 449
9.11. For-Each Loops......Page 455
CHAPTER 10 ArrayList s and an Introduction to the Java Collections Framework......Page 466
10.1. Introduction......Page 467
10.2. The ArrayList Class......Page 468
10.3. Storing Primitives in an ArrayList......Page 474
10.4. ArrayList Example Using Anonymous Objects and the For-Each Loop......Page 477
10.5. ArrayLists Versus Standard Arrays......Page 481
10.6. The LinkedList Class......Page 482
10.7. The List Interface......Page 483
10.8. Problem Solving: How to Compare Method Execution Times......Page 484
10.9. Queues, Stacks, and the ArrayDeque Class......Page 488
10.10. Overview of the Java Collections Framework......Page 495
10.11. Collections Example—Information Flow in a Network of Friends......Page 498
CHAPTER 11 Recursion......Page 512
11.1. Introduction......Page 513
11.2. Guidelines for Writing a Recursive Method......Page 514
11.3. A Recursive Factorial Method......Page 515
11.4. Comparison of Recursive and Iterative Solutions......Page 519
11.5. Recursive Method Evaluation Practice......Page 523
11.6. Binary Search......Page 526
11.7. Merge Sort......Page 529
11.8. Towers of Hanoi......Page 533
11.9. GUI Track: Drawing Trees with a Fractal Algorithm (Optional)......Page 537
11.10. Performance Analysis......Page 546
CHAPTER 12 Type Details and Alternative Coding Mechanisms......Page 555
12.2. Integer Types and Floating-Point Types......Page 556
12.3. char Type and the ASCII Character Set......Page 560
12.4. Type Conversions......Page 563
12.5. Prefix/Postfix Modes for Increment/Decrement Operators......Page 565
12.6. Embedded Assignments......Page 568
12.7. Conditional Operator Expressions......Page 570
12.8. Expression Evaluation Review......Page 571
12.9. Short-Circuit Evaluation......Page 575
12.10. Empty Statement......Page 576
12.11. break Statement Within a Loop......Page 578
12.12. for Loop Header Details......Page 579
12.13. Enumerated Types......Page 581
12.14. Hexadecimal, Octal, and Binary Numbers......Page 588
12.15. GUI Track: Unicode (Optional)......Page 589
12.16. Introduction to GridWorld Case Study (Optional)......Page 593
CHAPTER 13 Aggregation, Composition, and Inheritance......Page 604
13.2. Composition and Aggregation......Page 605
13.3. Inheritance Overview......Page 612
13.4. Implementation of a Person/Employee/FullTime Hierarchy......Page 616
13.5. Constructors in a Subclass......Page 618
13.6. Method Overriding......Page 619
13.7. Using the Person/Employee/FullTime Hierarchy......Page 622
13.9. Using Inheritance with Aggregation and Composition......Page 623
13.10. Design Practice with Card Game Example......Page 627
13.11. GridWorld Case Study Extensions (Optional)......Page 632
13.12. Problem Solving with Association Classes (Optional)......Page 639
CHAPTER 14 Inheritance and Polymorphism......Page 651
14.2. The Object Class and Automatic Type Promotion......Page 652
14.3. The equals Method......Page 653
14.4. The toString Method......Page 657
14.5. Polymorphism and Dynamic Binding......Page 662
14.6. Assignments Between Classes in a Class Hierarchy......Page 667
14.7. Polymorphism with Arrays......Page 668
14.8. abstract Methods and Classes......Page 674
14.9. Interfaces......Page 677
14.10. The protected Access Modifier......Page 683
14.11. GUI Track: Three-Dimensional Graphics (Optional)......Page 688
CHAPTER 15 Exception Handling......Page 700
15.2. Overview of Exceptions and Exception Messages......Page 701
15.3. Using try and catch Blocks to Handle "Dangerous" Method Calls......Page 702
15.4. Line Plot Example......Page 704
15.5. try Block Details......Page 708
15.6. Two Categories of Exceptions—Checked and Unchecked......Page 709
15.7. Unchecked Exceptions......Page 711
15.8. Checked Exceptions......Page 714
15.9. Generic catch Block with Exception Class......Page 718
15.10. Multiple catch Blocks and Multiple Exceptions Per Block......Page 721
15.11. Understanding Exception Messages......Page 723
15.12. Using throws to Postpone the catch......Page 727
15.13. Automatic Cleanup Using Try-With-Resources......Page 729
15.14. GUI Track and Problem Solving: Line Plot Example Revisited (Optional)......Page 731
CHAPTER 16 Files, Buffers, Channels, and Paths......Page 748
16.1. Introduction......Page 749
16.2. Simple Text-File Example: HTML File Generator......Page 750
16.3. A Website Reader......Page 754
16.4. Object File I/O......Page 756
16.5. Character Sets and File-Access Options......Page 760
16.6. Buffered Text File I/O......Page 762
16.7. Primitive Buffers with Random Access......Page 766
16.8. Channel I/O and Memory-Mapped Files......Page 773
16.9. Path, Whole-File, and Directory Operations......Page 779
16.10. Walking a Directory Tree......Page 782
16.11. GUI Track: The JFileChooser Class (Optional)......Page 787
CHAPTER 17 GUI Programming Basics......Page 800
17.1. Introduction......Page 801
17.2. Event-Driven Programming Basics......Page 802
17.3. A Simple Window Program......Page 803
17.4. JFrame Class......Page 805
17.5. Java Components......Page 807
17.6. JLabel Component......Page 808
17.7. JTextField Component......Page 809
17.8. Greeting Program......Page 810
17.9. Component Listeners......Page 813
17.10. Inner Classes......Page 814
17.11. Anonymous Inner Classes......Page 815
17.12. JButton Component......Page 818
17.13. Dialog Boxes and the JOptionPane Class......Page 823
17.14. Distinguishing Between Multiple Events......Page 827
17.15. Using getActionCommand to Distinguish Between Multiple Events......Page 829
17.16. Color......Page 830
17.17. How GUI Classes Are Grouped Together......Page 835
17.18. Mouse Listeners and Images (Optional)......Page 836
CHAPTER 18 GUI Programming—Component Layout, Additional GUI Components......Page 849
18.2. GUI Design and Layout Managers......Page 850
18.3. FlowLayout Manager......Page 852
18.4. BoxLayout Manager......Page 854
18.5. BorderLayout Manager......Page 860
18.6. GridLayout Manager......Page 865
18.7. Tic-Tac-Toe Example......Page 869
18.8. Problem Solving: Winning at Tic-Tac-Toe (Optional)......Page 871
18.9. Embedded Layout Managers......Page 874
18.10. JPanel class......Page 875
18.11. MathCalculator Program......Page 876
18.12. JTextArea Component......Page 880
18.13. JCheckBox Component......Page 883
18.14. JRadioButton Component......Page 886
18.15. JComboBox Component......Page 887
18.16. Job Application Example......Page 890
18.17. More Swing Components......Page 896
Appendix 1 ASCII Character Set......Page 908
Appendix 2 Operator Precedence......Page 910
Appendix 3 Java Reserved Words......Page 912
Appendix 4 Packages......Page 916
Appendix 5 Java Coding-Style Conventions......Page 920
Appendix 6 Javadoc with Tags......Page 932
Appendix 7 UML Diagrams......Page 937
Appendix 8 Number Systems and Conversions Between Them......Page 943
A......Page 947
B......Page 948
C......Page 949
D......Page 950
E......Page 951
G......Page 952
I......Page 953
J......Page 954
M......Page 955
O......Page 956
P......Page 957
R......Page 958
S......Page 959
T......Page 960
Z......Page 961