Introduction to Programming with Java: A Problem Solving Approach, 1st 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"

This book teaches the reader how to write programs using Java. It does so with a unique approach that combines fundamentals first with objects early. The book transitions smoothly through a carefully selected set of procedural programming fundamentals to object-oriented fundamentals. During this early transition and beyond, the book emphasizes problem solving. For example, Chapter 2 is devoted to algorithm development, Chapter 8 is devoted to program design, and problem-solving sections appear throughout the book. Problem-solving skills are fostered with the help of an interactive, iterative presentation style: Here's the problem. How can we solve it? How can we improve the solution?. Some key features include: A conversational, easy-to-follow writing style. Many executable code examples that clearly and efficiently illustrate key concepts. Extensive use of UML class diagrams to specify problem organization. Simple GUI programming early, in an optional standalone graphics track. Well-identified alternatives for altering the book's sequence to fit individual needs. Well-developed projects in six different academic disciplines, with a handy summary. Detailed customizable PowerPointTM lecture slides, with icon-keyed hidden notes. Student Resources: Links to compiler software - for Sun's Java2 SDK toolkit, Helios's TextPad, Eclipse, NetBeans, and BlueJ. TextPad tutorial. Eclipse tutorials. Textbook errata. All textbook example programs and associated resource files. Instructor Resources: Customizable PowerPoint lecture slides with hidden notes. Hidden notes provide comments that supplement the displayed text in the lecture slides. For example, if the displayed text asks a question the hidden notes provide the answer. Exercise solutions. Project solutions. "The authors have done a superb job of organizing the various chapters to allow the students to enjoy programming in Java from day one. I am deeply impressed with the entire textbook. I would have my students keep this text and use it throughout their academic career as an excellent Java programming source book". Benjamin B. Nystuen, University of Colorado at Colorado Springs. "The authors have done a great job in describing the technical aspects of programming. The authors have an immensely readable writing style. I have an extremely favorable impression of Dean and Dean's proposed text". Shyamal Mitra, University of Texas at Austin. "The overall impression of the book was that it was friendly to read. I think this is a great strength, simply because students reading it, and especially students who are prone to reading to understand, will appreciate this approach rather than the regular hardcore programming mentality". Andree Jacobson, University of New Mexico.

Author(s): John Dean, Ray Dean
Edition: 1st
Publisher: McGraw-Hill
Year: 2007

Language: English
Pages: 851
Tags: Библиотека;Компьютерная литература;Java;

Cover Page
......Page 1
Title Page......Page 2
Copyright Page
......Page 3
Dedication
......Page 4
About the Authors
......Page 5
Preface......Page 10
Project Summary......Page 22
Contents......Page 6
1.1. Introduction......Page 35
1.2. Hardware Terminology......Page 36
1.3. Program Development......Page 43
1.4. Source Code......Page 44
1.6. Portability......Page 46
1.7. Emergence of Java......Page 48
1.8. First Program—Hello World......Page 49
1.9. GUI Track: Hello World (Optional)......Page 54
2.1. Introduction......Page 59
2.2. Output......Page 60
2.3. Variables......Page 61
2.4. Operators and Assignment Statements......Page 62
2.5. Input......Page 63
2.6. Flow of Control and Flowcharts......Page 64
2.7. if Statements......Page 65
2.8. Loops......Page 70
2.9. Loop Termination Techniques......Page 72
2.10. Nested Looping......Page 75
2.11. Tracing......Page 76
2.12. Other Pseudocode Formats and Applications......Page 80
2.13. Problem Solving: Asset Management (Optional)......Page 82
CHAPTER 3: Java Basics......Page 90
3.2. “I Have a Dream” Program......Page 91
3.3. Comments and Readability......Page 92
3.5. The main Method’s Heading......Page 94
3.6. Braces......Page 95
3.7. System.out.println......Page 96
3.8. Compilation and Execution......Page 97
3.9. Identifiers......Page 98
3.10. Variables......Page 99
3.11. Assignment Statements......Page 100
3.12. Initialization Statements......Page 102
3.13. Numeric Data Types—int, long, float, double......Page 103
3.14. Constants......Page 105
3.15. Arithmetic Operators......Page 108
3.16. Expression Evaluation and Operator Precedence......Page 110
3.17. More Operators: Increment, Decrement, and Compound Assignment......Page 112
3.19. Type Casting......Page 114
3.20. char Type and Escape Sequences......Page 117
3.21. Primitive Variables Versus Reference Variables......Page 119
3.22. Strings......Page 120
3.23. Input—the Scanner Class......Page 124
3.24. GUI Track: Input and Output with JOptionPane (Optional)......Page 129
CHAPTER 4: Control Statements......Page 140
4.2. Conditions and Boolean Values......Page 141
4.3. if Statements......Page 142
4.4. && Logical Operator......Page 145
4.5. || Logical Operator......Page 150
4.6. ! Logical Operator......Page 152
4.7. switch Statement......Page 153
4.8. while Loop......Page 157
4.9. do Loop......Page 160
4.10. for Loop......Page 161
4.11. Solving the Problem of Which Loop to Use......Page 166
4.12. Nested Loops......Page 167
4.13. boolean Variables......Page 169
4.14. Input Validation......Page 172
4.15. Problem Solving with Boolean Logic (Optional)......Page 173
CHAPTER 5: Using Pre-Built Methods......Page 185
5.1. Introduction......Page 186
5.2. The API Library......Page 187
5.3. Math Class......Page 189
5.4. Wrapper Classes for Primitive Types......Page 195
5.5. Character Class......Page 199
5.6. String Methods......Page 201
5.7. Formatted Output with the printf Method......Page 206
5.8. Problem Solving with Random Numbers (Optional)......Page 211
5.9. GUI Track: Drawing Images, Lines, Rectangles, and Ovals in Java Applets (Optional)......Page 216
CHAPTER 6: Object-Oriented Programming......Page 229
6.2. Object-Oriented Programming Overview......Page 230
6.3. First OOP Class......Page 233
6.4. Driver Class......Page 237
6.5. Calling Object, this Reference......Page 240
6.6. Instance Variables......Page 243
6.7. Tracing an OOP Program......Page 244
6.8. UML Class Diagrams......Page 249
6.9. Local Variables......Page 250
6.10. The return Statement......Page 252
6.11. Argument Passing......Page 256
6.12. Specialized Methods—Accessors, Mutators, Boolean Methods......Page 258
6.13. Problem Solving with Simulation (Optional)......Page 261
CHAPTER 7: Object-Oriented Programming—Additional Details......Page 279
7.2. Object Creation—A Detailed Analysis......Page 280
7.3. Assigning a Reference......Page 282
7.4. Testing Objects for Equality......Page 286
7.5. Passing References as Arguments......Page 291
7.6. Method-Call Chaining......Page 294
7.7. Overloaded Methods......Page 296
7.8. Constructors......Page 299
7.9. Overloaded Constructors......Page 306
7.10. Problem Solving with Multiple Driven Classes......Page 309
CHAPTER 8: Software Engineering......Page 329
8.2. Coding-Style Conventions......Page 330
8.3. Helper Methods......Page 339
8.4. Encapsulation (With Instance Variables and Local Variables)......Page 342
8.5. Design Philosophy......Page 344
8.6. Top-Down Design......Page 346
8.7. Bottom-Up Design......Page 355
8.8. Case-Based Design......Page 357
8.9. Iterative Enhancement......Page 358
8.10. Merging Driver Method into Driven Class......Page 360
8.11. Accessing Instance Variables without Using this......Page 361
8.12. Problem Solving with the API Calendar Class (Optional)......Page 363
8.13. GUI Track: Problem Solving with CRC Cards (Optional)......Page 365
9.1. Introduction......Page 379
9.2. Class Variables......Page 380
9.3. Class Methods......Page 383
9.4. Named Constants......Page 386
9.6. Using Class Members in Conjunction with Instance Members......Page 388
9.7. Problem Solving with Class Members and Instance Members in a Linked List Class (Optional)......Page 392
CHAPTER 10: Arrays and ArrayLists......Page 404
10.2. Array Basics......Page 405
10.3. Array Declaration and Creation......Page 407
10.4. Array length Property and Partially Filled Arrays......Page 411
10.5. Copying an Array......Page 413
10.6. Problem Solving with Array Case Studies......Page 416
10.7. Searching an Array......Page 422
10.8. Sorting an Array......Page 427
10.9. Two-Dimensional Arrays......Page 430
10.10. Arrays of Objects......Page 436
10.11. The ArrayList Class......Page 443
10.12. Storing Primitives in an ArrayList......Page 448
10.13. ArrayList Example Using Anonymous Objects and the For-Each Loop......Page 451
10.14. ArrayLists Versus Standard Arrays......Page 456
CHAPTER 11: Type Details and Alternate Coding Mechanisms......Page 467
11.2. Integer Types and Floating-Point Types......Page 468
11.3. char Type and the ASCII Character Set......Page 472
11.4. Type Conversions......Page 475
11.5. Prefix/Postfix Modes for Increment/Decrement Operators......Page 477
11.6. Embedded Assignments......Page 480
11.7. Conditional Operator Expressions......Page 482
11.8. Expression Evaluation Review......Page 483
11.9. Short-Circuit Evaluation......Page 487
11.10. Empty Statement......Page 488
11.11. break Statement within a Loop......Page 490
11.12. for Loop Header Details......Page 491
11.13. GUI Track: Unicode (Optional)......Page 493
CHAPTER 12: Aggregation, Composition, and Inheritance......Page 505
12.2. Composition and Aggregation......Page 506
12.3. Inheritance Overview......Page 513
12.4. Implementation of Person/Employee/FullTime Hierarchy......Page 517
12.5. Constructors in a Subclass......Page 519
12.6. Method Overriding......Page 520
12.7. Using the Person/Employee/FullTime Hierarchy......Page 522
12.8. The final Access Modifier......Page 523
12.9. Using Inheritance with Aggregation and Composition......Page 524
12.10. Design Practice with Card Game Example......Page 527
12.11. Problem Solving with Association Classes (Optional)......Page 532
CHAPTER 13: Inheritance and Polymorphism......Page 542
13.2. The Object Class and Automatic Type Promotion......Page 543
13.3. The equals Method......Page 544
13.4. The toString Method......Page 548
13.5. Polymorphism and Dynamic Binding......Page 553
13.6. Assignments Between Classes in a Class Hierarchy......Page 556
13.7. Polymorphism with Arrays......Page 558
13.8. Abstract Methods and Classes......Page 564
13.9. Interfaces......Page 567
13.10. The protected Access Modifier......Page 573
13.11. GUI Track: Three-Dimensional Graphics (Optional)......Page 578
CHAPTER 14: Exception Handling......Page 589
14.2. Overview of Exceptions and Exception Messages......Page 590
14.3. Using try and catch Blocks to Handle “Dangerous” Method Calls......Page 591
14.4. Line Plot Example......Page 593
14.5. try Block Details......Page 597
14.6. Two Categories of Exceptions—Checked and Unchecked......Page 598
14.7. Unchecked Exceptions......Page 600
14.8. Checked Exceptions......Page 603
14.9. The Exception Class and Its getMessage Method......Page 606
14.10. Multiple catch Blocks......Page 607
14.11. Understanding Exception Messages......Page 610
14.12. Using throws to Postpone the catch......Page 614
14.13. GUI Track and Problem Solving: Line Plot Example Revisited (Optional)......Page 618
15.1. Introduction......Page 635
15.2. Java API Classes You Need to Import......Page 636
15.3. Text-File Output......Page 638
15.4. Text-File Input......Page 642
15.5. HTML File Generator......Page 646
15.6. Text File Data Format Versus Binary File Data Format......Page 649
15.7. Binary File I/O......Page 652
15.8. Object File I/O......Page 656
15.9. The File Class......Page 660
15.10. GUI Track: The JFileChooser Class (Optional)......Page 663
CHAPTER 16: GUI Programming Basics......Page 678
16.1. Introduction......Page 679
16.2. Event-Driven Programming Basics......Page 680
16.3. A Simple Window Program......Page 681
16.4. JFrame Class......Page 683
16.5. Java Components......Page 685
16.6. JLabel Component......Page 686
16.7. JTextField Component......Page 687
16.8. Greeting Program......Page 688
16.9. Component Listeners......Page 691
16.10. Inner Classes......Page 692
16.11. Anonymous Inner Classes......Page 693
16.12. JButton Component......Page 696
16.13. Dialog Boxes and the JOptionPane Class......Page 701
16.14. Distinguishing Between Multiple Events......Page 705
16.15. Using getActionCommand to Distinguish Between Multiple Events......Page 707
16.16. Color......Page 708
16.17. How GUI Classes Are Grouped Together......Page 713
16.18. Mouse Listeners and Images (Optional)......Page 714
CHAPTER 17: GUI Programming—Component Layout, Additional GUI Components......Page 727
17.2. GUI Design and Layout Managers......Page 728
17.3. FlowLayout Manager......Page 730
17.4. BorderLayout Manager......Page 732
17.5. GridLayout Manager......Page 738
17.6. Tic-Tac-Toe Example......Page 741
17.7. Problem Solving: Winning at Tic-Tac-Toe (Optional)......Page 744
17.8. Embedded Layout Managers......Page 746
17.9. JPanel class......Page 748
17.10. MathCalculator Program......Page 749
17.11. JtextArea Component......Page 753
17.12. JcheckBox Component......Page 755
17.13. JradioButton Component......Page 758
17.14. JcomboBox Component......Page 760
17.15. Job Application Example......Page 763
17.16. More Swing Components......Page 768
Appendix 1 Unicode/ASCII Character Set with Hexadecimal Codes......Page 779
Appendix 2 Operator Precedence......Page 783
Appendix 3 Java Reserved Words......Page 785
Appendix 4 Packages......Page 789
Appendix 5 Java Coding-Style Conventions......Page 793
Appendix 6 Javadoc......Page 805
Appendix 7 UML Diagrams......Page 812
Appendix 8 Recursion......Page 818
Appendix 9 Multithreading......Page 828