Java: how to program: late objects version

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Al-Hazbi, Saleh; Aly, Sherif G.; Deitel, Harvey M.; Deitel, Paul J
Edition: 10
Publisher: Pearson Education Limited
Year: 2014;2015

Language: English

Cover
Title
Copyright
Contents
Foreword
Preface
Before You Begin
1 Introduction to Computers, the Internet and Java
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 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.6.1 Windows—A Proprietary Operating System
1.6.2 Linux—An Open-Source Operating System
1.6.3 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 The Internet: A Network of Networks
1.11.2 The World Wide Web: Making the Internet User-Friendly
1.11.3 Web Services and Mashups
1.11.4 Ajax
1.11.5 The Internet of Things
1.12 Software Technologies
1.13 Keeping Up-to-Date with Information Technologies
2 Introduction to Java Applications; Input/Output and Operators
2.1 Introduction
2.2 Your First Program in Java: Printing a Line of Text
2.3 Modifying Your First Java Program
2.4 Displaying Text with printf
2.5 Another Application: Adding Integers
2.5.1 import Declarations
2.5.2 Declaring 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 (Optional) GUI and Graphics Case Study: Using Dialog Boxes
2.10 Wrap-Up
3 Control Statements: Part 1; Assignment, ++ and -- Operators
3.1 Introduction
3.2 Algorithms
3.3 Pseudocode
3.4 Control Structures
3.5 if Single-Selection Statement
3.6 if…else Double-Selection Statement
3.7 while Repetition Statement
3.8 Formulating Algorithms: Counter-Controlled Repetition
3.9 Formulating Algorithms: Sentinel-Controlled Repetition
3.10 Formulating Algorithms: Nested Control Statements
3.11 Compound Assignment Operators
3.12 Increment and Decrement Operators
3.13 Primitive Types
3.14 (Optional) GUI and Graphics Case Study: Creating Simple Drawings
3.15 Wrap-Up
4 Control Statements: Part 2; Logical Operators
4.1 Introduction
4.2 Essentials of Counter-Controlled Repetition
4.3 for Repetition Statement
4.4 Examples Using the for Statement
4.5 do…while Repetition Statement
4.6 switch Multiple-Selection Statement
4.7 break and continue Statements
4.8 Logical Operators
4.9 Structured Programming Summary
4.10 (Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals
4.11 Wrap-Up
5 Methods
5.1 Introduction
5.2 Program Modules in Java
5.3 static Methods, static Variables and Class Math
5.4 Declaring Methods
5.5 Notes on Declaring and Using Methods
5.6 Method-Call Stack and Stack Frames
5.7 Argument Promotion and Casting
5.8 Java API Packages
5.9 Case Study: Secure Random-Number Generation
5.10 Case Study: A Game of Chance; Introducing enum Types
5.11 Scope of Declarations
5.12 Method Overloading
5.13 (Optional) GUI and Graphics Case Study: Colors and Filled Shapes
5.14 Wrap-Up
6 Arrays and ArrayLists
6.1 Introduction
6.2 Primitive Types vs. Reference Types
6.3 Arrays
6.4 Declaring and Creating Arrays
6.5 Examples Using Arrays
6.5.1 Creating and Initializing an Array
6.5.2 Using an Array Initializer
6.5.3 Calculating the Values to Store in an Array
6.5.4 Summing the Elements of an Array
6.5.5 Using Bar Charts to Display Array Data Graphically
6.5.6 Using the Elements of an Array as Counters
6.5.7 Using Arrays to Analyze Survey Results
6.6 Exception Handling: Processing the Incorrect Response
6.6.1 The try Statement
6.6.2 Executing the catch Block
6.6.3 toString Method of the Exception Parameter
6.7 Enhanced for Statement
6.8 Passing Arrays to Methods
6.9 Pass-By-Value vs. Pass-By-Reference
6.10 Multidimensional Arrays
6.11 Variable-Length Argument Lists
6.12 Using Command-Line Arguments
6.13 Class Arrays
6.14 Introduction to Collections and Class ArrayList
6.15 (Optional) GUI and Graphics Case Study: Drawing Arcs
6.16 Wrap-Up
7 Introduction to Classes and Objects
7.1 Introduction
7.2 Instance Variables, set Methods and get Methods
7.2.1 Account Class with an Instance Variable, a set Method and a get Method
7.2.2 AccountTest Class That Creates and Uses an Object of Class Account
7.2.3 Compiling and Executing an App with Multiple Classes
7.2.4 Account UML Class Diagram with an Instance Variable and set and get Methods
7.2.5 Additional Notes on This Example
7.2.6 Software Engineering with private Instance Variables and public set and get Methods
7.3 Default and Explicit Initialization for Instance Variables
7.4 Account Class: Initializing Objects with Constructors
7.4.1 Declaring an Account Constructor for Custom Object Initialization
7.4.2 Class AccountTest: Initializing Account Objects When They’re Created
7.5 Account Class with a Balance; Floating-Point Numbers
7.5.1 Account Class with a balance Instance Variable of Type double
7.5.2 AccountTest Class to Use Class Account
7.6 Case Study: Card Shuffling and Dealing Simulation
7.7 Case Study: Class GradeBook Using an Array to Store Grades
7.8 Case Study: Class GradeBook Using a Two-Dimensional Array
7.9 Wrap-Up
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
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
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.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
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
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.10.1 default Interface Methods
10.10.2 static Interface Methods
10.10.3 Functional Interfaces
10.11 (Optional) GUI and Graphics Case Study: Drawing with Polymorphism
10.12 Wrap-Up
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
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
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.10.1 JCheckBox
12.10.2 JRadioButton
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.18.1 FlowLayout
12.18.2 BorderLayout
12.18.3 GridLayout
12.19 Using Panels to Manage More Complex Layouts
12.20 JTextArea
12.21 Wrap-Up
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
14 Strings, Characters and Regular Expressions
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
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.8 Wrap-Up
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.4.1 Creating a Sequential-Access Text File
15.4.2 Reading Data from a Sequential-Access Text File
15.4.3 Case Study: A Credit-Inquiry Program
15.4.4 Updating Sequential-Access Files
15.5 Object Serialization
15.5.1 Creating a Sequential-Access File Using Object Serialization
15.5.2 Reading and Deserializing Data from a Sequential-Access File
15.6 Opening Files with JFileChooser
15.7 (Optional) Additional java.io Classes
15.7.1 Interfaces and Classes for Byte-Based Input and Output
15.7.2 Interfaces and Classes for Character-Based Input and Output
15.8 Wrap-Up
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.6.1 ArrayList and Iterator
16.6.2 LinkedList
16.7 Collections Methods
16.7.1 Method sort
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 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
17 Java SE 8 Lambdas and Streams
17.1 Introduction
17.2 Functional Programming Technologies Overview
17.2.1 Functional Interfaces
17.2.2 Lambda Expressions
17.2.3 Streams
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 Manipulations
17.4.1 Creating a Stream
17.4.2 Sorting a Stream and Collecting the Results
17.4.3 Filtering a Stream and Storing the Results for Later Use
17.4.4 Filtering and Sorting a Stream and Collecting the Results
17.4.5 Sorting Previously Collected Results
17.5 Stream Manipulations
17.5.1 Mapping Strings to Uppercase Using a Method Reference
17.5.2 Filtering Strings Then Sorting Them in Case-Insensitive Ascending Order
17.5.3 Filtering Strings Then Sorting Them in Case-Insensitive Descending Order
17.6 Stream Manipulations
17.6.1 Creating and Displaying a List
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 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
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.9.1 Koch Curve Fractal
18.9.2 (Optional) Case Study: Lo Feather Fractal
18.10 Recursive Backtracking
18.11 Wrap-Up
19 Searching, Sorting and Big O
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
19.6.2 Efficiency of the Selection Sort
19.7 Insertion Sort
19.7.1 Insertion Sort Implementation
19.7.2 Efficiency of the Insertion Sort
19.8 Merge Sort
19.8.1 Merge Sort Implementation
19.8.2 Efficiency of the Merge Sort
19.9 Big O Summary for This Chapter’s Searching and Sorting Algorithms
19.10 Wrap-Up
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
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
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
22.11 Wrap-Up
23 Concurrency
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
23.4.4 Synchronized Mutable Data Sharing—Making Operations Atomic
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 with GUI: SwingWorker
23.11.1 Performing Computations in a Worker Thread: Fibonacci Numbers
23.11.2 Processing Intermediate Results: Sieve of Eratosthenes
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
24 Accessing Databases with JDBC
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
24.4.3 ORDER BY Clause
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
24.5.1 Creating the Chapter’s Databases on Windows
24.5.2 Creating the Chapter’s Databases on Mac OS X
24.5.3 Creating the Chapter’s Databases on Linux
24.6 Manipulating Databases with JDBC
24.6.1 Connecting to and Querying a Database
24.6.2 Querying the books Database
24.7 RowSet Interface
24.8 PreparedStatements
24.9 Stored Procedures
24.10 Transaction Processing
24.11 Wrap-Up
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.5.1 Test-Driving the Tip Calculator App
25.5.2 Technologies Overview
25.5.3 Building the App’s GUI
25.5.4 TipCalculator Class
25.5.5 TipCalculatorController Class
25.6 Features Covered in the Online JavaFX Chapters
25.7 Wrap-Up
Chapters on the Web
A Operator Precedence Chart
B ASCII Character Set
C Keywords and Reserved Words
D Primitive Types
E Using the Debugger
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