Description
Efnisyfirlit
- Title Page
- Copyright Page
- Acknowledgments
- About the Author
- Contents
- Preface
- Chapter 1 Introduction to Computers and Java
- 1.1 Introduction
- 1.2 Why Program?
- 1.3 Computer Systems: Hardware and Software
- Hardware
- Software
- 1.4 Programming Languages
- What Is a Program?
- A History of Java
- Java Applications and Applets
- 1.5 What Is a Program Made Of?
- Language Elements
- Lines and Statements
- Variables
- The Compiler and the Java Virtual Machine
- Java Software Editions
- Compiling and Running a Java Program
- 1.6 The Programming Process
- Software Engineering
- 1.7 Object-Oriented Programming
- Review Questions and Exercises
- Programming Challenge
- Chapter 2 Java Fundamentals
- 2.1 The Parts of a Java Program
- 2.2 The print and println Methods, and the Java API
- 2.3 Variables and Literals
- Displaying Multiple Items with the + Operator
- Be Careful with Quotation Marks
- More about Literals
- Identifiers
- Class Names
- 2.4 Primitive Data Types
- The Integer Data Types
- Floating-Point Data Types
- The boolean Data Type
- The char Data Type
- Variable Assignment and Initialization
- Variables Hold Only One Value at a Time
- 2.5 Arithmetic Operators
- Integer Division
- Operator Precedence
- Grouping with Parentheses
- The Math Class
- 2.6 Combined Assignment Operators
- 2.7 Conversion between Primitive Data Types
- Mixed Integer Operations
- Other Mixed Mathematical Expressions
- 2.8 Creating Named Constants with final
- 2.9 The String Class
- Objects Are Created from Classes
- The String Class
- Primitive Type Variables and Class Type Variables
- Creating a String Object
- 2.10 Scope
- 2.11 Comments
- 2.12 Programming Style
- 2.13 Reading Keyboard Input
- Reading a Character
- Mixing Calls to nextLine with Calls to Other Scanner Methods
- 2.14 Dialog Boxes
- Displaying Message Dialogs
- Displaying Input Dialogs
- An Example Program
- Converting String Input to Numbers
- 2.15 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 3 Decision Structures
- 3.1 The if Statement
- Using Relational Operators to Form Conditions
- Putting It All Together
- Programming Style and the if Statement
- Be Careful with Semicolons
- Having Multiple Conditionally Executed Statements
- Flags
- Comparing Characters
- 3.2 The if-else Statement
- 3.3 Nested if Statements
- 3.4 The if-else-if Statement
- 3.5 Logical Operators
- The Precedence of Logical Operators
- Checking Numeric Ranges with Logical Operators
- 3.6 Comparing String Objects
- Ignoring Case in String Comparisons
- 3.7 More about Variable Declaration and Scope
- 3.8 The Conditional Operator (Optional)
- 3.9 The switch Statement
- 3.10 Displaying Formatted Output with System.out.printf and String.format
- Format Specifier Syntax
- Precision
- Specifying a Minimum Field Width
- Flags
- Formatting String Arguments
- The String.format Method
- 3.11 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 4 Loops and Files
- 4.1 The Increment and Decrement Operators
- The Difference between Postfix and Prefix Modes
- 4.2 The while Loop
- The while Loop Is a Pretest Loop
- Infinite Loops
- Don’t Forget the Braces with a Block of Statements
- Programming Style and the while Loop
- 4.3 Using the while Loop for Input Validation
- 4.4 The do-while Loop
- 4.5 The for Loop
- The for Loop Is a Pretest Loop
- Avoid Modifying the Control Variable in the Body of the for Loop
- Other Forms of the Update Expression
- Declaring a Variable in the for Loop’s Initialization Expression
- Creating a User Controlled for Loop
- Using Multiple Statements in the Initialization and Update Expressions
- 4.6 Running Totals and Sentinel Values
- Using a Sentinel Value
- 4.7 Nested Loops
- 4.8 The break and continue Statements (Optional)
- 4.9 Deciding Which Loop to Use
- 4.10 Introduction to File Input and Output
- Using the PrintWriter Class to Write Data to a File
- Appending Data to a File
- Specifying the File Location
- Reading Data from a File
- Reading Lines from a File with the nextLine Method
- Adding a throws Clause to the Method Header
- Checking for a File’s Existence
- 4.11 Generating Random Numbers with the Random Class
- 4.12 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 5 Methods
- 5.1 Introduction to Methods
- void Methods and Value-Returning Methods
- Defining a void Method
- Calling a Method
- Hierarchical Method Calls
- Using Documentation Comments with Methods
- 5.2 Passing Arguments to a Method
- Argument and Parameter Data Type Compatibility
- Parameter Variable Scope
- Passing Multiple Arguments
- Arguments Are Passed by Value
- Passing Object References to a Method
- Using the @param Tag in Documentation Comments
- 5.3 More about Local Variables
- Local Variable Lifetime
- Initializing Local Variables with Parameter Values
- 5.4 Returning a Value from a Method
- Defining a Value-Returning Method
- Calling a Value-Returning Method
- Using the @return Tag in Documentation Comments
- Returning a boolean Value
- Returning a Reference to an Object
- 5.5 Problem Solving with Methods
- Calling Methods That Throw Exceptions
- 5.6 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 6 A First Look at Classes
- 6.1 Objects and Classes
- Classes: Where Objects Come From
- Classes in the Java API
- Primitive Variables vs. Objects
- 6.2 Writing a Simple Class, Step by Step
- Accessor and Mutator Methods
- The Importance of Data Hiding
- Avoiding Stale Data
- Showing Access Specification in UML Diagrams
- Data Type and Parameter Notation in UML Diagrams
- Layout of Class Members
- 6.3 Instance Fields and Methods
- 6.4 Constructors
- Showing Constructors in a UML Diagram
- Uninitialized Local Reference Variables
- The Default Constructor
- Writing Your Own No-Arg Constructor
- The String Class Constructor
- 6.5 Passing Objects as Arguments
- 6.6 Overloading Methods and Constructors
- The BankAccount Class
- Overloaded Methods Make Classes More Useful
- 6.7 Scope of Instance Fields
- Shadowing
- 6.8 Packages and import Statements
- Explicit and Wildcard import Statements
- The java.lang Package
- Other API Packages
- 6.9 Focus on Object-Oriented Design: Finding the Classes and Their Responsibilities
- Finding the Classes
- Identifying a Class’s Responsibilities
- This Is Only the Beginning
- 6.10 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 7 Arrays and the ArrayList Class
- 7.1 Introduction to Arrays
- Accessing Array Elements
- Inputting and Outputting Array Contents
- Java Performs Bounds Checking
- Watch Out for Off-by-One Errors
- Array Initialization
- Alternate Array Declaration Notation
- 7.2 Processing Array Elements
- Array Length
- The Enhanced for Loop
- Letting the User Specify an Array’s Size
- Reassigning Array Reference Variables
- Copying Arrays
- 7.3 Passing Arrays as Arguments to Methods
- 7.4 Some Useful Array Algorithms and Operations
- Comparing Arrays
- Summing the Values in a Numeric Array
- Getting the Average of the Values in a Numeric Array
- Finding the Highest and Lowest Values in a Numeric Array
- The SalesData Class
- Partially Filled Arrays
- Working with Arrays and Files
- 7.5 Returning Arrays from Methods
- 7.6 String Arrays
- Calling String Methods from an Array Element
- 7.7 Arrays of Objects
- 7.8 The Sequential Search Algorithm
- 7.9 Two-Dimensional Arrays
- Initializing a Two-Dimensional Array
- The length Field in a Two-Dimensional Array
- Displaying All the Elements of a Two-Dimensional Array
- Summing All the Elements of a Two-Dimensional Array
- Summing the Rows of a Two-Dimensional Array
- Summing the Columns of a Two-Dimensional Array
- Passing Two-Dimensional Arrays to Methods
- Ragged Arrays
- 7.10 Arrays with Three or More Dimensions
- 7.11 The Selection Sort and the Binary Search Algorithms
- The Selection Sort Algorithm
- The Binary Search Algorithm
- 7.12 Command-Line Arguments and Variable-Length Argument Lists
- Command-Line Arguments
- Variable-Length Argument Lists
- 7.13 The ArrayList Class
- Creating and Using an ArrayList Object
- Using the Enhanced for Loop with an ArrayList
- The ArrayList Class’s toString method
- Removing an Item from an ArrayList
- Inserting an Item
- Replacing an Item
- Capacity
- Using the Diamond Operator for Type Inference (Java 7)
- 7.14 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 8 A Second Look at Classes and Objects
- 8.1 Static Class Members
- A Quick Review of Instance Fields and Instance Methods
- Static Members
- Static Fields
- Static Methods
- 8.2 Passing Objects as Arguments to Methods
- 8.3 Returning Objects from Methods
- 8.4 The toString Method
- 8.5 Writing an equals Method
- 8.6 Methods That Copy Objects
- Copy Constructors
- 8.7 Aggregation
- Aggregation in UML Diagrams
- Security Issues with Aggregate Classes
- Avoid Using null References
- 8.8 The this Reference Variable
- Using this to Overcome Shadowing
- Using this to Call an Overloaded Constructor from Another Constructor
- 8.9 Enumerated Types
- Enumerated Types Are Specialized Classes
- Switching On an Enumerated Type
- 8.10 Garbage Collection
- The finalize Method
- 8.11 Focus on Object-Oriented Design: Class Collaboration
- Determining Class Collaborations with CRC Cards
- 8.12 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 9 Text Processing and More about Wrapper Classes
- 9.1 Introduction to Wrapper Classes
- 9.2 Character Testing and Conversion with the Character Class
- Character Case Conversion
- 9.3 More String Methods
- Searching for Substrings
- Extracting Substrings
- Methods That Return a Modified String
- The Static valueOf Methods
- 9.4 The StringBuilder Class
- The StringBuilder Constructors
- Other StringBuilder Methods
- The toString Method
- 9.5 Tokenizing Strings
- 9.6 Wrapper Classes for the Numeric Data Types
- The Static toString Methods
- The toBinaryString, toHexString, and toOctalString Methods
- The MIN_VALUE and MAX_VALUE Constants
- Autoboxing and Unboxing
- 9.7 Focus on Problem Solving: The TestScoreReader Class
- 9.8 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 10 Inheritance
- 10.1 What Is Inheritance?
- Generalization and Specialization
- Inheritance and the “Is a” Relationship
- Inheritance in UML Diagrams
- The Superclass’s Constructor
- Inheritance Does Not Work in Reverse
- 10.2 Calling the Superclass Constructor
- When the Superclass Has No Default or No-Arg Constructors
- Summary of Constructor Issues in Inheritance
- 10.3 Overriding Superclass Methods
- Overloading versus Overriding
- Preventing a Method from Being Overridden
- 10.4 Protected Members
- Package Access
- 10.5 Chains of Inheritance
- Class Hierarchies
- 10.6 The Object Class
- 10.7 Polymorphism
- Polymorphism and Dynamic Binding
- The “Is-a” Relationship Does Not Work in Reverse
- The instanceof Operator
- 10.8 Abstract Classes and Abstract Methods
- Abstract Classes in UML
- 10.9 Interfaces
- An Interface is a Contract
- Fields in Interfaces
- Implementing Multiple Interfaces
- Interfaces in UML
- Default Methods
- Polymorphism and Interfaces
- 10.10 Anonymous Inner Classes
- 10.11 Functional Interfaces and Lambda Expressions
- 10.12 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 11 Exceptions and Advanced File I/O
- 11.1 Handling Exceptions
- Exception Classes
- Handling an Exception
- Retrieving the Default Error Message
- Polymorphic References to Exceptions
- Using Multiple catch Clauses to Handle Multiple Exceptions
- The finally Clause
- The Stack Trace
- Handling Multiple Exceptions with One catch Clause (Java 7)
- When an Exception Is Not Caught
- Checked and Unchecked Exceptions
- 11.2 Throwing Exceptions
- Creating Your Own Exception Classes
- Using the @exception Tag in Documentation Comments
- 11.3 Advanced Topics: Binary Files, Random Access Files, and Object Serialization
- Binary Files
- Random Access Files
- Object Serialization
- Serializing Aggregate Objects
- 11.4 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 12 A First Look at GUI Applications
- 12.1 Introduction
- The JFC, AWT, and Swing
- Event-Driven Programming
- The javax.swing and java.awt Packages
- 12.2 Creating Windows
- Using Inheritance to Extend the JFrame Class
- Equipping GUI Classes with a main Method
- Adding Components to a Window
- Handling Events with Action Listeners
- Writing an Event Listener for the KiloConverter Class
- Background and Foreground Colors
- The ActionEvent Object
- 12.3 Layout Managers
- Adding a Layout Manager to a Container
- The FlowLayout Manager
- The BorderLayout Manager
- The GridLayout Manager
- 12.4 Radio Buttons and Check Boxes
- Radio Buttons
- Check Boxes
- 12.5 Borders
- 12.6 Focus on Problem Solving: Extending Classes from JPanel
- The Brandi’s Bagel House Application
- The GreetingPanel Class
- The BagelPanel Class
- The ToppingPanel Class
- The CoffeePanel Class
- Putting It All Together
- 12.7 Splash Screens
- 12.8 Using Console Output to Debug a GUI Application
- 12.9 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 13 Advanced GUI Applications
- 13.1 The Swing and AWT Class Hierarchy
- 13.2 Read-Only Text Fields
- 13.3 Lists
- Selection Modes
- Responding to List Events
- Retrieving the Selected Item
- Placing a Border around a List
- Adding a Scroll Bar to a List
- Adding Items to an Existing JList Component
- Multiple Selection Lists
- 13.4 Combo Boxes
- Retrieving the Selected Item
- 13.5 Displaying Images in Labels and Buttons
- 13.6 Mnemonics and Tool Tips
- Mnemonics
- Tool Tips
- 13.7 File Choosers and Color Choosers
- File Choosers
- Color Choosers
- 13.8 Menus
- 13.9 More about Text Components: Text Areas and Fonts
- Text Areas
- Fonts
- 13.10 Sliders
- 13.11 Look and Feel
- 13.12 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 14 Applets and More
- 14.1 Introduction to Applets
- 14.2 A Brief Introduction to HTML
- Hypertext
- Markup Language
- Document Structure Tags
- Text Formatting Tags
- Creating Breaks in Text
- Inserting Links
- 14.3 Creating Applets with Swing
- Running an Applet
- Handling Events in an Applet
- 14.4 Using AWT for Portability
- 14.5 Drawing Shapes
- The XY Coordinate System
- Graphics Objects
- The repaint Method
- Drawing on Panels
- 14.6 Handling Mouse Events
- Handling Mouse Events
- 14.7 Timer Objects
- 14.8 Playing Audio
- Using an AudioClip Object
- Playing Audio in an Application
- 14.9 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 15 Creating GUI Applications with JavaFX and Scene Builder
- 15.1 Introduction
- Event-Driven Programming
- 15.2 Scene Graphs
- 15.3 Using Scene Builder to Create JavaFX Applications
- Starting Scene Builder
- The Scene Builder Main Window
- 15.4 Writing the Application Code
- The Main Application Class
- The Controller Class
- Using the Sample Controller Skeleton
- Summary of Creating a JavaFX Application
- 15.5 RadioButtons and CheckBoxes
- RadioButtons
- Determining in Code Whether a RadioButton Is Selected
- Responding to RadioButton Events
- CheckBoxes
- Determining in Code Whether a CheckBox Is Selected
- Responding to CheckBox Events
- 15.6 Displaying Images
- Displaying an Image with Code
- 15.7 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 16 Recursion
- 16.1 Introduction to Recursion
- 16.2 Solving Problems with Recursion
- Direct and Indirect Recursion
- 16.3 Examples of Recursive Methods
- Summing a Range of Array Elements with Recursion
- Drawing Concentric Circles
- The Fibonacci Series
- Finding the Greatest Common Divisor
- 16.4 A Recursive Binary Search Method
- 16.5 The Towers of Hanoi
- 16.6 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Chapter 17 Databases
- 17.1 Introduction to Database Management Systems
- JDBC
- SQL
- Using a DBMS
- Java DB
- Creating the CoffeeDB Database
- Connecting to the CoffeeDB Database
- Connecting to a Password-Protected Database
- 17.2 Tables, Rows, and Columns
- Column Data Types
- Primary Keys
- 17.3 Introduction to the SQL SELECT Statement
- Passing an SQL Statement to the DBMS
- Specifying Search Criteria with the WHERE Clause
- Sorting the Results of a SELECT Query
- Mathematical Functions
- 17.4 Inserting Rows
- Inserting Rows with JDBC
- 17.5 Updating and Deleting Existing Rows
- Updating Rows with JDBC
- Deleting Rows with the DELETE Statement
- Deleting Rows with JDBC
- 17.6 Creating and Deleting Tables
- Removing a Table with the DROP TABLE Statement
- 17.7 Creating a New Database with JDBC
- 17.8 Scrollable Result Sets
- 17.9 Result Set Metadata
- 17.10 Displaying Query Results in a JTable
- 17.11 Relational Data
- Joining Data from Multiple Tables
- An Order Entry System
- 17.12 Advanced Topics
- Transactions
- Stored Procedures
- 17.13 Common Errors to Avoid
- Review Questions and Exercises
- Programming Challenges
- Index
- A
- B
- C
- D
- E
- F
- G
- H
- I
- J
- K
- L
- M
- N
- O
- P
- Q
- R
- S
- T
- U
- V
- W
- X
- Z
Reviews
There are no reviews yet.