jhtp printonly.book(jhtp printonlyTOC.fm) Class AutoPolicy Case Study: Strings in switch Statements...

16
Chapters 26–34 and Appendices F–N are PDF documents posted online at the book’s Companion Website (located at www.pearsonhighered.com/deitel/). See the inside front cover for information on accessing the Companion Website. Foreword xxiii Preface xxv Before You Begin xxxix 1 Introduction to Computers, the Internet and Java 1 1.1 Introduction 2 1.2 Hardware and Software 4 1.2.1 Moore’s Law 4 1.2.2 Computer Organization 5 1.3 Data Hierarchy 6 1.4 Machine Languages, Assembly Languages and High-Level Languages 9 1.5 Introduction to Object Technology 10 1.5.1 The Automobile as an Object 10 1.5.2 Methods and Classes 11 1.5.3 Instantiation 11 1.5.4 Reuse 11 1.5.5 Messages and Method Calls 11 1.5.6 Attributes and Instance Variables 11 1.5.7 Encapsulation and Information Hiding 12 1.5.8 Inheritance 12 1.5.9 Interfaces 12 1.5.10 Object-Oriented Analysis and Design (OOAD) 12 1.5.11 The UML (Unified Modeling Language) 13 1.6 Operating Systems 13 1.6.1 Windows—A Proprietary Operating System 13 1.6.2 Linux—An Open-Source Operating System 14 1.6.3 Android 14 1.7 Programming Languages 15 1.8 Java 17 1.9 A Typical Java Development Environment 17 1.10 Test-Driving a Java Application 21 Contents © Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

Transcript of jhtp printonly.book(jhtp printonlyTOC.fm) Class AutoPolicy Case Study: Strings in switch Statements...

Chapters 26–34 and Appendices F–N are PDF documents posted online at the book’sCompanion Website (located at www.pearsonhighered.com/deitel/). See the insidefront cover for information on accessing the Companion Website.

Foreword xxiii

Preface xxv

Before You Begin xxxix

1 Introduction to Computers, the Internet and Java 11.1 Introduction 21.2 Hardware and Software 4

1.2.1 Moore’s Law 41.2.2 Computer Organization 5

1.3 Data Hierarchy 61.4 Machine Languages, Assembly Languages and High-Level Languages 91.5 Introduction to Object Technology 10

1.5.1 The Automobile as an Object 101.5.2 Methods and Classes 111.5.3 Instantiation 111.5.4 Reuse 111.5.5 Messages and Method Calls 111.5.6 Attributes and Instance Variables 111.5.7 Encapsulation and Information Hiding 121.5.8 Inheritance 121.5.9 Interfaces 121.5.10 Object-Oriented Analysis and Design (OOAD) 121.5.11 The UML (Unified Modeling Language) 13

1.6 Operating Systems 131.6.1 Windows—A Proprietary Operating System 131.6.2 Linux—An Open-Source Operating System 141.6.3 Android 14

1.7 Programming Languages 151.8 Java 171.9 A Typical Java Development Environment 171.10 Test-Driving a Java Application 21

Contents

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

viii Contents

1.11 Internet and World Wide Web 251.11.1 The Internet: A Network of Networks 261.11.2 The World Wide Web: Making the Internet User-Friendly 261.11.3 Web Services and Mashups 261.11.4 Ajax 271.11.5 The Internet of Things 27

1.12 Software Technologies 281.13 Keeping Up-to-Date with Information Technologies 30

2 Introduction to Java Applications; Input/Output and Operators 34

2.1 Introduction 352.2 Your First Program in Java: Printing a Line of Text 352.3 Modifying Your First Java Program 412.4 Displaying Text with printf 432.5 Another Application: Adding Integers 45

2.5.1 import Declarations 452.5.2 Declaring Class Addition 462.5.3 Declaring and Creating a Scanner to Obtain User Input from

the Keyboard 462.5.4 Declaring Variables to Store Integers 472.5.5 Prompting the User for Input 482.5.6 Obtaining an int as Input from the User 482.5.7 Prompting for and Inputting a Second int 492.5.8 Using Variables in a Calculation 492.5.9 Displaying the Result of the Calculation 492.5.10 Java API Documentation 49

2.6 Memory Concepts 502.7 Arithmetic 512.8 Decision Making: Equality and Relational Operators 542.9 Wrap-Up 58

3 Introduction to Classes, Objects, Methods and Strings 69

3.1 Introduction 703.2 Instance Variables, set Methods and get Methods 71

3.2.1 Account Class with an Instance Variable, a set Method and a get Method 71

3.2.2 AccountTest Class That Creates and Uses an Object of Class Account 74

3.2.3 Compiling and Executing an App with Multiple Classes 773.2.4 Account UML Class Diagram with an Instance Variable and

set and get Methods 773.2.5 Additional Notes on Class AccountTest 78

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

Contents ix

3.2.6 Software Engineering with private Instance Variables and public set and get Methods 79

3.3 Primitive Types vs. Reference Types 803.4 Account Class: Initializing Objects with Constructors 81

3.4.1 Declaring an Account Constructor for Custom Object Initialization 813.4.2 Class AccountTest: Initializing Account Objects When

They’re Created 823.5 Account Class with a Balance; Floating-Point Numbers 84

3.5.1 Account Class with a balance Instance Variable of Type double 853.5.2 AccountTest Class to Use Class Account 86

3.6 (Optional) GUI and Graphics Case Study: Using Dialog Boxes 903.7 Wrap-Up 93

4 Control Statements: Part 1; Assignment, ++ and -- Operators 101

4.1 Introduction 1024.2 Algorithms 1024.3 Pseudocode 1034.4 Control Structures 1034.5 if Single-Selection Statement 1054.6 if…else Double-Selection Statement 1064.7 Student Class: Nested if…else Statements 1114.8 while Repetition Statement 1134.9 Formulating Algorithms: Counter-Controlled Repetition 1154.10 Formulating Algorithms: Sentinel-Controlled Repetition 1194.11 Formulating Algorithms: Nested Control Statements 1264.12 Compound Assignment Operators 1314.13 Increment and Decrement Operators 1314.14 Primitive Types 1344.15 (Optional) GUI and Graphics Case Study: Creating Simple Drawings 1354.16 Wrap-Up 139

5 Control Statements: Part 2; Logical Operators 1525.1 Introduction 1535.2 Essentials of Counter-Controlled Repetition 1535.3 for Repetition Statement 1555.4 Examples Using the for Statement 1595.5 do…while Repetition Statement 1635.6 switch Multiple-Selection Statement 1655.7 Class AutoPolicy Case Study: Strings in switch Statements 1715.8 break and continue Statements 1745.9 Logical Operators 1765.10 Structured Programming Summary 1825.11 (Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals 1875.12 Wrap-Up 190

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

x Contents

6 Methods: A Deeper Look 2006.1 Introduction 2016.2 Program Modules in Java 2016.3 static Methods, static Fields and Class Math 2036.4 Declaring Methods with Multiple Parameters 2056.5 Notes on Declaring and Using Methods 2086.6 Method-Call Stack and Stack Frames 2096.7 Argument Promotion and Casting 2106.8 Java API Packages 2116.9 Case Study: Secure Random-Number Generation 2136.10 Case Study: A Game of Chance; Introducing enum Types 2186.11 Scope of Declarations 2226.12 Method Overloading 2256.13 (Optional) GUI and Graphics Case Study: Colors and Filled Shapes 2276.14 Wrap-Up 230

7 Arrays and ArrayLists 2437.1 Introduction 2447.2 Arrays 2457.3 Declaring and Creating Arrays 2467.4 Examples Using Arrays 247

7.4.1 Creating and Initializing an Array 2477.4.2 Using an Array Initializer 2487.4.3 Calculating the Values to Store in an Array 2497.4.4 Summing the Elements of an Array 2517.4.5 Using Bar Charts to Display Array Data Graphically 2517.4.6 Using the Elements of an Array as Counters 2537.4.7 Using Arrays to Analyze Survey Results 254

7.5 Exception Handling: Processing the Incorrect Response 2567.5.1 The try Statement 2567.5.2 Executing the catch Block 2567.5.3 toString Method of the Exception Parameter 257

7.6 Case Study: Card Shuffling and Dealing Simulation 2577.7 Enhanced for Statement 2627.8 Passing Arrays to Methods 2637.9 Pass-By-Value vs. Pass-By-Reference 2657.10 Case Study: Class GradeBook Using an Array to Store Grades 2667.11 Multidimensional Arrays 2727.12 Case Study: Class GradeBook Using a Two-Dimensional Array 2757.13 Variable-Length Argument Lists 2817.14 Using Command-Line Arguments 2837.15 Class Arrays 2857.16 Introduction to Collections and Class ArrayList 2877.17 (Optional) GUI and Graphics Case Study: Drawing Arcs 2917.18 Wrap-Up 294

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

Contents xi

8 Classes and Objects: A Deeper Look 3158.1 Introduction 3168.2 Time Class Case Study 3168.3 Controlling Access to Members 3218.4 Referring to the Current Object’s Members with the this Reference 3228.5 Time Class Case Study: Overloaded Constructors 3248.6 Default and No-Argument Constructors 3308.7 Notes on Set and Get Methods 3308.8 Composition 3328.9 enum Types 3358.10 Garbage Collection 3378.11 static Class Members 3388.12 static Import 3428.13 final Instance Variables 3438.14 Package Access 3448.15 Using BigDecimal for Precise Monetary Calculations 3458.16 (Optional) GUI and Graphics Case Study: Using Objects with Graphics 3488.17 Wrap-Up 352

9 Object-Oriented Programming: Inheritance 3609.1 Introduction 3619.2 Superclasses and Subclasses 3629.3 protected Members 3649.4 Relationship Between Superclasses and Subclasses 365

9.4.1 Creating and Using a CommissionEmployee Class 3659.4.2 Creating and Using a BasePlusCommissionEmployee Class 3719.4.3 Creating a CommissionEmployee–BasePlusCommissionEmployee

Inheritance Hierarchy 3769.4.4 CommissionEmployee–BasePlusCommissionEmployee

Inheritance Hierarchy Using protected Instance Variables 3799.4.5 CommissionEmployee–BasePlusCommissionEmployee

Inheritance Hierarchy Using private Instance Variables 3829.5 Constructors in Subclasses 3879.6 Class Object 3879.7 (Optional) GUI and Graphics Case Study: Displaying Text and

Images Using Labels 3889.8 Wrap-Up 391

10 Object-Oriented Programming: Polymorphism and Interfaces 395

10.1 Introduction 39610.2 Polymorphism Examples 39810.3 Demonstrating Polymorphic Behavior 39910.4 Abstract Classes and Methods 401

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

xii Contents

10.5 Case Study: Payroll System Using Polymorphism 40410.5.1 Abstract Superclass Employee 40510.5.2 Concrete Subclass SalariedEmployee 40710.5.3 Concrete Subclass HourlyEmployee 40910.5.4 Concrete Subclass CommissionEmployee 41110.5.5 Indirect Concrete Subclass BasePlusCommissionEmployee 41310.5.6 Polymorphic Processing, Operator instanceof and Downcasting 414

10.6 Allowed Assignments Between Superclass and Subclass Variables 41910.7 final Methods and Classes 41910.8 A Deeper Explanation of Issues with Calling Methods from Constructors 42010.9 Creating and Using Interfaces 421

10.9.1 Developing a Payable Hierarchy 42210.9.2 Interface Payable 42310.9.3 Class Invoice 42410.9.4 Modifying Class Employee to Implement Interface Payable 42610.9.5 Modifying Class SalariedEmployee for Use in the Payable

Hierarchy 42810.9.6 Using Interface Payable to Process Invoices and Employees

Polymorphically 43010.9.7 Some Common Interfaces of the Java API 431

10.10 Java SE 8 Interface Enhancements 43210.10.1 default Interface Methods 43210.10.2 static Interface Methods 43310.10.3 Functional Interfaces 433

10.11 (Optional) GUI and Graphics Case Study: Drawing with Polymorphism 43310.12 Wrap-Up 436

11 Exception Handling: A Deeper Look 44111.1 Introduction 44211.2 Example: Divide by Zero without Exception Handling 44311.3 Example: Handling ArithmeticExceptions and InputMismatchExceptions 44511.4 When to Use Exception Handling 45111.5 Java Exception Hierarchy 45111.6 finally Block 45411.7 Stack Unwinding and Obtaining Information from an Exception Object 45911.8 Chained Exceptions 46111.9 Declaring New Exception Types 46411.10 Preconditions and Postconditions 46511.11 Assertions 46511.12 try-with-Resources: Automatic Resource Deallocation 46711.13 Wrap-Up 467

12 GUI Components: Part 1 47312.1 Introduction 474

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

Contents xiii

12.2 Java’s Nimbus Look-and-Feel 47512.3 Simple GUI-Based Input/Output with JOptionPane 47612.4 Overview of Swing Components 47912.5 Displaying Text and Images in a Window 48112.6 Text Fields and an Introduction to Event Handling with Nested Classes 48512.7 Common GUI Event Types and Listener Interfaces 49112.8 How Event Handling Works 49312.9 JButton 49512.10 Buttons That Maintain State 498

12.10.1 JCheckBox 49912.10.2 JRadioButton 501

12.11 JComboBox; Using an Anonymous Inner Class for Event Handling 50412.12 JList 50812.13 Multiple-Selection Lists 51112.14 Mouse Event Handling 51312.15 Adapter Classes 51812.16 JPanel Subclass for Drawing with the Mouse 52212.17 Key Event Handling 52512.18 Introduction to Layout Managers 528

12.18.1 FlowLayout 53012.18.2 BorderLayout 53212.18.3 GridLayout 536

12.19 Using Panels to Manage More Complex Layouts 53812.20 JTextArea 53912.21 Wrap-Up 542

13 Graphics and Java 2D 55513.1 Introduction 55613.2 Graphics Contexts and Graphics Objects 55813.3 Color Control 55913.4 Manipulating Fonts 56613.5 Drawing Lines, Rectangles and Ovals 57113.6 Drawing Arcs 57513.7 Drawing Polygons and Polylines 57813.8 Java 2D API 58113.9 Wrap-Up 588

14 Strings, Characters and Regular Expressions 59614.1 Introduction 59714.2 Fundamentals of Characters and Strings 59714.3 Class String 598

14.3.1 String Constructors 59814.3.2 String Methods length, charAt and getChars 59914.3.3 Comparing Strings 600

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

xiv Contents

14.3.4 Locating Characters and Substrings in Strings 60514.3.5 Extracting Substrings from Strings 60714.3.6 Concatenating Strings 60814.3.7 Miscellaneous String Methods 60814.3.8 String Method valueOf 610

14.4 Class StringBuilder 61114.4.1 StringBuilder Constructors 61214.4.2 StringBuilder Methods length, capacity, setLength

and ensureCapacity 61214.4.3 StringBuilder Methods charAt, setCharAt, getChars

and reverse 61414.4.4 StringBuilder append Methods 61514.4.5 StringBuilder Insertion and Deletion Methods 617

14.5 Class Character 61814.6 Tokenizing Strings 62314.7 Regular Expressions, Class Pattern and Class Matcher 62414.8 Wrap-Up 633

15 Files, Streams and Object Serialization 64415.1 Introduction 64515.2 Files and Streams 64515.3 Using NIO Classes and Interfaces to Get File and Directory Information 64715.4 Sequential-Access Text Files 651

15.4.1 Creating a Sequential-Access Text File 65115.4.2 Reading Data from a Sequential-Access Text File 65515.4.3 Case Study: A Credit-Inquiry Program 65715.4.4 Updating Sequential-Access Files 661

15.5 Object Serialization 66215.5.1 Creating a Sequential-Access File Using Object Serialization 66315.5.2 Reading and Deserializing Data from a Sequential-Access File 668

15.6 Opening Files with JFileChooser 67015.7 (Optional) Additional java.io Classes 673

15.7.1 Interfaces and Classes for Byte-Based Input and Output 67315.7.2 Interfaces and Classes for Character-Based Input and Output 675

15.8 Wrap-Up 676

16 Generic Collections 68416.1 Introduction 68516.2 Collections Overview 68516.3 Type-Wrapper Classes 68716.4 Autoboxing and Auto-Unboxing 68716.5 Interface Collection and Class Collections 68716.6 Lists 688

16.6.1 ArrayList and Iterator 68916.6.2 LinkedList 691

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

Contents xv

16.7 Collections Methods 69616.7.1 Method sort 69716.7.2 Method shuffle 70016.7.3 Methods reverse, fill, copy, max and min 70216.7.4 Method binarySearch 70416.7.5 Methods addAll, frequency and disjoint 706

16.8 Stack Class of Package java.util 70816.9 Class PriorityQueue and Interface Queue 71016.10 Sets 71116.11 Maps 71416.12 Properties Class 71816.13 Synchronized Collections 72116.14 Unmodifiable Collections 72116.15 Abstract Implementations 72216.16 Wrap-Up 722

17 Java SE 8 Lambdas and Streams 72917.1 Introduction 73017.2 Functional Programming Technologies Overview 731

17.2.1 Functional Interfaces 73217.2.2 Lambda Expressions 73317.2.3 Streams 734

17.3 IntStream Operations 73617.3.1 Creating an IntStream and Displaying Its Values with the

forEach Terminal Operation 73817.3.2 Terminal Operations count, min, max, sum and average 73917.3.3 Terminal Operation reduce 73917.3.4 Intermediate Operations: Filtering and Sorting IntStream Values 74117.3.5 Intermediate Operation: Mapping 74217.3.6 Creating Streams of ints with IntStream Methods range and

rangeClosed 74317.4 Stream<Integer> Manipulations 743

17.4.1 Creating a Stream<Integer> 74417.4.2 Sorting a Stream and Collecting the Results 74517.4.3 Filtering a Stream and Storing the Results for Later Use 74517.4.4 Filtering and Sorting a Stream and Collecting the Results 74517.4.5 Sorting Previously Collected Results 745

17.5 Stream<String> Manipulations 74617.5.1 Mapping Strings to Uppercase Using a Method Reference 74717.5.2 Filtering Strings Then Sorting Them in Case-Insensitive

Ascending Order 74817.5.3 Filtering Strings Then Sorting Them in Case-Insensitive

Descending Order 74817.6 Stream<Employee> Manipulations 748

17.6.1 Creating and Displaying a List<Employee> 750

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

xvi Contents

17.6.2 Filtering Employees with Salaries in a Specified Range 75117.6.3 Sorting Employees By Multiple Fields 75217.6.4 Mapping Employees to Unique Last Name Strings 75417.6.5 Grouping Employees By Department 75517.6.6 Counting the Number of Employees in Each Department 75617.6.7 Summing and Averaging Employee Salaries 756

17.7 Creating a Stream<String> from a File 75817.8 Generating Streams of Random Values 76117.9 Lambda Event Handlers 76317.10 Additional Notes on Java SE 8 Interfaces 76317.11 Java SE 8 and Functional Programming Resources 76417.12 Wrap-Up 764

18 Recursion 77618.1 Introduction 77718.2 Recursion Concepts 77818.3 Example Using Recursion: Factorials 77918.4 Reimplementing Class FactorialCalculator Using Class BigInteger 78118.5 Example Using Recursion: Fibonacci Series 78318.6 Recursion and the Method-Call Stack 78618.7 Recursion vs. Iteration 78718.8 Towers of Hanoi 78918.9 Fractals 791

18.9.1 Koch Curve Fractal 79118.9.2 (Optional) Case Study: Lo Feather Fractal 792

18.10 Recursive Backtracking 80118.11 Wrap-Up 802

19 Searching, Sorting and Big O 81019.1 Introduction 81119.2 Linear Search 81219.3 Big O Notation 814

19.3.1 O(1) Algorithms 81419.3.2 O(n) Algorithms 81519.3.3 O(n2) Algorithms 81519.3.4 Big O of the Linear Search 816

19.4 Binary Search 81619.4.1 Binary Search Implementation 81719.4.2 Efficiency of the Binary Search 820

19.5 Sorting Algorithms 82019.6 Selection Sort 821

19.6.1 Selection Sort Implementation 82119.6.2 Efficiency of the Selection Sort 824

19.7 Insertion Sort 824

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

Contents xvii

19.7.1 Insertion Sort Implementation 82519.7.2 Efficiency of the Insertion Sort 827

19.8 Merge Sort 82719.8.1 Merge Sort Implementation 82819.8.2 Efficiency of the Merge Sort 832

19.9 Big O Summary for This Chapter’s Searching and Sorting Algorithms 83319.10 Wrap-Up 834

20 Generic Classes and Methods 83920.1 Introduction 84020.2 Motivation for Generic Methods 84020.3 Generic Methods: Implementation and Compile-Time Translation 84220.4 Additional Compile-Time Translation Issues: Methods That Use a

Type Parameter as the Return Type 84520.5 Overloading Generic Methods 84820.6 Generic Classes 84920.7 Raw Types 85620.8 Wildcards in Methods That Accept Type Parameters 86020.9 Wrap-Up 864

21 Custom Generic Data Structures 86921.1 Introduction 87021.2 Self-Referential Classes 87121.3 Dynamic Memory Allocation 87121.4 Linked Lists 872

21.4.1 Singly Linked Lists 87221.4.2 Implementing a Generic List Class 87321.4.3 Generic Classes ListNode and List 87821.4.4 Class ListTest 87821.4.5 List Method insertAtFront 87821.4.6 List Method insertAtBack 87921.4.7 List Method removeFromFront 88021.4.8 List Method removeFromBack 88121.4.9 List Method print 88221.4.10 Creating Your Own Packages 882

21.5 Stacks 88621.6 Queues 89021.7 Trees 89321.8 Wrap-Up 900

22 GUI Components: Part 2 91122.1 Introduction 91222.2 JSlider 912

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

xviii Contents

22.3 Understanding Windows in Java 91622.4 Using Menus with Frames 91722.5 JPopupMenu 92522.6 Pluggable Look-and-Feel 92822.7 JDesktopPane and JInternalFrame 93322.8 JTabbedPane 93622.9 BoxLayout Layout Manager 93822.10 GridBagLayout Layout Manager 94222.11 Wrap-Up 952

23 Concurrency 95723.1 Introduction 95823.2 Thread States and Life Cycle 960

23.2.1 New and Runnable States 96123.2.2 Waiting State 96123.2.3 Timed Waiting State 96123.2.4 Blocked State 96123.2.5 Terminated State 96123.2.6 Operating-System View of the Runnable State 96223.2.7 Thread Priorities and Thread Scheduling 96223.2.8 Indefinite Postponement and Deadlock 963

23.3 Creating and Executing Threads with the Executor Framework 96323.4 Thread Synchronization 967

23.4.1 Immutable Data 96823.4.2 Monitors 96823.4.3 Unsynchronized Mutable Data Sharing 96923.4.4 Synchronized Mutable Data Sharing—Making Operations Atomic 974

23.5 Producer/Consumer Relationship without Synchronization 97623.6 Producer/Consumer Relationship: ArrayBlockingQueue 98423.7 (Advanced) Producer/Consumer Relationship with synchronized,

wait, notify and notifyAll 98723.8 (Advanced) Producer/Consumer Relationship: Bounded Buffers 99423.9 (Advanced) Producer/Consumer Relationship: The Lock and

Condition Interfaces 100223.10 Concurrent Collections 100923.11 Multithreading with GUI: SwingWorker 1011

23.11.1 Performing Computations in a Worker Thread: Fibonacci Numbers 1012

23.11.2 Processing Intermediate Results: Sieve of Eratosthenes 101823.12 sort and parallelSort Timings with the Java SE 8 Date/Time API 102523.13 Java SE 8: Sequential vs. Parallel Streams 102723.14 (Advanced) Interfaces Callable and Future 103023.15 (Advanced) Fork/Join Framework 103423.16 Wrap-Up 1034

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

Contents xix

24 Accessing Databases with JDBC 104524.1 Introduction 104624.2 Relational Databases 104724.3 A books Database 104824.4 SQL 1052

24.4.1 Basic SELECT Query 105224.4.2 WHERE Clause 105324.4.3 ORDER BY Clause 105524.4.4 Merging Data from Multiple Tables: INNER JOIN 105624.4.5 INSERT Statement 105824.4.6 UPDATE Statement 105924.4.7 DELETE Statement 1060

24.5 Setting up a Java DB Database 106024.5.1 Creating the Chapter’s Databases on Windows 106124.5.2 Creating the Chapter’s Databases on Mac OS X 106224.5.3 Creating the Chapter’s Databases on Linux 1063

24.6 Manipulating Databases with JDBC 106324.6.1 Connecting to and Querying a Database 106324.6.2 Querying the books Database 1067

24.7 RowSet Interface 108024.8 PreparedStatements 108224.9 Stored Procedures 109824.10 Transaction Processing 109824.11 Wrap-Up 1099

25 JavaFX GUI: Part 1 110725.1 Introduction 110825.2 JavaFX Scene Builder and the NetBeans IDE 110925.3 JavaFX App Window Structure 111025.4 Welcome App—Displaying Text and an Image 1111

25.4.1 Creating the App’s Project 111125.4.2 NetBeans Projects Window—Viewing the Project Contents 111325.4.3 Adding an Image to the Project 111425.4.4 Opening JavaFX Scene Builder from NetBeans 111425.4.5 Changing to a VBox Layout Container 111525.4.6 Configuring the VBox Layout Container 111625.4.7 Adding and Configuring a Label 111625.4.8 Adding and Configuring an ImageView 111625.4.9 Running the Welcome App 1117

25.5 Tip Calculator App—Introduction to Event Handling 111825.5.1 Test-Driving the Tip Calculator App 111925.5.2 Technologies Overview 111925.5.3 Building the App’s GUI 112225.5.4 TipCalculator Class 112625.5.5 TipCalculatorController Class 1128

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

xx Contents

25.6 Features Covered in the Online JavaFX Chapters 113325.7 Wrap-Up 1134

Chapters on the Web 1141

A Operator Precedence Chart 1143

B ASCII Character Set 1145

C Keywords and Reserved Words 1146

D Primitive Types 1147

E Using the Debugger 1148E.1 Introduction 1149E.2 Breakpoints and the run, stop, cont and print Commands 1149E.3 The print and set Commands 1153E.4 Controlling Execution Using the step, step up and next Commands 1155E.5 The watch Command 1158E.6 The clear Command 1160E.7 Wrap-Up 1162

Appendices on the Web 1165

Index 1167

Online Chapters and AppendicesChapters 26–34 and Appendices F–N are PDF documents posted online at the book’sCompanion Website (located at www.pearsonhighered.com/deitel/). See the insidefront cover for information on accessing the Companion Website.

26 JavaFX GUI: Part 2

27 JavaFX Graphics and Multimedia

28 Networking

29 Java Persistence API (JPA)

30 JavaServer™ Faces Web Apps: Part 1

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

Contents xxi

31 JavaServer™ Faces Web Apps: Part 2

32 REST-Based Web Services

33 (Optional) ATM Case Study, Part 1: Object-Oriented Design with the UML

34 (Optional) ATM Case Study, Part 2: Implementing an Object-Oriented Design

F Using the Java API Documentation

G Creating Documentation with javadoc

H Unicode®

I Formatted Output

J Number Systems

K Bit Manipulation

L Labeled break and continue Statements

M UML 2: Additional Diagram Types

N Design Patterns

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved.