Book description
For courses in Java programming
Unparalleled breadth and depth of object-oriented programming concepts
The Deitels’ groundbreaking How to Program series offers unparalleled breadth and depth of programming fundamentals, object-oriented programming concepts and intermediate-level topics for further study. Java How to Program, Late Objects, 11th Edition, presents leading-edge computing technologies using the Deitel signature live-code approach, which demonstrates concepts in hundreds of complete working programs. The 11th Edition presents updated coverage of Java SE 8 and new Java SE 9 capabilities, including JShell, the Java Module System, and other key Java 9 topics. [Java How to Program, Early Objects, 11th Edition also is available.]
Table of contents
- How To Program Series
- Deitel® Developer Series
- Simply Series
- VitalSource Web Books
- LiveLessons Video Learning Products
- REVEL™ Interactive Multimedia
- Java™ How to Program Late Objects
- Trademarks
- Contents
- Foreword
-
Preface
- New and Updated Features
- Flexibility Using Java SE 8 or the New Java SE 9
- Java How to Program, Late Objects, 11/e’s Modular Organization1
- Introduction and Programming Fundamentals (Parts 1 and 2)
- Flexible Coverage of Java 9: JShell, the Module System and Other Java 9 Topics
- Object-Oriented Programming (Part 3)
- Flexible JavaFX GUI, Graphics, Animation and Video Coverage (Part 4) and Optional Swing Coverage (Part 11)
- Data Structures and Generic Collections (Part 5)
- Flexible Lambdas and Streams Coverage (Chapter 17)
- Concurrency and Multi-Core Performance (Part 6)
- Database: JDBC and JPA (Part 7)
- Web Application Development and Web Services (Part 8)
- Optional Online Object-Oriented Design Case Study (Part 10)
- Teaching Approach
- Programming Wisdom
- What are JEPs, JSRs and the JCP?
- Secure Java Programming
- Companion Website: Source Code, VideoNotes, Online Chapters and Online Appendices
- Software Used in Java How to Program, 11/e
- Java Documentation Links
- Java How to Program, Early Objects Version, 11/e
- Instructor Supplements
- Keeping in Touch with the Authors
- Reviewers
- A Special Thank You to Robert Field
- A Special Thank You to Brian Goetz
- About the Authors
- About Deitel® & Associates, Inc. & Associates, Inc.
- About the Cover Art
- Before You Begin
-
1 Introduction to Computers, the Internet and Java
- Objectives
- Outline
- 1.1 Introduction
- 1.2 Hardware and Software
- 1.3 Data Hierarchy
- 1.4 Machine Languages, Assembly Languages and High-Level Languages
-
1.5 Basic Introduction to Object Terminology
- 1.5.1 Automobile as an Object
- 1.5.2 Methods and Classes
- 1.5.3 Instantiation
- 1.5.4 Reuse
- 1.5.5 Messages and Method Calls
- 1.5.6 Attributes and Instance Variables
- 1.5.7 Encapsulation and Information Hiding
- 1.5.8 Inheritance
- 1.5.9 Interfaces
- 1.5.10 Object-Oriented Analysis and Design (OOAD)
- 1.5.11 The UML (Unified Modeling Language)
- 1.6 Operating Systems
- 1.7 Programming Languages
- 1.8 Java
- 1.9 A Typical Java Development Environment
- 1.10 Test-Driving a Java Application
- 1.11 Internet and World Wide Web
- 1.12 Software Technologies
- 1.13 Getting Your Questions Answered
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
2 Introduction to Java Applications; Input/Output and Operators
- Objectives
- Outline
- 2.1 Introduction
- 2.2 Your First Program in Java: Printing a Line of Text
- 2.3 Modifying Your First Java Program
- 2.4 Displaying Text with printf
-
2.5 Another Application: Adding Integers
- 2.5.1 import Declarations
- 2.5.2 Declaring and Creating a Scanner to Obtain User Input from the Keyboard
- 2.5.3 Prompting the User for Input
- 2.5.4 Declaring a Variable to Store an Integer and Obtaining an Integer from the Keyboard
- 2.5.5 Obtaining a Second Integer
- 2.5.6 Using Variables in a Calculation
- 2.5.7 Displaying the Calculation Result
- 2.5.8 Java API Documentation
- 2.5.9 Declaring and Initializing Variables in Separate Statements
- 2.6 Memory Concepts
- 2.7 Arithmetic
- 2.8 Decision Making: Equality and Relational Operators
- 2.9 Wrap-Up
-
Summary
- Section 2.2 Your First Program in Java: Printing a Line of Text
- Section 2.3 Modifying Your First Java Program
-
Section 2.4 Displaying Text with printf
- Section 2.5.1 import Declarations
- Section 2.5.2 Declaring and Creating a Scanner to Obtain User Input from the Keyboard
- Section 2.5.3 Prompting the User for Input
- Section 2.5.4 Declaring a Variable to Store an Integer and Obtaining an Integer from the Keyboard
- Section 2.5.6 Using Variables in a Calculation
- Section 2.5.7 Displaying the Calculation Result
- Section 2.5.9 Declaring and Initializing Variables in Separate Statements
- Section 2.6 Memory Concepts
- Section 2.7 Arithmetic
- Section 2.8 Decision Making: Equality and Relational Operators
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
3 Control Statements: Part 1; Assignment, ++ and -- Operators
- Objectives
- Outline
- 3.1 Introduction
- 3.2 Algorithms
- 3.3 Pseudocode
- 3.4 Control Structures
- 3.5 if Single-Selection Statement
- 3.6 if…else Double-Selection Statement
- 3.7 while Iteration Statement
- 3.8 Formulating Algorithms: Counter-Controlled Iteration
- 3.9 Formulating Algorithms: Sentinel-Controlled Iteration
- 3.10 Formulating Algorithms: Nested Control Statements
- 3.11 Compound Assignment Operators
- 3.12 Increment and Decrement Operators
- 3.13 Primitive Types
- 3.14 Wrap-Up
-
Summary
- Section 3.1 Introduction
- Section 3.2 Algorithms
- Section 3.3 Pseudocode
- Section 3.4 Control Structures
- Section 3.4.1 Sequence Structure in Java
- Section 3.4.2 Selection Statements in Java
- Section 3.4.3 Iteration Statements in Java
- Section 3.4.4 Summary of Control Statements in Java
- Section 3.5 if Single-Selection Statement
- Section 3.6 if…else Double-Selection Statement
- Section 3.6.1 Nested if…else Statements
- Section 3.6.2 Dangling-else Problem
- Section 3.6.3 Blocks
- Section 3.6.4 Conditional Operator (?:)
- Section 3.7 while Iteration Statement
- Section 3.8 Formulating Algorithms: Counter-Controlled Iteration
- Section 3.9 Formulating Algorithms: Sentinel-Controlled Iteration
- Section 3.11 Compound Assignment Operators
- Section 3.12 Increment and Decrement Operators
- Section 3.13 Primitive Types
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
4 Control Statements: Part 2; Logical Operators
- Objectives
- Outline
- 4.1 Introduction
- 4.2 Essentials of Counter-Controlled Iteration
- 4.3 for Iteration Statement
- 4.4 Examples Using the for Statement
- 4.5 do…while Iteration Statement
- 4.6 switch Multiple-Selection Statement
- 4.7 break and continue Statements
-
4.8 Logical Operators
- 4.8.1 Conditional AND (&&) Operator Conditional AND (&&) Operator
- 4.8.2 Conditional OR (||) Operator
- 4.8.3 Short-Circuit Evaluation of Complex Conditions
- 4.8.4 Boolean Logical AND (&) and Boolean Logical Inclusive OR (|) Operators Boolean Logical AND (&) and Boolean Logical Inclusive OR (|) Operators
- 4.8.5 Boolean Logical Exclusive OR (^)
- 4.8.6 Logical Negation (!) Operator
- 4.8.7 Logical Operators Example
- 4.9 Structured-Programming Summary
- 4.10 Wrap-Up
-
Summary
- Section 4.2 Essentials of Counter-Controlled Iteration
- Section 4.3 for Iteration Statement
- Section 4.4.2 Application: Compound-Interest Calculations
- Section 4.5 do…while Iteration Statement
- Section 4.6 switch Multiple-Selection Statement
- Section 4.7.1 break Statement
- Section 4.7.2 continue Statement
- Section 4.8 Logical Operators
- Section 4.8.1 Conditional AND (&&) Operator
- Section 4.8.2 Conditional OR (||) Operator
- Section 4.8.3 Short-Circuit Evaluation of Complex Conditions
- Section 4.8.4 Boolean Logical AND (&) and Boolean Logical Inclusive OR (|) Operators
- Section 4.8.5 Boolean Logical Exclusive OR (^)
- Section 4.8.6 Logical Negation (!) Operator
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
5 Methods
- Objectives
- Outline
- 5.1 Introduction
- 5.2 Program Units in Java
- 5.3 static Methods, static Variables and Class Math
- 5.4 Declaring Methods
- 5.5 Notes on Declaring and Using Methods
- 5.6 Method-Call Stack and Activation Records
- 5.7 Argument Promotion and Casting
- 5.8 Java API Packages
- 5.9 Case Study: Secure Random-Number Generation
- 5.10 Case Study: A Game of Chance; Introducing enums
- 5.11 Scope of Declarations
- 5.12 Method Overloading
- 5.13 Wrap-Up
-
Summary
- Section 5.1 Introduction
- Section 5.2 Program Units in Java
- Section 5.3 static Methods, static Fields and Class Math
- Section 5.4 Declaring Methods
- Section 5.5 Notes on Declaring and Using Methods
- Section 5.6 Method-Call Stack and Activation Records
- Section 5.7 Argument Promotion and Casting
- Section 5.9 Case Study: Secure Random-Number Generation
- Section 5.10 Case Study: A Game of Chance; Introducing enum Types
- Section 5.11 Scope of Declarations
- Section 5.12 Method Overloading
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
6 Arrays and ArrayLists
- Objectives
- Outline
- 6.1 Introduction
- 6.2 Primitive Types vs. Reference Types
- 6.3 Arrays
- 6.4 Declaring and Creating Arrays
-
6.5 Examples Using Arrays
- 6.5.1 Creating and Initializing an Array
- 6.5.2 Using an Array Initializer
- 6.5.3 Calculating the Values to Store in an Array
- 6.5.4 Summing the Elements of an Array
- 6.5.5 Using Bar Charts to Display Array Data Graphically
- 6.5.6 Using the Elements of an Array as Counters
- 6.5.7 Using Arrays to Analyze Survey Results
- 6.6 Exception Handling: Processing the Incorrect Response
- 6.7 Enhanced for Statement
- 6.8 Passing Arrays to Methods
- 6.9 Pass-By-Value vs. Pass-By-Reference
-
6.10 Multidimensional Arrays
- 6.10.1 Arrays of One-Dimensional Arrays
- 6.10.2 Two-Dimensional Arrays with Rows of Different Lengths
- 6.10.3 Creating Two-Dimensional Arrays with Array-Creation Expressions
- 6.10.4 Two-Dimensional Array Example: Displaying Element Values
- 6.10.5 Common Multidimensional-Array Manipulations Performed with for Statements
- 6.11 Variable-Length Argument Lists
- 6.12 Using Command-Line Arguments
- 6.13 Class Arrays
- 6.14 Introduction to Collections and Class ArrayList
- 6.15 Wrap-Up
-
Summary
- Section 6.1 Introduction
- Section 6.2 Primitive Types vs. Reference Types
- Section 6.3 Arrays
- Section 6.4 Declaring and Creating Arrays
- Section 6.5 Examples Using Arrays
- Section 6.6 Exception Handling: Processing the Incorrect Response
- Section 6.7 Enhanced for Statement
- Section 6.8 Passing Arrays to Methods
- Section 6.9 Pass-By-Value vs. Pass-By-Reference
- Section 6.10 Multidimensional Arrays
- Section 6.11 Variable-Length Argument Lists
- Section 6.12 Using Command-Line Arguments
- Section 6.13 Class Arrays
- Section 6.14 Introduction to Collections and Class ArrayList
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
7 Introduction to Classes and Objects
- Objectives
- Outline
- 7.1 Introduction1
-
7.2 Instance Variables, set Methods and get Methods
- 7.2.1 Account Class with an Instance Variable, and set and get Methods
-
7.2.2 AccountTest Class That Creates and Uses an Object of Class Account
- Driver Class AccountTest
- Scanner Object for Receiving Input from the User
- Instantiating an Object—Keyword new and Constructors
- Calling Class Account’s getName Method
- null—the Default Initial Value for String Variable
- Calling Class Account’s setName Method
- Displaying the Name That Was Entered by the User
- 7.2.3 Compiling and Executing an App with Multiple Classes
- 7.2.4 Account UML Class Diagram
- 7.2.5 Additional Notes on Class AccountTest
- 7.2.6 Software Engineering with private Instance Variables and public set and get Methods
- 7.3 Default and Explicit Initialization for Instance Variables
- 7.4 Account Class: Initializing Objects with Constructors
- 7.5 Account Class with a Balance
- 7.6 Case Study: Card Shuffling and Dealing Simulation
- 7.7 Case Study: Class GradeBook Using an Array to Store Grades
- 7.8 Case Study: Class GradeBook Using a Two-Dimensional Array
- 7.9 Wrap-Up
-
Summary
- Section 7.2 Instance Variables, set Methods and get Methods
- Section 7.2.1 Account Class with an Instance Variable, a set Method and a get Method
- Section 7.2.2 AccountTest Class That Creates and Uses an Object of Class Account
- Section 7.2.3 Compiling and Executing an App with Multiple Classes
- Section 7.2.4 Account UML Class Diagram
- Section 7.2.5 Additional Notes on Class AccountTest
- Section 7.2.6 Software Engineering with private Instance Variables and public set and get Methods
- Section 7.3 Default and Explicit Initialization for Instance Variables
- Section 7.4 Account Class: Initializing Objects with Constructors
- Section 7.5 Account Class with a Balance
- Section 7.6 Case Study: Card Shuffling and Dealing Simulation
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
8 Classes and Objects: A Deeper Look
- Objectives
- Outline
- 8.1 Introduction
- 8.2 Time Class Case Study
- 8.3 Controlling Access to Members
- 8.4 Referring to the Current Object’s Members with the this Reference
- 8.5 Time Class Case Study: Overloaded Constructors
- 8.6 Default and No-Argument Constructors
- 8.7 Notes on Set and Get Methods
- 8.8 Composition
- 8.9 enum Types
- 8.10 Garbage Collection
- 8.11 static Class Members
- 8.12 static Import
- 8.13 final Instance Variables
- 8.14 Package Access
- 8.15 Using BigDecimal for Precise Monetary Calculations
- 8.16 Wrap-Up
-
Summary
- Section 8.2 Time Class Case Study
- Section 8.3 Controlling Access to Members
- Section 8.4 Referring to the Current Object’s Members with the this Reference
- Section 8.5 Time Class Case Study: Overloaded Constructors
- Section 8.6 Default and No-Argument Constructors
- Section 8.7 Notes on Set and Get Methods
- Section 8.8 Composition
- Section 8.9 enum Types
- Section 8.10 Garbage Collection
- Section 8.11 static Class Members
- Section 8.12 static Import
- Section 8.13 final Instance Variables
- Section 8.14 Package Access
- Section 8.15 Using BigDecimal for Precise Monetary Calculations
- Self-Review Exercises
- Answers to Self-Review Exercises
- Answers to Self-Review Exercises
- Making a Difference
-
9 Object-Oriented Programming: Inheritance
- Objectives
- Outline
- 9.1 Introduction
- 9.2 Superclasses and Subclasses
- 9.3 protected Members
-
9.4 Relationship Between Superclasses and Subclasses
- 9.4.1 Creating and Using a CommissionEmployee Class
- 9.4.2 Creating and Using a BasePlusCommissionEmployee Class
- 9.4.3 Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
- 9.4.4 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Instance Variables
- 9.4.5 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables
- 9.5 Constructors in Subclasses
- 9.6 Class Object
- 9.7 Designing with Composition vs. Inheritance
- 9.8 Wrap-Up
- Summary
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
10 Object-Oriented Programming: Polymorphism and Interfaces
- Objectives
- Outline
- 10.1 Introduction
- 10.2 Polymorphism Examples
- 10.3 Demonstrating Polymorphic Behavior
- 10.4 Abstract Classes and Methods
- 10.5 Case Study: Payroll System Using Polymorphism
- 10.6 Allowed Assignments Between Superclass and Subclass Variables
- 10.7 final Methods and Classes
- 10.8 A Deeper Explanation of Issues with Calling Methods from Constructors
- 10.9 Creating and Using Interfaces
- 10.10 Java SE 8 Interface Enhancements
- 10.11 Java SE 9 private Interface Methods
- 10.12 private Constructors
- 10.13 Program to an Interface, Not an Implementation3
- 10.14 Wrap-Up
-
Summary
- Section 10.1 Introduction
- Section 10.3 Demonstrating Polymorphic Behavior
- Section 10.4 Abstract Classes and Methods
- Section 10.5 Case Study: Payroll System Using Polymorphism
- Section 10.6 Allowed Assignments Between Superclass and Subclass Variables
- Section 10.7 final Methods and Classes
- Section 10.8 A Deeper Explanation of Issues with Calling Methods from Constructors
- Section 10.9 Creating and Using Interfaces
- Section 10.10 Java SE 8 Interface Enhancements
- Section 10.11 Java SE 9 private Interface Methods
- Section 10.12 private Constructors
- Section 10.13 Program to an Interface, Not an Implementation
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
11 Exception Handling: A Deeper Look
- Objectives
- Outline
- 11.1 Introduction
- 11.2 Example: Divide by Zero without Exception Handling
- 11.3 Example: Handling ArithmeticExceptions and InputMismatchExceptions
- 11.4 When to Use Exception Handling
- 11.5 Java Exception Hierarchy
- 11.6 finally Block
- 11.7 Stack Unwinding and Obtaining Information from an Exception
- 11.8 Chained Exceptions
- 11.9 Declaring New Exception Types
- 11.10 Preconditions and Postconditions
- 11.11 Assertions
- 11.12 try-with-Resources: Automatic Resource Deallocation
- 11.13 Wrap-Up
-
Summary
- Section 11.1 Introduction
- Section 11.2 Example: Divide by Zero without Exception Handling
- Section 11.3 Example: Handling ArithmeticExceptions and InputMismatchExceptions
- Section 11.4 When to Use Exception Handling
- Section 11.5 Java Exception Hierarchy
- Section 11.6 finally Block
- Section 11.7 Stack Unwinding and Obtaining Information from an Exception
- Section 11.8 Chained Exceptions
- Section 11.9 Declaring New Exception Types
- Section 11.10 Preconditions and Postconditions
- Section 11.11 Assertions
- Section 11.12 try-with-Resources: Automatic Resource Deallocation
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
12 JavaFX Graphical User Interfaces: Part 1
- Objectives
- Outline
- 12.1 Introduction
- 12.2 JavaFX Scene Builder
- 12.3 JavaFX App Window Structure
-
12.4 Welcome App—Displaying Text and an Image
- 12.4.1 Opening Scene Builder and Creating the File Welcome.fxml
- 12.4.2 Adding an Image to the Folder Containing Welcome.fxml
- 12.4.3 Creating a VBox Layout Container
- 12.4.4 Configuring the VBox Layout Container
- 12.4.5 Adding and Configuring a Label
- 12.4.6 Adding and Configuring an ImageView
- 12.4.7 Previewing the Welcome GUI
-
12.5 Tip Calculator App—Introduction to Event Handling
- 12.5.1 Test-Driving the Tip Calculator App
-
12.5.2 Technologies Overview
- Class Application
- Arranging JavaFX Components with a GridPane
- Creating and Customizing the GUI with Scene Builder
- Formatting Numbers as Locale-Specific Currency and Percentage Strings
- Event Handling
- Implementing Interface ChangeListener for Handling Slider Thumb Position Changes
- Model-View-Controller (MVC) Architecture
- FXMLLoader Class
-
12.5.3 Building the App’s GUI
- fx:id Property Values for This App’s Controls
- Creating the TipCalculator.fxml File
- Step 1: Adding a GridPane
- Step 2: Adding Rows to the GridPane
- Step 3: Adding the Controls to the GridPane
- Step 4: Sizing the GridPane to Fit Its Contents
- Step 5: Right-Aligning GridPane Column 0’s Contents
- Step 6: Sizing the GridPane Columns to Fit Their Contents
- Step 7: Sizing the Button
- Previewing the GUI
- Step 8: Configuring the GridPane’s Padding and Horizontal Gap Between Its Columns
- Step 9: Making the tipTextField and totalTextField Uneditable and Not Focusable
- Step 10: Setting the Slider’s Properties
- Previewing the Final Layout
- Specifying the Controller Class’s Name
- Specifying the Calculate Button’s Event-Handler Method Name
- Generating a Sample Controller Class
- 12.5.4 TipCalculator Class
-
12.5.5 TipCalculatorController Class
- Class TipCalculatorController’s import Statements
- TipCalculatorController’s static Variables and Instance Variables
- @FXML Annotation
- TipCalculatorController’s calculateButtonPressed Event Handler
- Registering the Calculate Button’s Event Handler
- Calculating and Displaying the Tip and Total Amounts
- TipCalculatorController’s initalize Method
- Using an Anonymous Inner Class for Event Handling
- Anonymous Inner Class Notes
- Java SE 8: Using a Lambda to Implement the ChangeListener
- 12.6 Features Covered in the Other JavaFX Chapters
- 12.7 Wrap-Up
-
Summary
- Section 12.1 Introduction
- Section 12.2 JavaFX Scene Builder
- Section 12.3 JavaFX App Window Structure
- Section 12.4 Welcome App—Displaying Text and an Image
- Section 12.5.2 Technologies Overview
- Section 12.5.3 Building the App’s GUI
- Section 12.5.4 TipCalculator Class
- Section 12.5.5 TipCalculatorController Class
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
13 JavaFX GUI: Part 2
- Objectives
- Outline
- 13.1 Introduction
- 13.2 Laying Out Nodes in a Scene Graph
-
13.3 Painter App: RadioButtons, Mouse Events and Shapes
- 13.3.1 Technologies Overview
- 13.3.2 Creating the Painter.fxml File
-
13.3.3 Building the GUI
- fx:id Property Values for This App’s Controls
- Step 1: Adding a BorderPane as the Root Layout Node
- Step 2: Configuring the BorderPane
- Step 3: Adding the VBox and Pane
- Step 4: Adding the TitledPanes to the VBox
- Step 5: Customizing the TitledPanes
- Step 6: Adding the RadioButtons to the VBox
- Step 7: Specifying the ToggleGroups for the RadioButtons
- Step 8: Changing the TitledPanes’ Preferred Width and Height
- Step 9: Adding the Buttons
- Step 10: Setting the Width the VBox
- Step 11: Specifying the Controller Class’s Name
- Step 12: Specifying the Event-Handler Method Names
- Step 13: Generating a Sample Controller Class
- 13.3.4 Painter Subclass of Application
- 13.3.5 PainterController Class
-
13.4 Color Chooser App: Property Bindings and Property Listeners
- 13.4.1 Technologies Overview
-
13.4.2 Building the GUI
- fx:id Property Values for This App’s Controls
- Step 1: Adding a GridPane
- Step 2: Configuring the GridPane
- Step 3: Adding the Controls
- Step 4: Configuring the Sliders
- Step 5: Configuring the TextFields
- Step 6: Configuring the Rectangle
- Step 7: Configuring the Circle
- Step 8: Configuring the Rows
- Step 9: Configuring the Columns
- Step 10: Configuring the GridPane
- Step 11: Specifying the Controller Class’s Name
- Step 12: Generating a Sample Controller Class
- 13.4.3 ColorChooser Subclass of Application
- 13.4.4 ColorChooserController Class
- 13.5 Cover Viewer App: Data-Driven GUIs with JavaFX Collections
- 13.6 Cover Viewer App: Customizing ListView Cells
- 13.7 Additional JavaFX Capabilities
- 13.8 JavaFX 9: Java SE 9 JavaFX Updates
- 13.9 Wrap-Up
-
Summary
- Section 13.2 Laying Out Nodes in a Scene Graph
- Section 13.3.1 Technologies Overview
- Section 13.3.2 Creating the Painter.fxml File
- Section 13.3.3 Building the GUI
- Section 13.3.5 PainterController Class
- Section 13.4.1 Technologies Overview
- Section 13.4.2 Building the GUI
- Section 13.4.4 ColorChooserController Class
- Section 13.5 Cover Viewer App: Data-Driven GUIs with JavaFX Collections
- Section 13.5.1 Technologies Overview
- Section 13.5.5 CoverViewerController Class
- Section 13.6.1 Technologies Overview
- Section 13.6.3 ImageTextCell Custom Cell Factory Class
- Section 13.6.4 CoverViewerController Class
- Section 13.7 Additional JavaFX Capabilities
- Section 13.8 JavaFX 9: Java SE 9 JavaFX Updates
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
14 Strings, Characters and Regular Expressions
- Objectives
- Outline
- 14.1 Introduction
- 14.2 Fundamentals of Characters and Strings
- 14.3 Class String
- 14.4 Class StringBuilder
- 14.5 Class Character
- 14.6 Tokenizing Strings
- 14.7 Regular Expressions, Class Pattern and Class Matcher
- 14.8 Wrap-Up
- Summary
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
15 Files, Input/Output Streams, NIO and XML Serialization
- Objectives
- Outline
- 15.1 Introduction
- 15.2 Files and Streams
- 15.3 Using NIO Classes and Interfaces to Get File and Directory Information
- 15.4 Sequential Text Files
- 15.5 XML Serialization
- 15.6 FileChooser and DirectoryChooser Dialogs
- 15.7 (Optional) Additional java.io Classes
- 15.8 Wrap-Up
-
Summary
- Section 15.1 Introduction
- Section 15.2 Files and Streams
- Section 15.3 Using NIO Classes and Interfaces to Get File and Directory Information
- Section 15.4 Sequential Text Files
- Section 15.5 XML Serialization
- Section 15.5.1 Creating a Sequential File Using XML Serialization
- Section 15.5.2 Reading and Deserializing Data from a Sequential File
- Section 15.6 FileChooser and DirectoryChooser Dialogs
- Section 15.7 (Optional) Additional java.io Classes
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
16 Generic Collections
- Objectives
- Outline
- 16.1 Introduction
- 16.2 Collections Overview
- 16.3 Type-Wrapper Classes
- 16.4 Autoboxing and Auto-Unboxing
- 16.5 Interface Collection and Class Collections
- 16.6 Lists
- 16.7 Collections Methods
- 16.8 Class PriorityQueue and Interface Queue
- 16.9 Sets
- 16.10 Maps
- 16.11 Synchronized Collections
- 16.12 Unmodifiable Collections
- 16.13 Abstract Implementations
- 16.14 Java SE 9: Convenience Factory Methods for Immutable Collections1
- 16.15 Wrap-Up
-
Summary
- Section 16.1 Introduction
- Section 16.2 Collections Overview
- Section 16.3 Type-Wrapper Classes
- Section 16.4 Autoboxing and Auto-Unboxing
- Section 16.5 Interface Collection and Class Collections
- Section 16.6 Lists
- Section 16.7 Collections Methods
- Section 16.8 Class PriorityQueue and Interface Queue
- Section 16.9 Sets
- Section 16.10 Maps
- Section 16.11 Synchronized Collections
- Section 16.12 Unmodifiable Collections
- Section 16.13 Abstract Implementations
- Section 16.14 Java SE 9: Convenience Factory Methods for Immutable Collections
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
17 Lambdas and Streams
- Objectives
- Outline
- 17.1 Introduction1
- 17.2 Streams and Reduction
- 17.3 Mapping and Lambdas
- 17.4 Filtering
- 17.5 How Elements Move Through Stream Pipelines
- 17.6 Method References
- 17.7 IntStream Operations
- 17.8 Functional Interfaces
- 17.9 Lambdas: A Deeper Look
- 17.10 Stream<Integer> Manipulations
- 17.11 Stream<String> Manipulations
-
17.12 Stream<Employee> Manipulations
- 17.12.1 Creating and Displaying a List<Employee>
- 17.12.2 Filtering Employees with Salaries in a Specified Range
- 17.12.3 Sorting Employees By Multiple Fields
- 17.12.4 Mapping Employees to Unique-Last-Name Strings
- 17.12.5 Grouping Employees By Department
- 17.12.6 Counting the Number of Employees in Each Department
- 17.12.7 Summing and Averaging Employee Salaries
- 17.13 Creating a Stream<String> from a File
- 17.14 Streams of Random Values
- 17.15 Infinite Streams
- 17.16 Lambda Event Handlers
- 17.17 Additional Notes on Java SE 8 Interfaces
- 17.18 Wrap-Up
-
Summary
- Section 17.1 Introduction
- Section 17.2 Streams and Reduction
- Section 17.2.1 Summing the Integers from 1 through 10 with a for Loop
- Section 17.2.2 External Iteration with for Is Error Prone
- Section 17.2.3 Summing with a Stream and Reduction
- Section 17.2.4 Internal Iteration
- Section 17.3 Mapping and Lambdas
- Section 17.3.1 Lambda Expressions
- Section 17.3.2 Lambda Syntax
- Section 17.3.3 Intermediate and Terminal Operations
- Section 17.4 Filtering
- Section 17.5 How Elements Move Through Stream Pipelines
- Section 17.6 Method References
- Section 17.6.1 Creating an IntStream of Random Values
- Section 17.6.2 Performing a Task on Each Stream Element with forEach and a Method Reference
- Section 17.6.3 Mapping Integers to String Objects with mapToObj
- Section 17.6.4 Concatenating Strings with collect
- Section 17.7 IntStream Operations
- Section 17.7.1 Creating an IntStream and Displaying Its Values
- Section 17.7.2 Terminal Operations count, min, max, sum and average
- Section 17.7.3 Terminal Operation reduce
- Section 17.7.4 Sorting IntStream Values
- Section 17.8 Functional Interfaces
- Section 17.9 Lambdas: A Deeper Look
- Section 17.10 Stream<Integer> Manipulations
- Section 17.10.1 Creating a Stream<Integer>
- Section 17.10.2 Sorting a Stream and Collecting the Results
- Section 17.10.3 Filtering a Stream and Storing the Results for Later Use
- Section 17.10.5 Sorting Previously Collected Results
- Section 17.11.1 Mapping Strings to Uppercase
- Section 17.11.2 Filtering Strings Then Sorting Them in Case-Insensitive Ascending Order
- Section 17.11.3 Filtering Strings Then Sorting Them in Case-Insensitive Descending Order
- Section 17.12.1 Creating and Displaying a List<Employee>
- Section 17.12.2 Filtering Employees with Salaries in a Specified Range
- Section 17.12.3 Sorting Employees By Multiple Fields
- Section 17.12.4 Mapping Employees to Unique Last Name Strings
- Section 17.12.5 Grouping Employees By Department
- Section 17.12.6 Counting the Number of Employees in Each Department
- Section 17.12.7 Summing and Averaging Employee Salaries
- Section 17.13 Creating a Stream<String> from a File
- Section 17.14 Streams of Random Values
- Section 17.15 Infinite Streams
- Section 17.16 Lambda Event Handlers
- Section 17.17 Additional Notes on Java SE 8 Interfaces
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
18 Recursion
- Objectives
- Outline
- 18.1 Introduction
- 18.2 Recursion Concepts
- 18.3 Example Using Recursion: Factorials
- 18.4 Reimplementing Class FactorialCalculator Using BigInteger
- 18.5 Example Using Recursion: Fibonacci Series
- 18.6 Recursion and the Method-Call Stack
- 18.7 Recursion vs. Iteration
- 18.8 Towers of Hanoi
- 18.9 Fractals
- 18.10 Recursive Backtracking
- 18.11 Wrap-Up
-
Summary
- Section 18.1 Introduction
- Section 18.2 Recursion Concepts
- Section 18.3 Example Using Recursion: Factorials
- Section 18.5 Example Using Recursion: Fibonacci Series
- Section 18.6 Recursion and the Method-Call Stack
- Section 18.7 Recursion vs. Iteration
- Section 18.9 Fractals
- Section 18.10 Recursive Backtracking
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
19 Searching, Sorting and Big O
- Objectives
- Outline
- 19.1 Introduction
- 19.2 Linear Search
- 19.3 Big O Notation
- 19.4 Binary Search
- 19.5 Sorting Algorithms
- 19.6 Selection Sort
- 19.7 Insertion Sort
- 19.8 Merge Sort
- 19.9 Big O Summary for This Chapter’s Searching and Sorting Algorithms
- 19.10 Massive Parallelism and Parallel Algorithms
- 19.11 Wrap-Up
- Summary
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
20 Generic Classes and Methods: A Deeper Look
- Objectives
- Outline
- 20.1 Introduction
- 20.2 Motivation for Generic Methods
- 20.3 Generic Methods: Implementation and Compile-Time Translation
- 20.4 Additional Compile-Time Translation Issues: Methods That Use a Type Parameter as the Return Type
- 20.5 Overloading Generic Methods
- 20.6 Generic Classes
- 20.7 Wildcards in Methods That Accept Type Parameters
- 20.8 Wrap-Up
-
Summary
- Section 20.1 Introduction
- Section 20.2 Motivation for Generic Methods
- Section 20.3 Generic Methods: Implementation and Compile-Time Translation
- Section 20.4 Additional Compile-Time Translation Issues: Methods That Use a Type Parameter as the Return Type
- Section 20.5 Overloading Generic Methods
- Section 20.6 Generic Classes
- Section 20.7 Wildcards in Methods That Accept Type Parameters
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
21 Custom Generic Data Structures
- Objectives
- Outline
- 21.1 Introduction
- 21.2 Self-Referential Classes
- 21.3 Dynamic Memory Allocation
-
21.4 Linked Lists
- 21.4.1 Singly Linked Lists
- 21.4.2 Implementing a Generic List Class
- 21.4.3 Generic Classes ListNode and List
- 21.4.4 Class ListTest
- 21.4.5 List Method insertAtFront
- 21.4.6 List Method insertAtBack
- 21.4.7 List Method removeFromFront
- 21.4.8 List Method removeFromBack
- 21.4.9 List Method print
-
21.4.10 Creating Your Own Packages
- Steps for Declaring a Reusable Class
- Step 1: Creating public Types for Reuse
- Step 2: Adding the package Statements
- Package Naming Conventions
- Fully Qualified Names
- Step 3: Compiling Packaged Types
- Step 4: Importing Types from Your Package
- Single-Type-Import vs. Type-Import-On-Demand Declarations
- Specifying the Classpath When Compiling a Program
- Specifying the Classpath When Executing a Program
- 21.5 Stacks
- 21.6 Queues
- 21.7 Trees
- 21.8 Wrap-Up
- Summary
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Special Section: Building Your Own Compiler
-
22 JavaFX Graphics, Animation and Video
- Objectives
- Outline
- 22.1 Introduction
- 22.2 Controlling Fonts with Cascading Style Sheets (CSS)
- 22.3 Displaying Two-Dimensional Shapes
- 22.4 Polylines, Polygons and Paths
- 22.5 Transforms
-
22.6 Playing Video with Media, MediaPlayer and MediaViewer
- 22.6.1 VideoPlayer GUI
-
22.6.2 VideoPlayerController Class
- Instance Variables
- Creating a Media Object Representing the Video to Play
- Creating a MediaPlayer Object to Load the Video and Control Playback
- Attaching the MediaPlayer Object to the MediaView to Display the Video
- Configuring Event Handlers for MediaPlayer Events
- Binding the MediaViewer’s Size to the Scene’s Size
- Method playPauseButtonPressed
- Using Java SE 8 Lambdas to Implement the Runnables
- 22.7 Transition Animations
- 22.8 Timeline Animations
- 22.9 Frame-by-Frame Animation with AnimationTimer
- 22.10 Drawing on a Canvas
- 22.11 Three-Dimensional Shapes
- 22.12 Wrap-Up
-
Summary
- Section 22.2 Controlling Fonts with Cascading Style Sheets (CSS)
- Section 22.2.1 CSS That Styles the GUI
- Section 22.2.2 FXML That Defines the GUI—Introduction to XML Markup
- Section 22.2.3 Referencing the CSS File from FXML
- Section 22.2.4 Specifying the VBox’s Style Class
- Section 22.2.5 Programmatically Loading CSS
- Section 22.3 Displaying Two-Dimensional Shapes
- Section 22.3.1 Defining Two-Dimensional Shapes with FXML
- Section 22.3.2 CSS That Styles the Two-Dimensional Shapes
- Section 22.4 Polylines, Polygons and Paths
- Section 22.4.2 PolyshapesController Class
- Section 22.5 Transforms
- Section 22.6 Playing Video with Media, MediaPalyer and MediaViewer
- Section 22.6.1 VideoPlayer GUI
- Section 22.6.2 VideoPlayerController Class
- Section 22.7 Transition Animations
- Section 22.7.2 TransitionAnimationsController Class
- Section 22.8 Timeline Animations
- Section 22.9 Frame-By-Frame Animation with AnimationTimer
- Section 22.10 Drawing on a Canvas
- Section 22.11 Three-Dimensional Shapes
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
23 Concurrency
- Objectives
- Outline
- 23.1 Introduction
- 23.2 Thread States and Life Cycle
- 23.3 Creating and Executing Threads with the Executor Framework
- 23.4 Thread Synchronization
- 23.5 Producer/Consumer Relationship without Synchronization
- 23.6 Producer/Consumer Relationship: ArrayBlockingQueue
- 23.7 (Advanced) Producer/Consumer Relationship with synchronized, wait, notify and notifyAll
- 23.8 (Advanced) Producer/Consumer Relationship: Bounded Buffers
- 23.9 (Advanced) Producer/Consumer Relationship: The Lock and Condition Interfaces
- 23.10 Concurrent Collections
- 23.11 Multithreading in JavaFX
- 23.12 sort/parallelSort Timings with the Java SE 8 Date/Time API
- 23.13 Java SE 8: Sequential vs. Parallel Streams
- 23.14 (Advanced) Interfaces Callable and Future
- 23.15 (Advanced) Fork/Join Framework
- 23.16 Wrap-Up
-
Summary
- Section 23.1 Introduction
- Section 23.2 Thread States and Life Cycle
- Section 23.3 Creating and Executing Threads with the Executor Framework
- Section 23.4 Thread Synchronization
- Section 23.5 Producer/Consumer Relationship without Synchronization
- Section 23.6 Producer/Consumer Relationship: ArrayBlockingQueue
- Section 23.7 (Advanced) Producer/Consumer Relationship with synchronized, wait, notify and notifyAll
- Section 23.8 (Advanced) Producer/Consumer Relationship: Bounded Buffers
- Section 23.9 (Advanced) Producer/Consumer Relationship: The Lock and Condition Interfaces
- Section 23.10 Concurrent Collections
- Section 23.11 Multithreading in JavaFX
- Section 23.11.1 Performing Computations in a Worker Thread: Fibonacci Numbers
- Section 23.11.2 Processing Intermediate Results: Sieve of Eratosthenes
- Section 23.12 sort/parallelSort Timings with the Java SE 8 Date/Time API
- Section 23.13 Java SE 8: Sequential vs. Parallel Streams
- Section 23.14 (Advanced) Interfaces Callable and Future
- Section 23.15 (Advanced) Fork/Join Framework
- Self-Review Exercises
- Exercises
- Exercises
-
24 Accessing Databases with JDBC
- Objectives
- Outline
- 24.1 Introduction
- 24.2 Relational Databases
- 24.3 A books Database
- 24.4 SQL
- 24.5 Setting Up a Java DB Database1
- 24.6 Connecting to and Querying a Database
- 24.7 Querying the books Database
- 24.8 RowSet Interface
- 24.9 PreparedStatements
- 24.10 Stored Procedures
- 24.11 Transaction Processing
- 24.12 Wrap-Up
-
Summary
- Section 24.1 Introduction
- Section 24.2 Relational Databases
- Section 24.3 A books Database
- Section 24.4.1 Basic SELECT Query
- Section 24.4.2 WHERE Clause
- Section 24.4.3 ORDER BY Clause
- Section 24.4.4 Merging Data from Multiple Tables: INNER JOIN
- Section 24.4.5 INSERT Statement
- Section 24.4.6 UPDATE Statement
- Section 24.4.7 DELETE Statement
- Section 24.5 Setting Up a Java DB Database
- Section 24.6 Connecting to and Querying a Database
- Section 24.7 Querying the books Database
- Section 24.8 RowSet Interface
- Section 24.9 PreparedStatements
- Section 24.10 Stored Procedures
- Section 24.11 Transaction Processing
- Self-Review Exercise
- Answers to Self-Review Exercise
- Exercises
-
25 Introduction to JShell: Java 9’s REPL for Interactive Java
- Objectives
- Outline
- 25.1 Introduction
- 25.2 Installing JDK 9
-
25.3 Introduction to JShell
- 25.3.1 Starting a JShell Session
- 25.3.2 Executing Statements
- 25.3.3 Declaring Variables Explicitly
- 25.3.4 Listing and Executing Prior Snippets
- 25.3.5 Evaluating Expressions and Declaring Variables Implicitly
- 25.3.6 Using Implicitly Declared Variables
- 25.3.7 Viewing a Variable’s Value
- 25.3.8 Resetting a JShell Session
- 25.3.9 Writing Multiline Statements
- 25.3.10 Editing Code Snippets
- 25.3.11 Exiting JShell
- 25.4 Command-Line Input in JShell
- 25.5 Declaring and Using Classes
- 25.6 Discovery with JShell Auto-Completion
- 25.7 Exploring a Class’s Members and Viewing Documentation
- 25.8 Declaring Methods
- 25.9 Exceptions
- 25.10 Importing Classes and Adding Packages to the CLASSPATH
- 25.11 Using an External Editor
- 25.12 Summary of JShell Commands
- 25.13 Keyboard Shortcuts for Snippet Editing
- 25.14 How JShell Reinterprets Java for Interactive Use
- 25.15 IDE JShell Support
- 25.16 Wrap-Up
- Self-Review Exercises
- Answers to Self-Review Exercises
- Chapters on the Web
- A Operator Precedence Chart
- B ASCII Character Set
- C Keywords and Reserved Words
- D Primitive Types
- E Using the Debugger
- Appendices on the Web
- Index
Product information
- Title: Java How To Program, Late Objects, 11th Edition
- Author(s):
- Release date: March 2017
- Publisher(s): Pearson
- ISBN: 9780137464180
You might also like
book
Java How to Program, Early Objects, 11th Edition
For courses in Java programming Unparalleled breadth and depth of object-oriented programming concepts The Deitels’ groundbreaking …
book
Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17
Learn the fundamentals of the Java 17 LTS or Java Standard Edition version 17 Long Term …
book
Java in a Nutshell, 8th Edition
This updated edition of the Nutshell guide not only helps experienced Java programmers get the most …
book
Core Java for the Impatient, 3rd Edition
Clear, Concise Guide to the Core Language and Libraries--Updated through Java 17 Modern Java introduces major …