Book description
Java How to Program (Early Objects), Tenth Editionis intended for use in the Java programming course. It also serves as a useful reference and self-study tutorial to Java programming.
The Deitels’ groundbreaking How to
Program series offers unparalleled breadth and depth of
object-oriented programming concepts and intermediate-level topics
for further study. Java How to Program (Early Objects),
Tenth Edition, teaches programming by presenting the concepts
in the context of full working programs and takes an early-objects
approach
MyProgrammingLab forJava How to Program (Early Objects) is a total learning package. MyProgrammingLab is an online homework, tutorial, and assessment program that truly engages students in learning. It helps students better prepare for class, quizzes, and exams—resulting in better performance in the course—and provides educators a dynamic set of tools for gauging individual and class progress.
Teaching and Learning Experience
This program presents a better teaching and learning experience—for you and your students.
Personalize Learning with MyProgrammingLab: Through the power of practice and immediate personalized feedback, MyProgrammingLab helps students fully grasp the logic, semantics, and syntax of programming.
Teach Programming with the Deitels’ Signature Live Code Approach: Java language features are introduced with thousands of lines of code in hundreds of complete working programs.
Introduce Objects Early: Presenting objects and classes early gets students “thinking about objects” immediately and mastering these concepts more thoroughly.
Keep Your Course Current: This edition can be used with Java SE 7 or Java SE 8, and is up-to-date with the latest technologies and advancements.
Facilitate Learning with Outstanding Applied Pedagogy: Making a Difference exercise sets, projects, and hundreds of valuable programming tips help students apply concepts.
Support Instructors and Students: Student and instructor resources are available to expand on the topics presented in the text.
Note: ISBN-10: 0133813436 / ISBN-13: 9780133813432 Java How to Program, Early Objects Plus MyProgrammingLab with Pearson eText -- Access Card Package, 10/e. This package consists of:
ISBN-10: 0133807800 / ISBN-13: 9780133807806 Java How to Program, Early Objects, 10/e
ISBN-10: 0133811905 / ISBN-13: 9780133811902 MyProgrammingLab with Pearson eText -- Access Card -- for Java How to Program, Early Objects
ALERT: Before you purchase, check with your instructor or review your course syllabus to ensure that you select the correct ISBN. Several versions of Pearson's MyLab & Mastering products exist for each title, including customized versions for individual schools, and registrations are not transferable. In addition, you may need a CourseID, provided by your instructor, to register for and use Pearson's MyLab & Mastering products.
Packages
Access codes for Pearson's MyLab & Mastering products may not be included when purchasing or renting from companies other than Pearson; check with the seller before completing your purchase.
Used or rental books
If you rent or purchase a used book with an access code, the access code may have been redeemed previously and you may have to purchase a new access code.
Access codes
Access codes that are purchased from sellers other than Pearson carry a higher risk of being either the wrong ISBN or a previously redeemed code. Check with the seller prior to purchase.
Table of contents
- About This eBook
- Title Page
- Copyright Page
- Deitel® Series Page
- Dedication Page
- Contents
- Foreword
-
Preface
- Keeping in Touch with the Authors
- Source Code and VideoNotes
-
Modular Organization
- Introduction
- Additional Programming Fundamentals
- Object-Oriented Programming and Object-Oriented Design
- Swing Graphical User Interfaces and Java 2D Graphics
- Data Structures, Collections, Lambdas and Streams
- Concurrency; Networking
- JavaFX Graphical User Interfaces, Graphics and Multimedia
- Database-Driven Desktop and Web Development
- New and Updated Features
- Secure Java Programming
- Optional GUI and Graphics Case Study
- Teaching Approach
- Software Used in Java How to Program, 10/e
- Instructor Supplements
- Acknowledgments
- A Special Thank You to Brian Goetz
- About the Authors
- About Deitel® & Associates, Inc.
-
Before You Begin
- Font and Naming Conventions
- Software Used in the Book
- JDK Installation Instructions
- Setting the PATH Environment Variable
- Setting the CLASSPATH Environment Variable
- Setting the JAVA_HOME Environment Variable
- Java Integrated Development Environments (IDEs)
- Obtaining the Code Examples
- Java’s Nimbus Look-and-Feel
-
1. Introduction to Computers, the Internet and Java
- 1.1 Introduction
- 1.2 Hardware and Software
- 1.3 Data Hierarchy
- 1.4 Machine Languages, Assembly Languages and High-Level Languages
-
1.5 Introduction to Object Technology
- 1.5.1 The 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 Keeping Up-to-Date with Information Technologies
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
2. Introduction to Java Applications; Input/Output and Operators
- 2.1 Introduction
-
2.2 Your First Program in Java: Printing a Line of Text
- Commenting Your Programs
- Using Blank Lines
- Declaring a Class
- Filename for a public Class
- Class Names and Identifiers
- Class Body
- Declaring a Method
- Performing Output with System.out.println
- Using End-of-Line Comments on Right Braces for Readability
- Compiling Your First Java Application
- Executing the Welcome1 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 Class Addition
- 2.5.3 Declaring and Creating a Scanner to Obtain User Input from the Keyboard
- 2.5.4 Declaring Variables to Store Integers
- 2.5.5 Prompting the User for Input
- 2.5.6 Obtaining an int as Input from the User
- 2.5.7 Prompting for and Inputting a Second int
- 2.5.8 Using Variables in a Calculation
- 2.5.9 Displaying the Result of the Calculation
- 2.5.10 Java API Documentation
- 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 Another Application: Adding Integers
- 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
- 3.1 Introduction
-
3.2 Instance Variables, set Methods and get Methods
- 3.2.1 Account Class with an Instance Variable, a set Method and a get Method
- 3.2.2 AccountTest Class That Creates and Uses an Object of Class Account
- 3.2.3 Compiling and Executing an App with Multiple Classes
- 3.2.4 Account UML Class Diagram with an Instance Variable and set and get Methods
- 3.2.5 Additional Notes on Class AccountTest
- 3.2.6 Software Engineering with private Instance Variables and public set and get Methods
- 3.3 Primitive Types vs. Reference Types
- 3.4 Account Class: Initializing Objects with Constructors
- 3.5 Account Class with a Balance; Floating-Point Numbers
- 3.6 (Optional) GUI and Graphics Case Study: Using Dialog Boxes
- 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 Primitive Types vs. Reference Types
- Section 3.4 Account Class: Initializing Objects with Constructors
- Section 3.5 Account Class with a Balance; Floating-Point Numbers and Type double
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
4. Control Statements: Part 1; Assignment, ++ and -- Operators
- 4.1 Introduction
- 4.2 Algorithms
- 4.3 Pseudocode
- 4.4 Control Structures
- 4.5 if Single-Selection Statement
- 4.6 if...else Double-Selection Statement
- 4.7 Student Class: Nested if...else Statements
- 4.8 while Repetition Statement
-
4.9 Formulating Algorithms: Counter-Controlled Repetition
- Pseudocode Algorithm with Counter-Controlled Repetition
- Implementing Counter-Controlled Repetition
- Local Variables in Method main
- Initialization Phase: Initializing Variables total and gradeCounter
- Processing Phase: Reading 10 Grades from the User
- Termination Phase: Calculating and Displaying the Class Average
- Notes on Integer Division and Truncation
- A Note About Arithmetic Overflow
- A Deeper Look at Receiving User Input
-
4.10 Formulating Algorithms: Sentinel-Controlled Repetition
- Developing the Pseudocode Algorithm with Top-Down, Stepwise Refinement: The Top and First Refinement
- Proceeding to the Second Refinement
- Implementing Sentinel-Controlled Repetition
- Program Logic for Sentinel-Controlled Repetition vs. Counter-Controlled Repetition
- Braces in a while statement
- Explicitly and Implicitly Converting Between Primitive Types
- Floating-Point Number Precision
- 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: Creating Simple Drawings
- 4.16 Wrap-Up
-
Summary
- Section 4.1 Introduction
- Section 4.2 Algorithms
- Section 4.3 Pseudocode
- Section 4.4 Control Structures
- Section 4.5 if Single-Selection Statement
- Section 4.6 if...else Double-Selection Statement
- Section 4.8 while Repetition Statement
- Section 4.9 Formulating Algorithms: Counter-Controlled Repetition
- Section 4.10 Formulating Algorithms: Sentinel-Controlled Repetition
- 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
- 5.1 Introduction
- 5.2 Essentials of Counter-Controlled Repetition
-
5.3 for Repetition Statement
- A Closer Look at the for Statement’s Header
- General Format of a for Statement
- Representing a for Statement with an Equivalent while Statement
- Scope of a for Statement’s Control Variable
- Expressions in a for Statement’s Header Are Optional
- Placing Arithmetic Expressions in a for Statement’s Header
- Using a for Statement’s Control Variable in the Statement’s Body
- UML Activity Diagram for the for Statement
-
5.4 Examples Using the for Statement
- Application: Summing the Even Integers from 2 to 20
- 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 Repetition Statement
- 5.6 switch Multiple-Selection Statement
- 5.7 Class AutoPolicy Case Study: Strings in switch Statements
- 5.8 break and continue Statements
-
5.9 Logical Operators
- Conditional AND (&&) Operator
- Conditional OR (||) Operator
- Short-Circuit Evaluation of Complex Conditions
- Boolean Logical AND (&) and Boolean Logical Inclusive OR (|) Operators
- Boolean Logical Exclusive OR (^)
- Logical Negation (!) Operator
- 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 Repetition
- Section 5.3 for Repetition Statement
- Section 5.4 Examples Using the for Statement
- Section 5.5 do...while Repetition Statement
- Section 5.6 switch Multiple-Selection Statement
- Section 5.7 Class AutoPolicy Case Study: Strings in switch Statements
- Section 5.8 break and continue Statements
- Section 5.9 Logical Operators
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
6. Methods: A Deeper Look
- 6.1 Introduction
- 6.2 Program Modules in Java
- 6.3 static Methods, static Fields and Class Math
- 6.4 Declaring Methods with Multiple Parameters
- 6.5 Notes on Declaring and Using Methods
- 6.6 Method-Call Stack and Stack Frames
- 6.7 Argument Promotion and Casting
- 6.8 Java API Packages
-
6.9 Case Study: Secure Random-Number Generation
- Moving to Secure Random Numbers
- Creating a SecureRandom Object
- Obtaining a Random int Value
- Changing the Range of Values Produced By nextInt
- Rolling a Six-Sided Die
- Rolling a Six-Sided Die 20 Times
- Rolling a Six-Sided Die 6,000,000 Times
- Generalized Scaling and Shifting of Random Numbers
- A Note About Performance
- 6.10 Case Study: A Game of Chance; Introducing enum Types
- 6.11 Scope of Declarations
- 6.12 Method Overloading
- 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 Modules in Java
- Section 6.3 static Methods, static Fields and Class Math
- Section 6.4 Declaring Methods with Multiple Parameters
- Section 6.5 Notes on Declaring and Using Methods
- Section 6.6 Method-Call Stack and Stack Frames
- 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
- 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
- 7.5 Exception Handling: Processing the Incorrect Response
- 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.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
- 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 Exercise
- Answers to Self-Review Exercise
- Exercises
- Making a Difference
-
9. Object-Oriented Programming: Inheritance
- 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 (Optional) GUI and Graphics Case Study: Displaying Text and Images Using Labels
- 9.8 Wrap-Up
- Summary
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
10. Object-Oriented Programming: Polymorphism and Interfaces
- 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
- Standardizing Interactions
- Software Objects Communicate Via Interfaces
- Using an Interface
- Relating Disparate Types
- Interfaces vs. Abstract Classes
- Tagging Interfaces
- 10.9.1 Developing a Payable Hierarchy
- 10.9.2 Interface Payable
- 10.9.3 Class Invoice
- 10.9.4 Modifying Class Employee to Implement Interface Payable
- 10.9.5 Modifying Class SalariedEmployee for Use in the Payable Hierarchy
- 10.9.6 Using Interface Payable to Process Invoices and Employees Polymorphically
- 10.9.7 Some Common Interfaces of the Java API
- 10.10 Java SE 8 Interface Enhancements
- 10.11 (Optional) GUI and Graphics Case Study: Drawing with Polymorphism
- 10.12 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.7 final Methods and Classes
- Section 10.9 Creating and Using Interfaces
- Section 10.10 Java SE 8 Interface Enhancements
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
11. Exception Handling: A Deeper Look
- 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 Object
- 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 Object
- 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. GUI Components: Part 1
- 12.1 Introduction
- 12.2 Java’s Nimbus Look-and-Feel
- 12.3 Simple GUI-Based Input/Output with JOptionPane
- 12.4 Overview of Swing Components
- 12.5 Displaying Text and Images in a Window
-
12.6 Text Fields and an Introduction to Event Handling with Nested Classes
- Creating the GUI
- Steps Required to Set Up Event Handling for a GUI Component
- Using a Nested Class to Implement an Event Handler
- Inner Class TextFieldHandler
- Registering the Event Handler for Each Text Field
- Details of Class TextFieldHandler’s actionPerformed Method
- Class TextFieldTest
- Java SE 8: Implementing Event Listeners with Lambdas
- 12.7 Common GUI Event Types and Listener Interfaces
- 12.8 How Event Handling Works
- 12.9 JButton
- 12.10 Buttons That Maintain State
- 12.11 JComboBox; Using an Anonymous Inner Class for Event Handling
- 12.12 JList
- 12.13 Multiple-Selection Lists
- 12.14 Mouse Event Handling
- 12.15 Adapter Classes
- 12.16 JPanel Subclass for Drawing with the Mouse
- 12.17 Key Event Handling
- 12.18 Introduction to Layout Managers
- 12.19 Using Panels to Manage More Complex Layouts
- 12.20 JTextArea
- 12.21 Wrap-Up
-
Summary
- Section 12.1 Introduction
- Section 12.2 Java’s Nimbus Look-and-Feel
- Section 12.3 Simple GUI-Based Input/Output with JOptionPane
- Section 12.4 Overview of Swing Components
- Section 12.5 Displaying Text and Images in a Window
- Section 12.6 Text Fields and an Introduction to Event Handling with Nested Classes
- Section 12.7 Common GUI Event Types and Listener Interfaces
- Section 12.8 How Event Handling Works
- Section 12.9 JButton
- Section 12.10 Buttons That Maintain State
- Section 12.11 JComboBox; Using an Anonymous Inner Class for Event Handling
- Section 12.12 JList
- Section 12.13 Multiple-Selection Lists
- Section 12.14 Mouse Event Handling
- Section 12.15 Adapter Classes
- Section 12.16 JPanel Subclass for Drawing with the Mouse
- Section 12.17 Key Event Handling
- Section 12.18 Introduction to Layout Managers
- Section 12.19 Using Panels to Manage More Complex Layouts
- Section 12.20 JTextArea
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
13. Graphics and Java 2D
- 13.1 Introduction
- 13.2 Graphics Contexts and Graphics Objects
- 13.3 Color Control
- 13.4 Manipulating Fonts
- 13.5 Drawing Lines, Rectangles and Ovals
- 13.6 Drawing Arcs
- 13.7 Drawing Polygons and Polylines
- 13.8 Java 2D API
- 13.9 Wrap-Up
- Summary
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
14. Strings, Characters and Regular Expressions
- 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
- Special Section: Advanced String-Manipulation Exercises
- Special Section: Challenging String-Manipulation Projects
- Making a Difference
-
15. Files, Streams and Object Serialization
- 15.1 Introduction
- 15.2 Files and Streams
- 15.3 Using NIO Classes and Interfaces to Get File and Directory Information
- 15.4 Sequential-Access Text Files
- 15.5 Object Serialization
- 15.6 Opening Files with JFileChooser
- 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-Access Text Files
- Section 15.5 Object Serialization
- Section 15.6 Opening Files with JFileChooser
- Section 15.7 (Optional) Additional java.io Classes
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
-
16. Generic Collections
- 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 Stack Class of Package java.util
- 16.9 Class PriorityQueue and Interface Queue
- 16.10 Sets
- 16.11 Maps
- 16.12 Properties Class
- 16.13 Synchronized Collections
- 16.14 Unmodifiable Collections
- 16.15 Abstract Implementations
- 16.16 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 Stack Class of Package java.util
- Section 16.9 Class PriorityQueue and Interface Queue
- Section 16.10 Sets
- Section 16.11 Maps
- Section 16.12 Properties Class
- Section 16.13 Synchronized Collections
- Section 16.14 Unmodifiable Collections
- Section 16.15 Abstract Implementations
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
17. Java SE 8 Lambdas and Streams
- 17.1 Introduction
- 17.2 Functional Programming Technologies Overview
-
17.3 IntStream Operations
- 17.3.1 Creating an IntStream and Displaying Its Values with the forEach Terminal Operation
- 17.3.2 Terminal Operations count, min, max, sum and average
- 17.3.3 Terminal Operation reduce
- 17.3.4 Intermediate Operations: Filtering and Sorting IntStream Values
- 17.3.5 Intermediate Operation: Mapping
- 17.3.6 Creating Streams of ints with IntStream Methods range and rangeClosed
- 17.4 Stream<Integer> Manipulations
- 17.5 Stream<String> Manipulations
-
17.6 Stream<Employee> Manipulations
- 17.6.1 Creating and Displaying a List<Employee>
- 17.6.2 Filtering Employees with Salaries in a Specified Range
- 17.6.3 Sorting Employees By Multiple Fields
- 17.6.4 Mapping Employees to Unique Last Name Strings
- 17.6.5 Grouping Employees By Department
- 17.6.6 Counting the Number of Employees in Each Department
- 17.6.7 Summing and Averaging Employee Salaries
- 17.7 Creating a Stream<String> from a File
- 17.8 Generating Streams of Random Values
- 17.9 Lambda Event Handlers
- 17.10 Additional Notes on Java SE 8 Interfaces
- 17.11 Java SE 8 and Functional Programming Resources
- 17.12 Wrap-Up
-
Summary
- Section 17.1 Introduction
- Section 17.2 Functional Programming Technologies Overview
- Section 17.2.1 Functional Interfaces
- Section 17.2.2 Lambda Expressions
- Section 17.2.3 Streams
- Section 17.3 IntStream Operations
- Section 17.3.1 Creating an IntStream and Displaying Its Values with the forEach Terminal Operation
- Section 17.3.2 Terminal Operations count, min, max, sum and average
- Section 17.3.3 Terminal Operation reduce
- Section 17.3.4 Intermediate Operations: Filtering and Sorting IntStream Values
- Section 17.3.5 Intermediate Operation: Mapping
- Section 17.3.6 Creating Streams of ints with IntStream Methods range and rangeClosed
- Section 17.4 Stream<Integer> Manipulations
- Section 17.4.1 Creating a Stream<Integer>
- Section 17.4.2 Sorting a Stream and Collecting the Results
- Section 17.4.3 Filtering a Stream and Storing the Results for Later Use
- Section 17.4.5 Sorting Previously Collected Results
- Section 17.5.1 Mapping Strings to Uppercase Using a Method Reference
- Section 17.5.2 Filtering Strings Then Sorting Them in Case-Insensitive Ascending Order
- Section 17.5.3 Filtering Strings Then Sorting Them in Case-Insensitive Descending Order
- Section 17.6.1 Creating and Displaying a List<Employee>
- Section 17.6.2 Filtering Employees with Salaries in a Specified Range
- Section 17.6.3 Sorting Employees By Multiple Fields
- Section 17.6.4 Mapping Employees to Unique Last Name Strings
- Section 17.6.5 Grouping Employees By Department
- Section 17.6.6 Counting the Number of Employees in Each Department
- Section 17.6.7 Summing and Averaging Employee Salaries
- Section 17.7 Creating a Stream<String> from a File
- Section 17.8 Generating Streams of Random Values
- Section 17.9 Lambda Event Handlers
- Section 17.10 Additional Notes on Java SE 8 Interfaces
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
18. Recursion
- 18.1 Introduction
- 18.2 Recursion Concepts
- 18.3 Example Using Recursion: Factorials
- 18.4 Reimplementing Class FactorialCalculator Using Class 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
- 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 Wrap-Up
- Summary
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
20. Generic Classes and Methods
- 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 Raw Types
- 20.8 Wildcards in Methods That Accept Type Parameters
- 20.9 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 Raw Types
- Section 20.8 Wildcards in Methods That Accept Type Parameters
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
21. Custom Generic Data Structures
- 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
- 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. GUI Components: Part 2
- 22.1 Introduction
- 22.2 JSlider
- 22.3 Understanding Windows in Java
- 22.4 Using Menus with Frames
- 22.5 JPopupMenu
- 22.6 Pluggable Look-and-Feel
- 22.7 JDesktopPane and JInternalFrame
- 22.8 JTabbedPane
- 22.9 BoxLayout Layout Manager
-
22.10 GridBagLayout Layout Manager
- GridBagConstraints
- 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
- 22.11 Wrap-Up
-
Summary
- Section 22.2 JSlider
- Section 22.3 Understanding Windows in Java
- Section 22.4 Using Menus with Frames
- Section 22.5 JPopupMenu
- Section 22.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
-
23. Concurrency
- 23.1 Introduction
- 23.2 Thread States and Life Cycle
-
23.3 Creating and Executing Threads with the Executor Framework
- Creating Concurrent Tasks with the Runnable Interface
- Executing Runnable Objects with an Executor
- Using Class Executors to Obtain an ExecutorService
- Implementing the Runnable Interface
- Let the Thread Handle InterruptedExceptions
- Using the ExecutorService to Manage Threads that Execute PrintTasks
- Main Thread
- Sample Outputs
- Waiting for Previously Scheduled Tasks to Terminate
- 23.4 Thread Synchronization
-
23.5 Producer/Consumer Relationship without Synchronization
- Examples of Producer/Consumer Relationship
- Synchronization and State Dependence
- Logic Errors from Lack of Synchronization
- Interface Buffer
- Class Producer
- Class Consumer
- We Call Thread Method sleep Only for Demonstration Purposes
- Class UnsynchronizedBuffer Does Not Synchronize Access to the Buffer
- Class SharedBufferTest
- 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 with GUI: SwingWorker
- 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.11 Multithreading with GUI: SwingWorker
- Section 23.12 Timing sort and parallelSort 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
- Answers to Self-Review Exercises
- Exercises
-
24. Accessing Databases with JDBC
- 24.1 Introduction
- 24.2 Relational Databases
- 24.3 A books Database
- 24.4 SQL
- 24.5 Setting up a Java DB Database
- 24.6 Manipulating Databases with JDBC
- 24.7 RowSet Interface
- 24.8 PreparedStatements
- 24.9 Stored Procedures
- 24.10 Transaction Processing
- 24.11 Wrap-Up
-
Summary
- Section 24.1 Introduction
- Section 24.2 Relational Databases
- 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.1 Connecting to and Querying a Database
- Section 24.6.2 Querying the books Database
- Section 24.7 RowSet Interface
- Section 24.8 PreparedStatements
- Section 24.9 Stored Procedures
- Section 24.10 Transaction Processing
- Self-Review Exercise
- Answers to Self-Review Exercise
- Exercises
-
25. JavaFX GUI: Part 1
- 25.1 Introduction
- 25.2 JavaFX Scene Builder and the NetBeans IDE
- 25.3 JavaFX App Window Structure
-
25.4 Welcome App—Displaying Text and an Image
- 25.4.1 Creating the App’s Project
- 25.4.2 NetBeans Projects Window—Viewing the Project Contents
- 25.4.3 Adding an Image to the Project
- 25.4.4 Opening JavaFX Scene Builder from NetBeans
- 25.4.5 Changing to a VBox Layout Container
- 25.4.6 Configuring the VBox Layout Container
- 25.4.7 Adding and Configuring a Label
- 25.4.8 Adding and Configuring an ImageView
- 25.4.9 Running the Welcome App
- 25.5 Tip Calculator App—Introduction to Event Handling
- 25.6 Features Covered in the Online JavaFX Chapters
- 25.7 Wrap-Up
-
Summary
- Section 25.1 Introduction
- Section 25.2 JavaFX Scene Builder and the NetBeans IDE
- Section 25.3 JavaFX App Window Structure
- Section 25.4 Welcome App—Displaying Text and an Image
- Section 25.5.2 Technologies Overview
- Section 25.5.3 Building the App’s GUI
- Section 25.5.4 TipCalculator Class
- Section 25.5.5 TipCalculatorController Class
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Making a Difference
- Chapters on the Web
- Appendices on the Web
- Index
- Additional Comments from Recent Editions Reviewers
-
26. JavaFX GUI: Part 2
- 26.1 Introduction
- 26.2 Installing JDK 8, NetBeans 8 and JavaFX Scene Builder 2.0
- 26.3 Laying Out Nodes in a Scene Graph
- 26.4 Painter App: RadioButtons, Mouse Events and Shapes
- 26.5 Color Chooser App: Property Bindings and Property Listeners
- 26.6 Cover Viewer App: Data-Drivien GUIs with JavaFX Collections
- 26.7 Cover Viewer App: Customizing ListView Cells
- 26.8 Wrap-Up
-
28. Networking
- 28.1 Introduction
- 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: DeitelMessenger
- 28.9 Wrap-Up
- Summary
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
29. Java Persistence API (JPA)
- 29.1 Introduction
- 29.2 JPA Technology Overview
-
29.3 Querying a Database with JPA
- 29.3.1 Creating the Java DB Database
- 29.3.2 Populate the books Database with Sample Data
- 29.3.3 Creating the Java Project
- 29.3.4 Adding the JPA and Java DB Libraries
- 29.3.5 Creating the Persistence Unit for the books Database
- 29.3.6 Querying the Authors Table
- 29.3.7 JPA Features of Autogenerated Class Authors
- 29.4 Named Queries; Accessing Data from Multiple Tables
- 29.5 Address Book: Using JPA and Transactions to Modify a Database
- 29.6 Web Resources
- 29.7 Wrap-Up
- Exercises
-
30. JavaServer™ Faces Web Apps: Part 1
- 30.1 Introduction
- 30.2 HyperText Transfer Protocol (HTTP) Transactions
- 30.3 Multitier Application Architecture
- 30.4 Your First JSF Web App
- 30.5 Model-View-Controller Architecture of JSF Apps
- 30.6 Common JSF Components
-
30.7 Validation Using JSF Standard Validators
- Validating Form Data in a Web Application
- Class ValidationBean
- index.xhtml
- First Row of the h:panelGrid
- Validating the nameInputText Element’s Contents
- Second and Third Rows of the h:panelGrid
- Validating the e-Mail Address
- Validating the Phone Number
- Submitting the Form—More Details of the JSF Lifecycle
- 30.8 Session Tracking
- 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
Product information
- Title: Java™ How To Program (Early Objects), Tenth Edition
- Author(s):
- Release date: February 2014
- Publisher(s): Pearson
- ISBN: 9780133813036
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
Head First Design Patterns, 2nd Edition
What will you learn from this book? You know you don't want to reinvent the wheel, …
book
The Object-Oriented Thought Process, 5th Edition
Object-oriented programming (OOP) is the foundation of modern programming languages, including C++, Java, C#, Visual Basic …
book
Learning Java, 5th Edition
If you're new to Java—or new to programming—this best-selling book will guide you through the language …