This is completed downloadable of Solution Manual for Java How to Program, Early Objects (11th Edition) (Deitel: How to Program) 11th Edition
Product Details:
- ISBN-10 : 9780134743356
- ISBN-13 : 978-0134743356
- Author:
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, Early 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, Late Objects, 11th Edition also is available.]
Table of Content:
- Contents
- Foreword
- Preface
- New and Updated Features
- Flexibility Using Java SE 8 or the New Java SE 9
- Java How to Program, 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 (JShell Begins in Part 1; the Rest is in Part 9)
- Object-Oriented Programming (Part 3)
- Flexible JavaFX GUI, Graphics and Multimedia Coverage (Part 4) and Optional Swing Coverage (Part 11)
- Data Structures and Generic Collections (Part 5)
- Flexible Lambdas and Streams Coverage (Chapter 17)
- 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, Late Objects Version, 11/e
- Instructor Supplements
- Online Practice and Assessment with MyProgrammingLab™
- 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.
- 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.2.1 Moore’s Law
- 1.2.2 Computer Organization
- 1.3 Data Hierarchy
- 1.4 Machine Languages, Assembly Languages and High-Level Languages
- 1.5 Introduction to Object Technology
- 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.6.1 Windows—A Proprietary Operating System
- 1.6.2 Linux—An Open-Source Operating System
- 1.6.3 Apple’s macOS and Apple’s iOS for iPhone®, iPad® and iPod Touch® Devices
- 1.6.4 Google’s Android
- 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.11.1 Internet: A Network of Networks
- 1.11.2 World Wide Web: Making the Internet User-Friendly
- 1.11.3 Web Services and Mashups
- 1.11.4 Internet of Things
- 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.2.1 Compiling the Application
- 2.2.2 Executing the Application
- 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.2.1 Compiling the Application
- Section 2.2.2 Executing the Application
- 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 Introduction to Classes, Objects, Methods and Strings
- Objectives
- Outline
- 3.1 Introduction1
- 3.2 Instance Variables, set Methods and get Methods
- 3.2.1 Account Class with an Instance Variable, and set and get Methods
- Class Declaration
- Identifiers and Camel-Case Naming
- Instance Variable name
- Access Modifiers public and private
- setName Method of Class Account
- Parameters Are Local Variables
- setName Method Body
- getName Method of Class Account
- 3.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 Variables
- Calling Class Account’s setName Method
- Displaying the Name That Was Entered by the User
- 3.2.3 Compiling and Executing an App with Multiple Classes
- 3.2.4 Account UML Class Diagram
- Top Compartment
- Middle Compartment
- Bottom Compartment
- Return Types
- Parameters
- 3.2.5 Additional Notes on Class AccountTest
- static Method main
- Notes on import Declarations
- 3.2.6 Software Engineering with private Instance Variables and public set and get Methods
- Conceptual View of an Account Object with Encapsulated Data
- 3.3 Account Class: Initializing Objects with Constructors
- 3.3.1 Declaring an Account Constructor for Custom Object Initialization
- Account Constructor Declaration
- Parameter name of Class Account’s Constructor and Method setName
- 3.3.2 Class AccountTest: Initializing Account Objects When They’re Created
- Constructors Cannot Return Values
- Default Constructor
- There’s No Default Constructor in a Class That Declares a Constructor
- Adding the Constructor to Class Account’s UML Class Diagram
- 3.4 Account Class with a Balance; Floating-Point Numbers
- 3.4.1 Account Class with a balance Instance Variable of Type double
- Account Class Two-Parameter Constructor
- Account Class deposit Method
- Account Class getBalance Method
- Account’s Methods Can All Use balance
- 3.4.2 AccountTest Class to Use Class Account
- Displaying the Account Objects’ Initial Balances
- Formatting Floating-Point Numbers for Display
- Reading a Floating-Point Value from the User and Making a Deposit
- Duplicated Code in Method main
- UML Class Diagram for Class Account
- 3.5 Primitive Types vs. Reference Types
- 3.6 (Optional) GUI and Graphics Case Study: A Simple GUI
- 3.6.1 What Is a Graphical User Interface?
- 3.6.2 JavaFX Scene Builder and FXML
- FXML (FX Markup Language)
- 3.6.3 Welcome App—Displaying Text and an Image
- 3.6.4 Opening Scene Builder and Creating the File Welcome.fxml
- 3.6.5 Adding an Image to the Folder Containing Welcome.fxml
- 3.6.6 Creating a VBox Layout Container
- 3.6.7 Configuring the VBox
- Specifying the VBox’s Alignment
- Specifying the VBox’s Preferred Size
- 3.6.8 Adding and Configuring a Label
- Adding a Label to the VBox
- Changing the Label’s Text
- Changing the Label’s Font
- 3.6.9 Adding and Configuring an ImageView
- Adding an ImageView to the VBox
- Setting the ImageView’s Image
- Changing the ImageView’s Size
- 3.6.10 Previewing the Welcome GUI
- GUI and Graphics Case Study Exercise
- 3.7 Wrap-Up
- Summary
- Section 3.2 Instance Variables, set Methods and get Methods
- Section 3.2.1 Account Class with an Instance Variable, a set Method and a get Method
- Section 3.2.2 AccountTest Class That Creates and Uses an Object of Class Account
- Section 3.2.3 Compiling and Executing an App with Multiple Classes
- Section 3.2.4 Account UML Class Diagram with an Instance Variable and set and get Methods
- Section 3.2.5 Additional Notes on Class AccountTest
- Section 3.2.6 Software Engineering with private Instance Variables and public set and get Methods
- Section 3.3 Account Class: Initializing Objects with Constructors
- Section 3.4 Account Class with a Balance; Floating-Point Numbers
- Section 3.5 Primitive Types vs. Reference Types
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
- 4 Control Statements: Part 1; Assignment, ++ and — Operators
- Objectives
- Outline
- 4.1 Introduction
- 4.2 Algorithms
- 4.3 Pseudocode
- 4.4 Control Structures
- 4.4.1 Sequence Structure in Java
- 4.4.2 Selection Statements in Java
- 4.4.3 Iteration Statements in Java
- 4.4.4 Summary of Control Statements in Java
- 4.5 if Single-Selection Statement
- 4.6 if…else Double-Selection Statement
- UML Activity Diagram for an if…else Statement
- 4.6.1 Nested if…else Statements
- 4.6.2 Dangling-else Problem
- 4.6.3 Blocks
- 4.6.4 Conditional Operator (?:)
- 4.7 Student Class: Nested if…else Statements
- 4.8 while Iteration Statement
- 4.9 Formulating Algorithms: Counter-Controlled Iteration
- 4.10 Formulating Algorithms: Sentinel-Controlled Iteration
- 4.11 Formulating Algorithms: Nested Control Statements
- 4.12 Compound Assignment Operators
- 4.13 Increment and Decrement Operators
- 4.14 Primitive Types
- 4.15 (Optional) GUI and Graphics Case Study: Event Handling; Drawing Lines
- 4.15.1 Test-Driving the Completed Draw Lines App
- 4.15.2 Building the App’s GUI
- Opening Scene Builder and Creating the File DrawLines.fxml
- Creating a BorderPane Layout Container
- Adding a ToolBar and Configuring Its Button
- Configuring the Button’s Text
- Adding and Configuring a Canvas
- Setting the Canvas’s Width and Height
- Configuring the BorderPane Layout Container’s Size
- Saving the Design
- 4.15.3 Preparing to Interact with the GUI Programmatically
- Specifying the App’s Controller Class
- Specifying the Canvas’s Instance Variable Name
- Specifying the Button’s Event-Handler Method
- Generating the Initial Controller Class
- 4.15.4 Class DrawLinesController
- @FXML Annotation
- Getting a GraphicsContext to Draw on a Canvas
- Canvas’s Coordinate System
- Drawing Lines
- 4.15.5 Class DrawLines—The Main Application Class
- GUI and Graphics Case Study Exercises
- 4.16 Wrap-Up
- Summary
- Section 4.1 Introduction
- Section 4.2 Algorithms
- Section 4.3 Pseudocode
- Section 4.4 Control Structures
- Section 4.4.1 Sequence Structure in Java
- Section 4.4.2 Selection Statements in Java
- Section 4.4.3 Iteration Statements in Java
- Section 4.4.4 Summary of Control Statements in Java
- Section 4.5 if Single-Selection Statement
- Section 4.6 if…else Double-Selection Statement
- Section 4.6.1 Nested if…else Statements
- Section 4.6.2 Dangling-else Problem
- Section 4.6.3 Blocks
- Section 4.6.4 Conditional Operator (?:)
- Section 4.8 while Iteration Statement
- Section 4.9 Formulating Algorithms: Counter-Controlled Iteration
- Section 4.10 Formulating Algorithms: Sentinel-Controlled Iteration
- Section 4.12 Compound Assignment Operators
- Section 4.13 Increment and Decrement Operators
- Section 4.14 Primitive Types
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
- 5 Control Statements: Part 2; Logical Operators
- Objectives
- Outline
- 5.1 Introduction
- 5.2 Essentials of Counter-Controlled Iteration
- 5.3 for Iteration Statement
- 5.4 Examples Using the for Statement
- 5.4.1 Application: Summing the Even Integers from 2 to 20
- 5.4.2 Application: Compound-Interest Calculations
- Formatting Strings with Field Widths and Justification
- Performing the Interest Calculations with static Method pow of Class Math
- Formatting Floating-Point Numbers
- A Warning about Displaying Rounded Values
- 5.5 do…while Iteration Statement
- 5.6 switch Multiple-Selection Statement
- 5.7 Class AutoPolicy Case Study: Strings in switch Statements
- 5.8 break and continue Statements
- 5.8.1 break Statement
- 5.8.2 continue Statement
- 5.9 Logical Operators
- 5.9.1 Conditional AND (&&) Operator
- 5.9.2 Conditional OR (||) Operator
- 5.9.3 Short-Circuit Evaluation of Complex Conditions
- 5.9.4 Boolean Logical AND (&) and Boolean Logical Inclusive OR (|) Operators
- 5.9.5 Boolean Logical Exclusive OR (^)
- 5.9.6 Logical Negation (!) Operator
- 5.9.7 Logical Operators Example
- Precedence and Associativity of the Operators Presented So Far
- 5.10 Structured-Programming Summary
- 5.11 (Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals
- 5.12 Wrap-Up
- Summary
- Section 5.2 Essentials of Counter-Controlled Iteration
- Section 5.3 for Iteration Statement
- Section 5.4.2 Application: Compound-Interest Calculations
- Section 5.5 do…while Iteration Statement
- Section 5.6 switch Multiple-Selection Statement
- Section 5.7 Class AutoPolicy Case Study: Strings in switch Statements
- Section 5.8.1 break Statement
- Section 5.8.2 continue Statement
- Section 5.9 Logical Operators
- Section 5.9.1 Conditional AND (&&) Operator
- Section 5.9.2 Conditional OR (||) Operator
- Section 5.9.3 Short-Circuit Evaluation of Complex Conditions
- Section 5.9.4 Boolean Logical AND (&) and Boolean Logical Inclusive OR (|) Operators
- Section 5.9.5 Boolean Logical Exclusive OR (^)
- Section 5.9.6 Logical Negation (!) Operator
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
- 6 Methods: A Deeper Look
- Objectives
- Outline
- 6.1 Introduction
- 6.2 Program Units in Java
- 6.3 static Methods, static Fields and Class Math
- 6.4 Methods with Multiple Parameters
- 6.5 Notes on Declaring and Using Methods
- 6.6 Method-Call Stack and Activation Records
- 6.6.1 Method-Call Stack
- 6.6.2 Stack Frames
- 6.6.3 Local Variables and Stack Frames
- 6.6.4 Stack Overflow
- 6.7 Argument Promotion and Casting
- 6.8 Java API Packages
- 6.9 Case Study: Secure Random-Number Generation
- 6.10 Case Study: A Game of Chance; Introducing enum Types
- 6.11 Scope of Declarations
- 6.12 Method Overloading
- 6.12.1 Declaring Overloaded Methods
- 6.12.2 Distinguishing Between Overloaded Methods
- 6.12.3 Return Types of Overloaded Methods
- 6.13 (Optional) GUI and Graphics Case Study: Colors and Filled Shapes
- 6.14 Wrap-Up
- Summary
- Section 6.1 Introduction
- Section 6.2 Program Units in Java
- Section 6.3 static Methods, static Fields and Class Math
- Section 6.4 Methods with Multiple Parameters
- Section 6.5 Notes on Declaring and Using Methods
- Section 6.6 Method-Call Stack and Activation Records
- Section 6.7 Argument Promotion and Casting
- Section 6.9 Case Study: Secure Random-Number Generation
- Section 6.10 Case Study: A Game of Chance; Introducing enum Types
- Section 6.11 Scope of Declarations
- Section 6.12 Method Overloading
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
- 7 Arrays and ArrayLists
- Objectives
- Outline
- 7.1 Introduction
- 7.2 Arrays
- 7.3 Declaring and Creating Arrays
- 7.4 Examples Using Arrays
- 7.4.1 Creating and Initializing an Array
- 7.4.2 Using an Array Initializer
- 7.4.3 Calculating the Values to Store in an Array
- 7.4.4 Summing the Elements of an Array
- 7.4.5 Using Bar Charts to Display Array Data Graphically
- 7.4.6 Using the Elements of an Array as Counters
- 7.4.7 Using Arrays to Analyze Survey Results
- The frequency Array
- Summarizing the Results
- 7.5 Exception Handling: Processing the Incorrect Response
- 7.5.1 The try Statement
- 7.5.2 Executing the catch Block
- 7.5.3 toString Method of the Exception Parameter
- 7.6 Case Study: Card Shuffling and Dealing Simulation
- 7.7 Enhanced for Statement
- 7.8 Passing Arrays to Methods
- 7.9 Pass-By-Value vs. Pass-By-Reference
- 7.10 Case Study: Class GradeBook Using an Array to Store Grades
- 7.11 Multidimensional Arrays
- 7.11.1 Arrays of One-Dimensional Arrays
- 7.11.2 Two-Dimensional Arrays with Rows of Different Lengths
- 7.11.3 Creating Two-Dimensional Arrays with Array-Creation Expressions
- 7.11.4 Two-Dimensional Array Example: Displaying Element Values
- 7.11.5 Common Multidimensional-Array Manipulations Performed with for Statements
- 7.12 Case Study: Class GradeBook Using a Two-Dimensional Array
- 7.13 Variable-Length Argument Lists
- 7.14 Using Command-Line Arguments
- 7.15 Class Arrays
- 7.16 Introduction to Collections and Class ArrayList
- 7.17 (Optional) GUI and Graphics Case Study: Drawing Arcs
- 7.18 Wrap-Up
- Summary
- Section 7.1 Introduction
- Section 7.2 Arrays
- Section 7.3 Declaring and Creating Arrays
- Section 7.4 Examples Using Arrays
- Section 7.5 Exception Handling: Processing the Incorrect Response
- Section 7.6 Case Study: Card Shuffling and Dealing Simulation
- Section 7.7 Enhanced for Statement
- Section 7.8 Passing Arrays to Methods
- Section 7.9 Pass-By-Value vs. Pass-By-Reference
- Section 7.11 Multidimensional Arrays
- Section 7.13 Variable-Length Argument Lists
- Section 7.14 Using Command-Line Arguments
- Section 7.15 Class Arrays
- Section 7.16 Introduction to Collections and Class ArrayList
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Special Section: Building Your Own Computer
- 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 (Optional) GUI and Graphics Case Study: Using Objects with Graphics
- 8.17 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
- 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
- Overview of Class CommissionEmployee’s Methods and Instance Variables
- Class CommissionEmployee’s Constructor
- Class CommissionEmployee’s earnings Method
- Class CommissionEmployee’s toString Method
- @Override Annotaton
- Class CommissionEmployeeTest
- 9.4.2 Creating and Using a BasePlusCommissionEmployee Class
- Testing Class BasePlusCommissionEmployee
- Notes on Class BasePlusCommissionEmployee
- 9.4.3 Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
- A Subclass’s Constructor Must Call Its Superclass’s Constructor
- BasePlusCommissionEmployee Methods Earnings and toString
- 9.4.4 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Instance Variables
- Class BasePlusCommissionEmployee
- A Subclass Object Contains the Instance Variables of All of Its Superclasses
- Testing Class BasePlusCommissionEmployee
- Notes on Using protected Instance Variables
- 9.4.5 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables
- Class CommissionEmployee
- Class BasePlusCommissionEmployee
- Class BasePlusCommissionEmployee’s earnings Method
- Class BasePlusCommissionEmployee’s toString Method
- Testing Class BasePlusCommissionEmployee
- 9.5 Constructors in Subclasses
- 9.6 Class Object
- 9.7 Designing with Composition vs. Inheritance
- 9.8 Wrap-Up
- Summary
- Section 9.1 Introduction
- Section 9.2 Superclasses and Subclasses
- Section 9.3 protected Members
- Section 9.4 Relationship Between Superclasses and Subclasses
- Section 9.5 Constructors in Subclasses
- Section 9.6 Class Object
- 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.5.1 Abstract Superclass Employee
- 10.5.2 Concrete Subclass SalariedEmployee
- 10.5.3 Concrete Subclass HourlyEmployee
- 10.5.4 Concrete Subclass CommissionEmployee
- 10.5.5 Indirect Concrete Subclass BasePlusCommissionEmployee
- 10.5.6 Polymorphic Processing, Operator instanceof and Downcasting
- Creating the Array of Employees
- Polymorphically Processing Employees
- Performing Type-Specific Operations on BasePlusCommissionEmployees
- Calling earnings Polymorphically
- Getting Each Employee’s Class Name
- Avoiding Compilation Errors with Downcasting
- 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.9.1 Developing a Payable Hierarchy
- UML Diagram Containing an Interface
- 10.9.2 Interface Payable
- 10.9.3 Class Invoice
- A Class Can Extend Only One Other Class But Can Implement Many Interfaces
- 10.9.4 Modifying Class Employee to Implement Interface Payable
- Subclasses of Employee and Interface Payable
- 10.9.5 Using Interface Payable to Process Invoices and Employees Polymorphically
- 10.9.6 Some Common Interfaces of the Java API
- 10.10 Java SE 8 Interface Enhancements
- 10.10.1 default Interface Methods
- Adding Methods to Existing Interfaces
- Interfaces vs. abstract Classes
- 10.10.2 static Interface Methods
- 10.10.3 Functional Interfaces
- 10.11 Java SE 9 private Interface Methods
- 10.12 private Constructors
- 10.13 Program to an Interface, Not an Implementation3
- 10.13.1 Implementation Inheritance Is Best for Small Numbers of Tightly Coupled Classes
- 10.13.2 Interface Inheritance Is Best for Flexibility
- 10.13.3 Rethinking the Employee Hierarchy
- Flexibility if Compensation Models Change
- Flexibility if Employees Are Promoted
- Flexibility if Employees Acquire New Capabilities
- 10.14 (Optional) GUI and Graphics Case Study: Drawing with Polymorphism
- 10.15 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
- Specifying the VBox’s Alignment
- Specifying the VBox’s Preferred Size
- 12.4.5 Adding and Configuring a Label
- Adding a Label to the VBox
- Changing the Label’s Text
- Changing the Label’s Font
- 12.4.6 Adding and Configuring an ImageView
- Adding an ImageView to the VBox
- Setting the ImageView’s Image
- Changing the ImageView’s Size
- 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
- Entering a Bill Total
- Selecting a Custom Tip Percentage
- 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
- Overridden Application Method start
- Creating the Scene
- 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
- RadioButtons and ToggleGroups
- BorderPane Layout Container
- TitledPane Layout Container
- JavaFX Shapes
- Pane Layout Container
- Mouse Event Handling
- Setting a Control’s User Data
- 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
- PenSize enum
- Instance Variables
- Method initialize
- drawingAreaMouseDragged Event Handler
- colorRadioButtonSelected Event Handler
- sizeRadioButtonSelected Event Handler
- undoButtonPressed Event Handler
- clearButtonPressed Event Handler
- 13.4 Color Chooser App: Property Bindings and Property Listeners
- 13.4.1 Technologies Overview
- RGBA Colors
- Properties of a Class
- Property Bindings
- Property Listeners
- 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
- Instance Variables
- Method initialize
- Property-to-Property Bindings
- Property Listeners
- 13.5 Cover Viewer App: Data-Driven GUIs with JavaFX Collections
- 13.5.1 Technologies Overview
- 13.5.2 Adding Images to the App’s Folder
- 13.5.3 Building the GUI
- fx:id Property Values for This App’s Controls
- Adding and Configuring the Controls
- Specifying the Controller Class’s Name
- Generating a Sample Controller Class
- 13.5.4 CoverViewer Subclass of Application
- 13.5.5 CoverViewerController Class
- @FXML Instance Variables
- Instance Variable books
- Initializing the books ObservableList
- Listening for ListView Selection Changes
- 13.6 Cover Viewer App: Customizing ListView Cells
- 13.6.1 Technologies Overview
- ListCell Generic Class for Custom ListView Cell Formats
- Programmatically Creating Layouts and Controls
- 13.6.2 Copying the CoverViewer App
- 13.6.3 ImageTextCell Custom Cell Factory Class
- Constructor
- Method updateItem
- 13.6.4 CoverViewerController Class
- 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
- (Optional) GUI and Graphics Case Study Exercise: Interactive Polymorphic Drawing App
- 14 Strings, Characters and Regular Expressions
- Objectives
- Outline
- 14.1 Introduction
- 14.2 Fundamentals of Characters and Strings
- 14.3 Class String
- 14.3.1 String Constructors
- 14.3.2 String Methods length, charAt and getChars
- 14.3.3 Comparing Strings
- String Method equals
- Comparing Strings with the == Operator
- String Method equalsIgnoreCase
- String Method compareTo
- String Method regionMatches
- String Methods startsWith and endsWith
- 14.3.4 Locating Characters and Substrings in Strings
- 14.3.5 Extracting Substrings from Strings
- 14.3.6 Concatenating Strings
- 14.3.7 Miscellaneous String Methods
- 14.3.8 String Method valueOf
- 14.4 Class StringBuilder
- 14.4.1 StringBuilder Constructors
- 14.4.2 StringBuilder Methods length, capacity, setLength and ensureCapacity
- 14.4.3 StringBuilder Methods charAt, setCharAt, getChars and reverse
- 14.4.4 StringBuilder append Methods
- 14.4.5 StringBuilder Insertion and Deletion Methods
- 14.5 Class Character
- 14.6 Tokenizing Strings
- 14.7 Regular Expressions, Class Pattern and Class Matcher
- 14.7.1 Replacing Substrings and Splitting Strings
- 14.7.2 Classes Pattern and Matcher
- Java SE 8
- Java SE 9: New Matcher Methods
- 14.8 Wrap-Up
- Summary
- Section 14.2 Fundamentals of Characters and Strings
- Section 14.3 Class String
- Section 14.4 Class StringBuilder
- Section 14.5 Class Character
- Section 14.6 Tokenizing Strings
- Section 14.7 Regular Expressions, Class Pattern and Class Matcher
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Special Section: String-Manipulation Exercises
- Special Section: Challenging String-Manipulation Projects
- 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.4.1 Creating a Sequential Text File
- Class CreateTextFile
- Writing Data to the File
- Sample Output
- 15.4.2 Reading Data from a Sequential Text File
- 15.4.3 Case Study: A Credit-Inquiry Program
- MenuOption enum
- CreditInquiry Class
- 15.4.4 Updating Sequential Files
- 15.5 XML Serialization
- 15.5.1 Creating a Sequential File Using XML Serialization
- Declaring Class Account
- Plain Old Java Objects
- Declaring Class Accounts
- Writing XML Serialized Objects to a File
- The XML Output
- 15.5.2 Reading and Deserializing Data from a Sequential File
- 15.6 FileChooser and DirectoryChooser Dialogs
- 15.7 (Optional) Additional java.io Classes
- 15.7.1 Interfaces and Classes for Byte-Based Input and Output
- Pipe Streams
- Filter Streams
- Data Streams
- Buffered Streams
- Memory-Based byte Array Steams
- Sequencing Input from Multiple Streams
- 15.7.2 Interfaces and Classes for Character-Based Input and Output
- Character-Based Buffering Readers and Writers
- Memory-Based char Array Readers and Writers
- Character-Based File, Pipe and String Readers and Writers
- 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.6.1 ArrayList and Iterator
- Type Inference with the <> Notation
- 16.6.2 LinkedList
- Method convertToUppercaseStrings
- Method removeItems
- Method printReversedList
- Views into Collections and Arrays Method asList
- Viewing Arrays as Lists and Converting Lists to Arrays
- 16.7 Collections Methods
- 16.7.1 Method sort
- Sorting in Ascending Order
- Sorting in Descending Order
- Sorting with a Comparator
- 16.7.2 Method shuffle
- 16.7.3 Methods reverse, fill, copy, max and min
- 16.7.4 Method binarySearch
- 16.7.5 Methods addAll, frequency and disjoint
- 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.2.1 Summing the Integers from 1 through 10 with a for Loop
- 17.2.2 External Iteration with for Is Error Prone
- 17.2.3 Summing with a Stream and Reduction
- Streams and Stream Pipelines
- Specifying the Data Source
- Calculating the Sum of the IntStream’s Elements
- Processing the Stream Pipeline
- 17.2.4 Internal Iteration
- 17.3 Mapping and Lambdas
- 17.3.1 Lambda Expressions
- 17.3.2 Lambda Syntax
- Eliminating a Lambda’s Parameter Type(s)
- Simplifying the Lambda’s Body
- Simplifying the Lambda’s Parameter List
- Lambdas with Empty Parameter Lists
- Method References
- 17.3.3 Intermediate and Terminal Operations
- Lazy and Eager Operations
- 17.4 Filtering
- 17.5 How Elements Move Through Stream Pipelines
- 17.6 Method References
- 17.6.1 Creating an IntStream of Random Values
- 17.6.2 Performing a Task on Each Stream Element with forEach and a Method Reference
- 17.6.3 Mapping Integers to String Objects with mapToObj
- 17.6.4 Concatenating Strings with collect
- 17.7 IntStream Operations
- 17.7.1 Creating an IntStream and Displaying Its Values
- 17.7.2 Terminal Operations count, min, max, sum and average
- 17.7.3 Terminal Operation reduce
- Calculating the Product of the Values with Method reduce
- Summing the Squares of the Values
- 17.7.4 Sorting IntStream Values
- 17.8 Functional Interfaces
- 17.9 Lambdas: A Deeper Look
- 17.10 Stream<Integer> Manipulations
- 17.10.1 Creating a Stream<Integer>
- 17.10.2 Sorting a Stream and Collecting the Results
- Creating a New Collection Containing a Stream Pipeline’s Results
- 17.10.3 Filtering a Stream and Storing the Results for Later Use
- 17.10.4 Filtering and Sorting a Stream and Collecting the Results
- 17.10.5 Sorting Previously Collected Results
- 17.11 Stream<String> Manipulations
- 17.11.1 Mapping Strings to Uppercase
- 17.11.2 Filtering Strings Then Sorting Them in Case-Insensitive Ascending Order
- 17.11.3 Filtering Strings Then Sorting Them in Case-Insensitive Descending Order
- 17.12 Stream<Employee> Manipulations
- 17.12.1 Creating and Displaying a List<Employee>
- Java SE 9: Creating an Immutable List<Employee> with List Method of
- 17.12.2 Filtering Employees with Salaries in a Specified Range
- Short-Circuit Stream Pipeline Processing
- 17.12.3 Sorting Employees By Multiple Fields
- Aside: Composing Lambda Expressions
- 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.9.1 Koch Curve Fractal
- 18.9.2 (Optional) Case Study: Lo Feather Fractal
- 18.9.3 (Optional) Fractal App GUI
- ToolBar and Its Additional Controls
- ColorPicker
- Event Handlers
- 18.9.4 (Optional) FractalController Class
- FractalController Fields
- initialize Method
- colorSelected Event Handler
- decreaseLevelButtonPressed and increaseLevelButtonPressed Event Handlers
- drawFractal Method with No Arguments
- drawFractal Method with Five Arguments
- 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
- Lambdas and Streams Exercises
- 19 Searching, Sorting and Big O
- Objectives
- Outline
- 19.1 Introduction
- 19.2 Linear Search
- 19.3 Big O Notation
- 19.3.1 O(1) Algorithms
- 19.3.2 O(n) Algorithms
- 19.3.3 O(n2) Algorithms
- 19.3.4 Big O of the Linear Search
- 19.4 Binary Search
- 19.4.1 Binary Search Implementation
- 19.4.2 Efficiency of the Binary Search
- 19.5 Sorting Algorithms
- 19.6 Selection Sort
- 19.6.1 Selection Sort Implementation
- Methods selectionSort and swap
- Methods printPass
- 19.6.2 Efficiency of the Selection Sort
- 19.7 Insertion Sort
- 19.7.1 Insertion Sort Implementation
- Method insertionSort
- Method printPass
- 19.7.2 Efficiency of the Insertion Sort
- 19.8 Merge Sort
- 19.8.1 Merge Sort Implementation
- Method mergeSort
- Recursive Method sortArray
- Method merge
- 19.8.2 Efficiency of the 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
- Section 19.1 Introduction
- Section 19.2 Linear Search
- Section 19.3 Big O Notation
- Section 19.4 Binary Search
- Section 19.6 Selection Sort
- Section 19.7 Insertion Sort
- Section 19.8 Merge Sort
- 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
- Section 21.1 Introduction
- Section 21.2 Self-Referential Classes
- Section 21.3 Dynamic Memory Allocation
- Section 21.4 Linked Lists
- Section 21.5 Stacks
- Section 21.6 Queues
- Section 21.7 Trees
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Special Section: Building Your Own Compiler
- First Pass
- Second Pass
- A Complete Example
- A Step-by-Step View of the Compilation Process
- 22 JavaFX Graphics and Multimedia
- Objectives
- Outline
- 22.1 Introduction
- 22.2 Controlling Fonts with Cascading Style Sheets (CSS)
- 22.2.1 CSS That Styles the GUI
- .vbox CSS Rule—Style Class Selectors
- #label1 CSS Rule—ID Selectors
- #label2 CSS Rule
- #label3 CSS Rule
- #label4 CSS Rule
- #label5 CSS Rule
- #label5 .text CSS Rule
- 22.2.2 FXML That Defines the GUI—Introduction to XML Markup2
- XML Declaration
- Attributes
- Comments
- FXML import Declarations
- Elements
- XML Namespaces
- 22.2.3 Referencing the CSS File from FXML
- 22.2.4 Specifying the VBox’s Style Class
- 22.2.5 Programmatically Loading CSS
- 22.3 Displaying Two-Dimensional Shapes
- 22.3.1 Defining Two-Dimensional Shapes with FXML
- Line Objects
- Rectangle Object
- Circle Object
- Ellipse Object
- Arc Object
- 22.3.2 CSS That Styles the Two-Dimensional Shapes
- Specifying Common Attributes for Various Objects
- Styling the Lines
- Styling the Rectangle
- Styling the Circle
- Styling the Ellipse
- Styling the Arc
- 22.4 Polylines, Polygons and Paths
- 22.4.1 GUI and CSS
- 22.4.2 PolyShapesController Class
- Method initialize
- Method drawingAreaMouseClicked
- Method shapeRadioButtonSelected
- Method displayShape
- Method clearButtonPressed
- 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.7.1 TransitionAnimations.fxml
- 22.7.2 TransitionAnimationsController Class
- FillTransition
- StrokeTransition
- ParallelTransition
- FadeTransition
- RotateTransition
- PathTransition
- ScaleTransition
- SequentialTransition
- 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, MediaPlayer 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
- Project Exercises
- 23 Concurrency
- Objectives
- Outline
- 23.1 Introduction
- 23.2 Thread States and Life Cycle
- 23.2.1 New and Runnable States
- 23.2.2 Waiting State
- 23.2.3 Timed Waiting State
- 23.2.4 Blocked State
- 23.2.5 Terminated State
- 23.2.6 Operating-System View of the Runnable State
- 23.2.7 Thread Priorities and Thread Scheduling
- 23.2.8 Indefinite Postponement and Deadlock
- 23.3 Creating and Executing Threads with the Executor Framework
- 23.4 Thread Synchronization
- 23.4.1 Immutable Data
- 23.4.2 Monitors
- 23.4.3 Unsynchronized Mutable Data Sharing
- Class SimpleArray
- Class ArrayWriter
- Class SharedArrayTest
- ExecutorService Method awaitTermination
- Sample Program Output
- 23.4.4 Synchronized Mutable Data Sharing—Making Operations Atomic
- Class SimpleArray with 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.11.1 Performing Computations in a Worker Thread: Fibonacci Numbers
- Creating a Task
- FibonacciNumbers GUI
- Class FibonacciNumbersController
- Method goButtonPressed
- Method nextNumberButtonPressed
- 23.11.2 Processing Intermediate Results: Sieve of Eratosthenes
- A Task to Find Prime Numbers
- Constructor
- Sieve of Eratosthenes
- Overridden Task Method call
- FindPrimes GUI
- Class FindPrimesController
- Method getPrimesButtonPressed
- Method cancelButtonPressed
- 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.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
- Parallel Streams
- Parallel Sorting and Searching Projects
- 24 Accessing Databases with JDBC
- Objectives
- Outline
- 24.1 Introduction
- 24.2 Relational Databases
- 24.3 A books Database
- 24.4 SQL
- 24.4.1 Basic SELECT Query
- 24.4.2 WHERE Clause
- Pattern Matching: Zero or More Characters
- Pattern Matching: Any Character
- 24.4.3 ORDER BY Clause
- Sorting in Descending Order
- Sorting By Multiple Columns
- Combining the WHERE and ORDER BY Clauses
- 24.4.4 Merging Data from Multiple Tables: INNER JOIN
- 24.4.5 INSERT Statement
- 24.4.6 UPDATE Statement
- 24.4.7 DELETE Statement
- 24.5 Setting Up a Java DB Database 1
- 24.5.1 Creating the Chapter’s Databases on Windows
- 24.5.2 Creating the Chapter’s Databases on macOS
- 24.5.3 Creating the Chapter’s Databases on Linux
- 24.6 Connecting to and Querying a Database
- 24.6.1 Automatic Driver Discovery
- 24.6.2 Connecting to the Database
- 24.6.3 Creating a Statement for Executing Queries
- 24.6.4 Executing a Query
- 24.6.5 Processing a Query’s ResultSet
- 24.7 Querying the books Database
- 24.7.1 ResultSetTableModel Class
- ResultSetTableModel Constructor
- ResultSetTableModel Method getColumnClass
- ResultSetTableModel Method getColumnCount
- ResultSetTableModel Method getColumnName
- ResultSetTableModel Method getRowCount
- ResultSetTableModel Method getValueAt
- ResultSetTableModel Method setQuery
- ResultSetTableModel Method disconnectFromDatabase
- 24.7.2 DisplayQueryResults App’s GUI
- 24.7.3 DisplayQueryResultsController Class
- static Fields
- Method initialize
- Method submitQueryButtonPressed
- Method applyFilterButtonPressed
- Method displayAlert
- 24.8 RowSet Interface
- 24.9 PreparedStatements
- 24.9.1 AddressBook App That Uses PreparedStatements
- 24.9.2 Class Person
- 24.9.3 Class PersonQueries
- Creating PreparedStatements
- PersonQueries Method getAllPeople
- PersonQueries Method getPeopleByLastName
- PersonQueries Methods addPerson and Close
- 24.9.4 AddressBook GUI
- 24.9.5 Class AddressBookController
- Instance Variables
- Method initialize
- Methods getAllEntries and selectFirstEntry
- Method displayContact
- Method addEntryButtonPressed
- Method findButtonPressed
- Method browseAllButtonPressed
- 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 Exercises
- 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
- Compilation Errors in JShell
- Fixing the Error
- Recalling and Re-executing a Previous Snippet
- 25.3.4 Listing and Executing Prior Snippets
- Executing Snippets By ID Number
- 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
- Editing a Single-Line Snippet
- Editing a Multiline Snippet
- Adding a New Snippet Via JShell Edit Pad
- Executing the New if Statement Again
- 25.3.11 Exiting JShell
- 25.4 Command-Line Input in JShell
- 25.5 Declaring and Using Classes
- 25.5.1 Creating a Class in JShell
- Viewing Declared Classes
- 25.5.2 Explicitly Declaring Reference-Type Variables
- 25.5.3 Creating Objects
- Declaring an Implicit Account Variable Initialized with an Account Object
- Viewing Declared Variables
- 25.5.4 Manipulating Objects
- Using the Return Value of a Method in a Statement
- 25.5.5 Creating a Meaningful Variable Name for an Expression
- 25.5.6 Saving and Opening Code-Snippet Files
- Saving Snippets to a File
- Loading Snippets from a File
- Using /open to Load Java Source-Code Files
- 25.6 Discovery with JShell Auto-Completion
- 25.6.1 Auto-Completing Identifiers
- 25.6.2 Auto-Completing JShell Commands
- 25.7 Exploring a Class’s Members and Viewing Documentation
- 25.7.1 Listing Class Math’s static Members
- 25.7.2 Viewing a Method’s Parameters
- 25.7.3 Viewing a Method’s Documentation
- 25.7.4 Viewing a public Field’s Documentation
- 25.7.5 Viewing a Class’s Documentation
- 25.7.6 Viewing Method Overloads
- 25.7.7 Exploring Members of a Specific Object
- Exploring toUpperCase
- Exploring substring
- 25.8 Declaring Methods
- 25.8.1 Forward Referencing an Undeclared Method—Declaring Method displayCubes
- 25.8.2 Declaring a Previously Undeclared Method
- 25.8.3 Testing cube and Replacing Its Declaration
- 25.8.4 Testing Updated Method cube and Method displayCubes
- 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.12.1 Getting Help in JShell
- 25.12.2 /edit Command: Additional Features
- 25.12.3 /reload Command
- 25.12.4 /drop Command
- 25.12.5 Feedback Modes
- Feedback Mode verbose
- Feedback Mode concise
- Feedback Mode silent
- 25.12.6 Other JShell Features Configurable with /set
- Customizing JShell Startup
- 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
- Notes
- E Using the Debugger
- Objectives
- Outline
- E.1 Introduction
- E.2 Breakpoints and the run, stop, cont and print Commands
- E.3 The print and set Commands
- E.4 Controlling Execution Using the step, step up and next Commands
- E.5 The watch Command
- E.6 The clear Command
- E.7 Wrap-Up
- Appendices on the Web
- Index
- Symbols
- Numerics
- A
- B
- C
- D
- E
- F
- G
- H
- I
- J
- K
- L
- M
- N
- O
- P
- Q
- R
- S
- T
- U
- V
- W
- X
- Y
- Z
- ADDITIONAL COMMENTS FROM RECENT EDITIONS REVIEWERS
- 26 Swing GUI Components: Part 1
- Objectives
- Outline
- 26.1 Introduction
- 26.2 Java’s Nimbus Look-and-Feel
- 26.3 Simple GUI-Based Input/Output with JOptionPane
- 26.4 Overview of Swing Components
- 26.5 Displaying Text and Images in a Window
- 26.6 Text Fields and an Introduction to Event Handling with Nested Classes
- 26.7 Common GUI Event Types and Listener Interfaces
- 26.8 How Event Handling Works
- 26.9 JButton
- 26.10 Buttons That Maintain State
- 26.10.1 JCheckBox
- Relationship Between an Inner Class and Its Top-Level Class
- 26.10.2 JRadioButton
- 26.11 JComboBox; Using an Anonymous Inner Class for Event Handling
- 26.12 JList
- 26.13 Multiple-Selection Lists
- 26.14 Mouse Event Handling
- 26.15 Adapter Classes
- 26.16 JPanel Subclass for Drawing with the Mouse
- 26.17 Key Event Handling
- 26.18 Introduction to Layout Managers
- 26.18.1 FlowLayout
- 26.18.2 BorderLayout
- 26.18.3 GridLayout
- 26.19 Using Panels to Manage More Complex Layouts
- 26.20 JTextArea
- 26.21 Wrap-Up
- Summary
- Section 26.1 Introduction
- Section 26.2 Java’s Nimbus Look-and-Feel
- Section 26.3 Simple GUI-Based Input/Output with JOptionPane
- Section 26.4 Overview of Swing Components
- Section 26.5 Displaying Text and Images in a Window
- Section 26.6 Text Fields and an Introduction to Event Handling with Nested Classes
- Section 26.7 Common GUI Event Types and Listener Interfaces
- Section 26.8 How Event Handling Works
- Section 26.9 JButton
- Section 26.10 Buttons That Maintain State
- Section 26.11 JComboBox; Using an Anonymous Inner Class for Event Handling
- Section 26.12 JList
- Section 26.13 Multiple-Selection Lists
- Section 26.14 Mouse Event Handling
- Section 26.15 Adapter Classes
- Section 26.16 JPanel Subclass for Drawing with the Mouse
- Section 26.17 Key Event Handling
- Section 26.18 Introduction to Layout Managers
- Section 26.19 Using Panels to Manage More Complex Layouts
- Section 26.20 JTextArea
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- (Optional) GUI and Graphics Case Study Exercise: Expanding the Interface
- Making a Difference
- 27 Graphics and Java 2D
- Objectives
- Outline
- 27.1 Introduction
- 27.2 Graphics Contexts and Graphics Objects
- 27.3 Color Control
- 27.4 Manipulating Fonts
- 27.5 Drawing Lines, Rectangles and Ovals
- 27.6 Drawing Arcs
- 27.7 Drawing Polygons and Polylines
- 27.8 Java 2D API
- 27.9 Wrap-Up
- Summary
- Section 27.1 Introduction
- Section 27.2 Graphics Contexts and Graphics Objects
- Section 27.3 Color Control
- Section 27.4 Manipulating Fonts
- Section 27.5 Drawing Lines, Rectangles and Ovals
- Section 27.6 Drawing Arcs
- Section 27.7 Drawing Polygons and Polylines
- Section 27.8 Java 2D API
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- (Optional) GUI and Graphics Case Study Exercise: Adding Java 2D
- Making a Difference
- 28 Networking
- Objectives
- Outline
- 28.1 Introduction1
- 28.2 Reading a File on a Web Server
- 28.3 Establishing a Simple Server Using Stream Sockets
- 28.4 Establishing a Simple Client Using Stream Sockets
- 28.5 Client/Server Interaction with Stream Socket Connections
- 28.6 Datagrams: Connectionless Client/Server Interaction
- 28.7 Client/Server Tic-Tac-Toe Using a Multithreaded Server
- 28.8 Optional Online Case Study: DeitelMessenger2
- 28.9 Wrap-Up
- Summary
- Section 28.1 Introduction
- Section 28.2 Reading a File on a Web Server
- Section 28.3 Establishing a Simple Server Using Stream Sockets
- Section 28.4 Establishing a Simple Client Using Stream Sockets
- Section 28.6 Datagrams: Connectionless Client/Server Interaction
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- 29 Java Persistence API (JPA)
- Objectives
- Outline
- 29.1 Introduction
- 29.2 JPA Technology Overview
- 29.2.1 Generated Entity Classes
- 29.2.2 Relationships Between Tables in the Entity Classes
- 29.2.3 The javax.persistence Package
- EntityManager Interface
- EntityManagerFactory Interface and the Persistence Class
- TypedQuery Class, Dynamic Queries and Named Queries
- 29.3 Querying a Database with JPA
- 29.3.1 Creating the Java DB Database
- Creating the Database
- 29.3.2 Populating the books Database with Sample Data
- 29.3.3 Creating the Java Project
- 29.3.4 Adding the JPA and Java DB Libraries
- EclipseLink—The JPA Reference Implementation
- Adding Libraries
- 29.3.5 Creating the Persistence Unit for the books Database
- 29.3.6 Querying the Authors Table
- Importing the JPA Interfaces and Class Used in This Example
- Creating the EntityManagerFactory Object
- Creating the EntityManager
- Creating a TypedQuery That Retrieves the Authors Table
- Displaying the Query Results
- 29.3.7 JPA Features of Autogenerated Class Authors
- JPA Annotations for Class Authors
- JPA Annotations for Class Authors’ Instance Variables
- 29.4 Named Queries; Accessing Data from Multiple Tables
- 29.4.1 Using a Named Query to Get the List of Authors, then Display the Authors with Their Titles
- Creating a TypedQuery That Retrieves the Authors Table
- Processing the Results
- 29.4.2 Using a Named Query to Get the List of Titles, then Display Each with Its Authors
- 29.5 Address Book: Using JPA and Transactions to Modify a Database
- 29.5.1 Transaction Processing
- 29.5.2 Creating the AddressBook Database, Project and Persistence Unit
- Step 1: Creating the addressbook Database
- Step 2: Populating the Database
- Step 3: Creating the AddressBook Project
- Step 4: Adding the JPA and Java DB Libraries
- Step 5: Creating the AddressBook Database’s Persistence Unit
- 29.5.3 Addresses Entity Class
- Ordering the Named Query Results
- ToString Method of Class Addresses
- 29.5.4 AddressBookController Class
- Obtaining the EntityManager
- Obtaining the Complete List of Contacts—Method getAllEntries
- Adding an Entry to the Database—Method addEntryButtonPressed
- Finding by Last Name—Method findButtonPressed
- 29.5.5 Other JPA Operations
- Updating an Existing Entity
- Deleting an Existing Entity
- 29.6 Web Resources
- 29.7 Wrap-Up
- 30 JavaServer™ Faces Web Apps: Part 1
- Objectives
- Outline
- 30.1 Introduction
- 30.2 HyperText Transfer Protocol (HTTP) Transactions
- 30.3 Multitier Application Architecture
- 30.4 Your First JSF Web App
- 30.4.1 The Default index.xhtml Document: Introducing Facelets
- Facelets: XHTML and JSF Markup
- XML Declaration, Comments and the DOCTYPE Declaration
- Specifying the XML Namespaces Used in the Document
- The h:head and h:body Elements
- 30.4.2 Examining the WebTimeBean Class
- JavaBeans
- Class WebTimeBean
- The @ManagedBean Annotation
- Processing the EL Expression
- 30.4.3 Building the WebTime JSF Web App in NetBeans
- Creating the JSF Web Application Project
- Examining the NetBeans Projects Window
- Examining the Default index.xhtml Page
- Editing the h:head Element’s Contents
- Editing the h:body Element’s Contents
- Defining the Page’s Logic: Class WebTimeBean
- Adding the EL Expression to the index.xhtml Page
- Running the Application
- Debugging the Application
- Testing the Application from Other Web Browsers
- 30.5 Model-View-Controller Architecture of JSF Apps
- 30.6 Common JSF Components
- 30.7 Validation Using JSF Standard Validators
- 30.8 Session Tracking
- 30.8.1 Cookies
- 30.8.2 Session Tracking with @SessionScoped Beans
- Test-Driving the App
- @SessionScoped Class SelectionsBean
- Methods of Class SelectionsBean
- index.xhtml
- recommendations.xhtml
- Iterating Through the List of Books
- 30.9 Wrap-Up
- Summary
- Section 30.1 Introduction
- Section 30.2 HyperText Transfer Protocol (HTTP) Transactions
- Section 30.3 Multitier Application Architecture
- Section 30.4 Your First JSF Web App
- Section 30.4.1 The Default index.xhtml Document: Introducing Facelets
- Section 30.4.2 Examining the WebTimeBean Class
- Section 30.5 Model-View-Controller Architecture of JSF Apps
- Section 30.6 Common JSF Components
- Section 30.7 Validation Using JSF Standard Validators
- Section 30.8 Session Tracking
- Section 30.8.1 Cookies
- Section 30.8.2 Session Tracking with @SessionScoped Beans
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- 31 JavaServer™ Faces Web Apps: Part 2
- Objectives
- Outline
- 31.1 Introduction
- 31.2 Accessing Databases in Web Apps
- 31.2.1 Setting Up the Database
- Open NetBeans and Ensure that Java DB and GlassFish Are Running
- Creating the Database
- Populate the addressbook Database with Sample Data
- 31.2.2 Class AddressBean
- Defining a Data Source with the Annotation @DataSourceDefinition
- Class AddressBean’s Annotations—@Named and @javax.faces.view.ViewScoped
- Injecting the DataSource into Class AddressBean
- AddressBean Method getAddresses
- AddressBean Method save
- 31.2.3 index.xhtml Facelets Page
- The h:dataTable Element
- The h:column Elements
- 31.2.4 addentry.xhtml Facelets Page
- 31.3 Ajax
- 31.4 Adding Ajax Functionality to the Validation App
- 31.5 Wrap-Up
- Summary
- Section 30.2.2 Class AddressBean
- Section 30.2.3 index.xhtml Facelets Page
- Section 30.2.4 addentry.xhtml Facelets Page
- Section 31.3 Ajax
- Section 31.4 Adding Ajax Functionality to the Validation App
- Self-Review Exercise
- Answers to Self-Review Exercise
- Exercises
- 32 REST Web Services
- Objectives
- Outline
- 32.1 Introduction
- 32.2 Web Service Basics
- 32.3 Simple Object Access Protocol (SOAP)
- 32.4 Representational State Transfer (REST)
- 32.5 JavaScript Object Notation (JSON)
- 32.6 Publishing and Consuming SOAP-Based Web Services
- 32.6.1 Creating a Web Application Project and Adding a Web Service Class in NetBeans
- Creating a Web Application Project in NetBeans
- Adding a Web Service Class to a Web Application Project
- 32.6.2 Defining the WelcomeSOAP Web Service in NetBeans
- Annotation import Declarations
- @WebService Annotation
- WelcomeSOAP Service’s welcome Method
- Completing the Web Service’s Code
- 32.6.3 Publishing the WelcomeSOAP Web Service from NetBeans
- 32.6.4 Testing the WelcomeSOAP Web Service with GlassFish Application Server’s Tester Web Page
- Application Server Note
- Testing the WelcomeSOAP Web Service from Another Computer
- 32.6.5 Describing a Web Service with the Web Service Description Language (WSDL)
- Accessing the WelcomeSOAP Web Service’s WSDL from Another Computer
- 32.6.6 Creating a Client to Consume the WelcomeSOAP Web Service
- Service Endpoint Interface (SEI)
- Creating a Desktop Application Project in NetBeans
- Step 2: Adding a Web Service Reference to an Application
- 32.6.7 Consuming the WelcomeSOAP Web Service
- 32.7 Publishing and Consuming REST-Based XML Web Services
- 32.7.1 Creating a REST-Based XML Web Service
- Testing the RESTful Web Service
- WADL
- 32.7.2 Consuming a REST-Based XML Web Service
- 32.8 Publishing and Consuming REST-Based JSON Web Services
- 32.8.1 Creating a REST-Based JSON Web Service
- 32.8.2 Consuming a REST-Based JSON Web Service
- 32.9 Session Tracking in a SOAP Web Service
- 32.9.1 Creating a Blackjack Web Service
- Session Tracking in Web Services: @HttpSessionScope Annotation
- Client Interactions with the Blackjack Web Service
- 32.9.2 Consuming the Blackjack Web Service
- Configuring the Client for Session Tracking
- Method gameOver
- Method dealJButtonActionPerformed
- Method hitJButtonActionPerformed
- Method dealerPlay
- Method standJButtonActionPerformed
- Method displayCard
- 32.10 Consuming a Database-Driven SOAP Web Service
- 32.10.1 Creating the Reservation Database
- Creating the Reservation Web Service
- 32.10.2 Creating a Web Application to Interact with the Reservation Service
- index.xhtml
- ReservationBean.java
- 32.11 Equation Generator: Returning User-Defined Types
- 32.11.1 Creating the EquationGeneratorXML Web Service
- 32.11.2 Consuming the EquationGeneratorXML Web Service
- 32.11.3 Creating the EquationGeneratorJSON Web Service
- 32.11.4 Consuming the EquationGeneratorJSON Web Service
- 32.12 Wrap-Up
- Summary
- Section 32.1 Introduction
- Section 32.2 Web Service Basics
- Section 32.3 Simple Object Access Protocol (SOAP)
- Section 32.4 Representational State Transfer (REST)
- Section 32.5 JavaScript Object Notation (JSON)
- Section 32.6.1 Creating a Web Application Project and Adding a Web Service Class in NetBeans
- Section 31.6.2 Defining the WelcomeSOAP Web Service in NetBeans
- Section 31.6.3 Publishing the WelcomeSOAP Web Service from NetBeans
- Section 31.6.4 Testing the WelcomeSOAP Web Service with GlassFish Application Server’s Tester Web Page
- Section 32.6.5 Describing a Web Service with the Web Service Description Language (WSDL)
- Section 31.6.6 Creating a Client to Consume the WelcomeSOAP Web Service
- Section 31.6.7 Consuming the WelcomeSOAP Web Service
- Section 32.7.1 Creating a REST-Based XML Web Service
- Section 32.7.2 Consuming a REST-Based XML Web Service
- Section 32.8 Publishing and Consuming REST-Based JSON Web Services
- Section 32.8.1 Creating a REST-Based JSON Web Service
- Section 32.8.2 Consuming a REST-Based JSON Web Service
- Section 32.9 Session Tracking in a SOAP Web Service
- Section 31.9.1 Creating a Blackjack Web Service
- Section 31.9.2 Consuming the Blackjack Web Service
- Section 32.11 Equation Generator: Returning User-Defined Types
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
- 33 ATM Case Study, Part 1: Object-Oriented Design with the UML
- Objectives
- Outline
- 33.1 Case Study Introduction
- 33.2 Examining the Requirements Document
- Self-Review Exercises for Section 33.2
- 33.3 Identifying the Classes in a Requirements Document
- Self-Review Exercises for Section 33.3
- 33.4 Identifying Class Attributes
- Self-Review Exercises for Section 33.4
- 33.5 Identifying Objects’ States and Activities
- Self-Review Exercises for Section 33.5
- 33.6 Identifying Class Operations
- Self-Review Exercises for Section 33.6
- 33.7 Indicating Collaboration Among Objects
- Self-Review Exercises for Section 33.7
- 33.8 Wrap-Up
- Answers to Self-Review Exercises
- 34 ATM Case Study Part 2: Implementing the Design
- Objectives
- Outline
- 34.1 Introduction
- 34.2 Starting to Program the Classes of the ATM System
- Self-Review Exercises for Section 34.2
- 34.3 Incorporating Inheritance and Polymorphism into the ATM System
- Self-Review Exercises for Section 34.3
- 34.4 ATM Case Study Implementation
- 34.4.1 Class ATM
- ATM Method run
- Authenticating a User
- Performing Transactions
- Creating a Transaction
- Exiting the Main Menu and Processing Invalid Selections
- Awaiting the Next ATM User
- 34.4.2 Class Screen
- 34.4.3 Class Keypad
- 34.4.4 Class CashDispenser
- 34.4.5 Class DepositSlot
- 34.4.6 Class Account
- 34.4.7 Class BankDatabase
- 34.4.8 Class Transaction
- 34.4.9 Class BalanceInquiry
- 34.4.10 Class Withdrawal
- 34.4.11 Class Deposit
- 34.4.12 Class ATMCaseStudy
- 34.5 Wrap-Up
- Answers to Self-Review Exercises
- 35 Swing GUI Components: Part 2
- Objectives
- Outline
- 35.1 Introduction
- Java SE 8: Implementing Event Listeners with Lambdas
- 35.2 JSlider
- 35.3 Understanding Windows in Java
- Returning Window Resources to the System
- Displaying and Positioning Windows
- Window Events
- 35.4 Using Menus with Frames
- Overview of Several Menu-Related Components
- Using Menus in an Application
- Setting Up the File Menu
- Setting Up the Format Menu
- Creating the Rest of the GUI and Defining the Event Handlers
- 35.5 JPopupMenu
- 35.6 Pluggable Look-and-Feel
- 35.7 JDesktopPane and JInternalFrame
- 35.8 JTabbedPane
- 35.9 BoxLayout Layout Manager
- Creating Box Containers
- Struts
- Glue
- Rigid Areas
- Setting a BoxLayout for a Container
- Adding Glue and JButtons
- Creating the JTabbedPane
- Attaching the Box Containers and JPanel to the JTabbedPane
- 35.10 GridBagLayout Layout Manager
- GridBagConstraints fields.
- GridBagConstraints Field anchor
- GridBagConstraints Field fill
- GridBagConstraints Fields gridx and gridy
- GridBagConstraints Field gridwidth
- GridBagConstraints Field weightx
- GridBagConstraints Field weighty
- Effects of weightx and weighty
- Demonstrating GridBagLayout
- GUI Overview
- JTextArea textArea1
- JButton button1
- JComboBox comboBox
- JButton button2
- JButton button3
- JTextField textField and JTextArea textArea2
- Method addComponent
- GridBagConstraints Constants RELATIVE and REMAINDER
- Setting the JFrame’s Layout to a GridBagLayout
- Configuring the JTextField
- Configuring JButton buttons[0]
- Configuring JButton buttons[1]
- Configuring JButton buttons[2]
- Configuring JComboBox
- Configuring JButton buttons[3]
- Configuring JButton buttons[4]
- Configuring JList
- 35.11 Wrap-Up
- Summary
- Section 22.2 JSlider
- Section 35.3 Understanding Windows in Java
- Section 35.4 Using Menus with Frames
- Section 22.5 JPopupMenu
- Section 35.6 Pluggable Look-and-Feel
- Section 22.7 JDesktopPane and JInternalFrame
- Section 22.8 JTabbedPane
- Section 22.9 BoxLayout Layout Manager
- Section 22.10 GridBagLayout Layout Manager
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- 36 Java Platform Module System
- Objectives
- Outline
- 36.1 Introduction1
- 36.2 Module Declarations
- 36.2.1 requires
- 36.2.2 requires transitive—Implied Readability
- 36.2.3 exports and exports…to
- 36.2.4 uses
- 36.2.5 provides…with
- 36.2.6 open, opens and opens…to10,11
- Allowing Runtime-Only Access to a Package
- Allowing Runtime-Only Access to a Package By Specific Modules
- Allowing Runtime-Only Access to All Packages in a Module
- Reflection Defaults
- Dependency Injection
- 36.2.7 Restricted Keywords
- 36.3 Modularized Welcome App
- 36.3.1 Welcome App’s Structure
- Module Naming Conventions
- Listing the java.base Module’s Contents
- 36.3.2 Class Welcome
- 36.3.3 module-info.java
- 36.3.4 Module-Dependency Graph
- 36.3.5 Compiling a Module
- Note Regarding Lengthy Commands in This Chapter
- Welcome App’s Folder Structure After Compilation
- Listing the com.deitel.welcome Module’s Contents
- 36.3.6 Running an App from a Module’s Exploded Folders
- 36.3.7 Packaging a Module into a Modular JAR File
- 36.3.8 Running the Welcome App from a Modular JAR File
- 36.3.9 Aside: Classpath vs. Module Path
- 36.4 Creating and Using a Custom Module
- 36.4.1 Exporting a Package for Use in Other Modules
- com.deitel.timelibrary Module Declaration
- 36.4.2 Using a Class from a Package in Another Module
- com.deitel.timetest Module Declaration
- com.deitel.timetest Module-dependency Graph
- 36.4.3 Compiling and Running the Example
- Compiling Module com.deitel.timelibrary
- Compiling Module com.deitel.timetest
- Running the Example
- 36.4.4 Packaging the App into Modular JAR Files
- Running the App from a Modular JAR File
- 36.4.5 Strong Encapsulation and Accessibility
- Compilation Error When Attempting to Use an Inaccessible Type
- 36.5 Module-Dependency Graphs: A Deeper Look
- 36.5.1 java.sql
- 36.5.2 java.se
- 36.5.3 Browsing the JDK Module Graph
- 36.5.4 Error: Module Graph with a Cycle
- A Module That (Incorrectly) Requires Itself
- Two Modules That (Incorrectly) Require One Another
- Modules in a Cycle Are Really “One Thing”
- 36.6 Migrating Code to Java 9
- 36.6.1 Unnamed Module
- 36.6.2 Automatic Modules
- 36.6.3 jdeps: Java Dependency Analysis
- Determining the Modules You Need
- Verbose jdeps Output
- Using jdeps to Produce DOT Files for Graphing Tools
- Additional jdeps Options
- 36.7 Resources in Modules; Using an Automatic Module
- 36.7.1 Automatic Modules
- Code Changes for Modularization
- 36.7.2 Requiring Multiple Modules
- 36.7.3 Opening a Module for Reflection
- 36.7.4 Module-Dependency Graph
- 36.7.5 Compiling the Module
- Copying the Resource Files into the Module
- 36.7.6 Running a Modularized App
- 36.8 Creating Custom Runtimes with jlink
- 36.8.1 Listing the JRE’s Modules
- 36.8.2 Custom Runtime Containing Only java.base
- Note Regarding the JAVA_HOME Variable
- Executing the Welcome App Using This Custom Runtime
- Listing the Modules in a Custom Runtime
- 36.8.3 Creating a Custom Runtime for the Welcome App
- 36.8.4 Executing the Welcome App Using a Custom Runtime
- 36.8.5 Using the Module Resolver on a Custom Runtime
- 36.9 Services and ServiceLoader
- 36.9.1 Service-Provider Interface
- 36.9.2 Loading and Consuming Service Providers
- Using ServiceLoader to Locate Service Providers
- Using a Service-Provider Interface
- 36.9.3 uses Module Directive and Service Consumers
- 36.9.4 Running the App with No Service Providers
- 36.9.5 Implementing a Service Provider
- 36.9.6 provides…with Module Directive and Declaring a Service Provider
- 36.9.7 Running the App with One Service Provider
- 36.9.8 Implementing a Second Service Provider
- 36.9.9 Running the App with Two Service Providers
- 36.10 Wrap-Up
- 37 Additional Java 9 Topics
- Objectives
- Outline
- 37.1 Introduction
- 37.2 Recap: Java 9 Features Covered in Earlier Chapters
- 37.3 New Version String Format
- 37.4 Regular Expressions: New Matcher Class Methods
- 37.4.1 Methods appendReplacement and appendTail
- 37.4.2 Methods replaceFirst and replaceAll
- 37.4.3 Method results
- 37.5 New Stream Interface Methods
- 37.5.1 Stream Methods takeWhile and dropWhile
- 37.5.2 Stream Method iterate
- 37.5.3 Stream Method ofNullable
- 37.6 Modules in JShell
- Adding a Module to the JShell Session
- Importing a Class from a Module’s Exported Package(s)
- Using the Imported Class
- 37.7 JavaFX 9 Skin APIs
- 37.8 Other GUI and Graphics Enhancements
- 37.8.1 Multi-Resolution Images
- 37.8.2 TIFF Image I/O
- 37.8.3 Platform-Specific Desktop Features
- 37.9 Security Related Java 9 Topics
- 37.9.1 Filter Incoming Serialization Data
- 37.9.2 Create PKCS12 Keystores by Default
- 37.9.3 Datagram Transport Layer Security (DTLS)
- 37.9.4 OCSP Stapling for TLS
- 37.9.5 TLS Application-Layer Protocol Negotiation Extension
- 37.10 Other Java 9 Topics
- 37.10.1 Indify String Concatenation
- 37.10.2 Platform Logging API and Service
- 37.10.3 Process API Updates
- 37.10.4 Spin-Wait Hints
- 37.10.5 UTF-8 Property Resource Bundles
- 37.10.6 Use CLDR Locale Data by Default
- 37.10.7 Elide Deprecation Warnings on Import Statements
- 37.10.8 Multi-Release JAR Files
- 37.10.9 Unicode 8
- 37.10.10 Concurrency Enhancements
- New Methods of Class CompletableFuture
- 37.11 Items Removed from the JDK and Java 9
- Removed Platform Features
- Removed Methods
- 37.12 Items Proposed for Removal from Future Java Versions
- 37.12.1 Enhanced Deprecation
- 37.12.2 Items Likely to Be Removed in Future Java Versions
- 37.12.3 Finding Deprecated Features
- 37.12.4 Java Applets
- 37.13 Wrap-Up
- F Using the Java API Documentation
- F.1 Introduction
- F.2 Navigating the Java API
- G Creating Documentation with javadoc
- G.1 Introduction
- G.2 Documentation Comments
- G.3 Documenting Java Source Code
- G.4 javadoc
- Downloading the Java Documentation
- Executing javadoc from the Command Line
- G.5 Files Produced by javadoc
- H Unicode®
- H.1 Introduction
- H.2 Unicode Transformation Formats
- H.3 Characters and Glyphs
- H.4 Advantages/Disadvantages of Unicode
- H.5 Using Unicode
- H.6 Character Ranges
- I Formatted Output
- Objectives
- Outline
- I.1 Introduction
- I.2 Streams
- I.3 Formatting Output with printf
- I.4 Printing Integers
- I.5 Printing Floating-Point Numbers
- I.6 Printing Strings and Characters
- I.7 Printing Dates and Times
- I.8 Other Conversion Characters
- I.9 Printing with Field Widths and Precisions
- I.10 Using Flags in the printf Format String
- I.11 Printing with Argument Indices
- I.12 Printing Literals and Escape Sequences
- I.13 Formatting Output with Class Formatter
- I.14 Wrap-Up
- J Number Systems
- Objectives
- Outline
- J.1 Introduction
- J.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
- J.3 Converting Octal and Hexadecimal Numbers to Binary Numbers
- J.4 Converting from Binary, Octal or Hexadecimal to Decimal
- J.5 Converting from Decimal to Binary, Octal or Hexadecimal
- J.6 Negative Binary Numbers: Two’s Complement Notation
- K Bit Manipulation
- K.1 Introduction
- K.2 Bit Manipulation and the Bitwise Operators
- K.3 BitSet Class
- L Labeled break and continue Statements
- L.1 Introduction
- L.2 Labeled break Statement
- L.3 Labeled continue Statement
- M UML 2: Additional Diagram Types
- M.1 Introduction
- M.2 Additional Diagram Types
- N Design Patterns
- N.1 Introduction
- History of Object-Oriented Design Patterns
- N.2 Creational, Structural and Behavioral Design Patterns
- N.2.1 Creational Design Patterns
- Singleton
- N.2.2 Structural Design Patterns
- Proxy
- N.2.3 Behavioral Design Patterns
- Memento
- State
- N.2.4 Conclusion
- N.3 Design Patterns in Packages java.awt and javax.swing
- N.3.1 Creational Design Patterns
- Factory Method
- N.3.2 Structural Design Patterns
- Adapter
- Bridge
- Composite
- N.3.3 Behavioral Design Patterns
- Chain of Responsibility
- Command
- Observer
- Strategy
- Template Method
- N.3.4 Conclusion
- N.4 Concurrency Design Patterns
- Concurrency Design Patterns
- N.5 Design Patterns Used in Packages java.io and java.net
- N.5.1 Creational Design Patterns
- Abstract Factory
- N.5.2 Structural Design Patterns
- Decorator
- Facade
- N.5.3 Architectural Patterns
- MVC
- Layers
- N.5.4 Conclusion
- N.6 Design Patterns Used in Package java.util
- N.6.1 Creational Design Patterns
- Prototype
- N.6.2 Behavioral Design Patterns
- Iterator
- N.7 Wrap-Up