| |
| |
Preface | |
| |
| |
Read this Before you Begin | |
| |
| |
| |
An Introduction to Java and the Java Programming Environment | |
| |
| |
The Java Programming Language | |
| |
| |
Three Types of Java Programs | |
| |
| |
An Introduction to Object-Oriented Terminology | |
| |
| |
Downloading the Java Standard Edition Development Kit (JDK) | |
| |
| |
The Structure of a Java Program | |
| |
| |
The Java Development Cycle | |
| |
| |
Writing Java Source Code | |
| |
| |
Compiling a Java Program | |
| |
| |
Executing a Java Program | |
| |
| |
Exercise 1-1: Understanding Java Utilities | |
| |
| |
Lab 1-1: Compiling and Executing A Java Program | |
| |
| |
| |
Variables, Operators, and Writing Programs Using Sequential Statements | |
| |
| |
Variables | |
| |
| |
Variable Names | |
| |
| |
Java Data Types | |
| |
| |
Exercise 2-1: Using Java Variables, Data Types, and Keywords | |
| |
| |
Declaring and Initializing Variables | |
| |
| |
Exercise 2-2: Declaring and Initializing Java Variables | |
| |
| |
Lab 2-1: Declaring and Initializing Java Variables | |
| |
| |
Arithmetic and Assignment Operators | |
| |
| |
Arithmetic Operators | |
| |
| |
Assignment Operators and the Assignment Statement | |
| |
| |
Precedence and Associativity | |
| |
| |
Exercise 2-3: Understanding Operator Precedence and Associativity | |
| |
| |
Lab 2-2: Arithmetic and Assignment Operators | |
| |
| |
Sequential Statements and Interactive Input Statements | |
| |
| |
Exercise 2-4: Understanding Sequential Statements | |
| |
| |
Lab 2-3: Using Sequential Statements in a Java Program | |
| |
| |
| |
Writing Structured Java Programs | |
| |
| |
Using Flowcharts and Pseudocode to Write a Java Program | |
| |
| |
Lab 3-1: Using Flowcharts and Pseudocode to Write a Java Program | |
| |
| |
Java Comments | |
| |
| |
Lab 3-2: Commenting Java Programs | |
| |
| |
Writing a Modular Program in Java | |
| |
| |
Lab 3-3: Writing a Modular Program in Java | |
| |
| |
| |
Writing Programs that Make Decisions | |
| |
| |
Boolean Operators | |
| |
| |
Relational Operators | |
| |
| |
Logical Operators | |
| |
| |
Relational and Logical Operator Precedence and Associativity | |
| |
| |
Comparing Strings | |
| |
| |
Decision Statements | |
| |
| |
The If Statement | |
| |
| |
Exercise 4-1: Understanding if Statements | |
| |
| |
Lab 4-1: Using if Statements | |
| |
| |
The if-else Statement | |
| |
| |
Exercise 4-2: Understanding if-else Statements | |
| |
| |
Lab 4-2: Using if-else Statements | |
| |
| |
Nested if Statements | |
| |
| |
Exercise 4-3: Understanding Nested if Statements | |
| |
| |
Lab 4-3: Using Nested if Statements | |
| |
| |
The switch Statement | |
| |
| |
Exercise 4-4: Using a switch Statement | |
| |
| |
Lab 4-4: Using a switch Statement | |
| |
| |
Using Decision Statements to Make Multiple Comparisons | |
| |
| |
Using And Logic | |
| |
| |
Using Or Logic | |
| |
| |
Exercise 4-5: Making Multiple Comparisons in Decision Statements | |
| |
| |
Lab 4-5: Making Multiple Comparisons in Decision Statements | |
| |
| |
| |
Writing Programs Using Loops | |
| |
| |
The Increment (++) and Decrement (--) Operators | |
| |
| |
Exercise 5-1: Using the Increment and Decrement Operators | |
| |
| |
Writing a While Loop in Java | |
| |
| |
Exercise 5-2: Using a while Loop | |
| |
| |
Using a Counter to Control a Loop | |
| |
| |
Exercise 5-3: Using a Counter-Controlled while Loop | |
| |
| |
Lab 5-1: Using a Counter-Controlled while Loop | |
| |
| |
Using a Sentinel Value to Control a Loop | |
| |
| |
Exercise 5-4: Using a Sentinel Value to Control a while Loop | |
| |
| |
Lab 5-2: Using a Sentinel Value to Control a while Loop | |
| |
| |
Writing a for Loop in Java | |
| |
| |
Exercise 5-5: Using a for Loop | |
| |
| |
Lab 5-3: Using a for Loop | |
| |
| |
Writing a Do-While Loop in Java | |
| |
| |
Exercise 5-6: Using a do-while Loop | |
| |
| |
Lab 5-4: Using a do-while Loop | |
| |
| |
Nesting Loops | |
| |
| |
Exercise 5-7: Nesting Loops | |
| |
| |
Lab 5-5: Nesting Loops | |
| |
| |
Accumulating Totals in a Loop | |
| |
| |
Exercise 5-8: Accumulating Totals in a Loop | |
| |
| |
Lab 5-6: Accumulating Totals in a Loop | |
| |
| |
Using a Loop to Validate Input | |
| |
| |
Exercise 5-9: Validating User Input | |
| |
| |
Lab 5-7: Validating User Input | |
| |
| |
| |
Using Arrays in Java Programs | |
| |
| |
Array Basics | |
| |
| |
Declaring Arrays | |
| |
| |
Initializing Arrays | |
| |
| |
Accessing Array Elements | |
| |
| |
Staying within the Bounds of an Array | |
| |
| |
Using Constants with Arrays | |
| |
| |
Exercise 6-1: Array Basics | |
| |
| |
Lab 6-1: Using Arrays | |
| |
| |
Searching an Array for an Exact Match | |
| |
| |
Exercise 6-2: Searching an Array for an Exact Match | |
| |
| |
Lab 6-2: Searching an Array for an Exact Match | |
| |
| |
Parallel Arrays | |
| |
| |
Exercise 6-3: Parallel Arrays | |
| |
| |
Lab 6-3: Parallel Arrays | |
| |
| |
| |
Using Methods in Java Programs | |
| |
| |
A Simple Java Method | |
| |
| |
Exercise 7-1: Writing Simple Methods | |
| |
| |
Lab 7-1: Writing Simple Methods | |
| |
| |
Writing Methods that Require a Single Parameter | |
| |
| |
Exercise 7-2: Writing Methods that Require a Single Parameter | |
| |
| |
Lab 7-2: Writing Methods that Require a Single Parameter | |
| |
| |
Writing Methods that Require Multiple Parameters | |
| |
| |
Exercise 7-3: Writing Methods that Require Multiple Parameters | |
| |
| |
Lab 7-3: Writing Methods that Require Multiple Parameters | |
| |
| |
Writing Methods that Return a Value | |
| |
| |
Exercise 7-4: Writing Methods that Return a Value | |
| |
| |
Lab 7-4: Writing Methods that Return a Value | |
| |
| |
Passing an Array and an Array Element to a Method | |
| |
| |
Exercise 7-5: Passing Arrays to Methods | |
| |
| |
Lab 7-5: Passing Arrays to Methods | |
| |
| |
Overloading Methods | |
| |
| |
Exercise 7-6: Overloading Methods | |
| |
| |
Lab 7-6: Overloading Methods | |
| |
| |
Using Java's Built-In Methods | |
| |
| |
Exercise 7-7: Using Java's Built-in Methods | |
| |
| |
Lab 7-7: Using Java's Built-in Methods | |
| |
| |
| |
Writing Control Break Programs | |
| |
| |
Accumulating Totals in Single-Level Control Break Programs | |
| |
| |
Exercise 8-1: Accumulating Totals in Single-Level Control Break Programs | |
| |
| |
Lab 8-1: Accumulating Totals in Single-Level Control Break Programs | |
| |
| |
Multiple-Level Control Break Programs | |
| |
| |
Exercise 8-2: Multiple-Level Control Break Programs | |
| |
| |
Lab 8-2: Multiple-Level Control Break Programs | |
| |
| |
| |
Sorting Data and File Input/Output | |
| |
| |
Sorting Data | |
| |
| |
Swapping Data Values | |
| |
| |
Exercise 9-1: Swapping Values | |
| |
| |
Lab 9-1: Swapping Values | |
| |
| |
Using a Bullet Sort | |
| |
| |
The main ( ) Method | |
| |
| |
The fillArray ( ) Method | |
| |
| |
The sortArray ( ) Method | |
| |
| |
The displayArray ( ) Method | |
| |
| |
Exercise 9-2: Using a Bubble Sort | |
| |
| |
Lab 9-2: Using a Bubble Sort | |
| |
| |
File Input and Output | |
| |
| |
Importing Packages and Classes | |
| |
| |
Opening a File for Reading | |
| |
| |
Reading Data from an Input File | |
| |
| |
Reading Data Using a Loop and EOF | |
| |
| |
Opening a File for Writing | |
| |
| |
Writing Data to an Output File | |
| |
| |
Exercise 9-3: Opening Files and Performing File Input | |
| |
| |
Lab 9-2: Using an Input File | |
| |
| |
| |
Additional Topics | |
| |
| |
A Programmer-Defined Class | |
| |
| |
Creating a Programmer-Defined Class | |
| |
| |
Adding Attributes to a Class | |
| |
| |
Adding Methods to a Class | |
| |
| |
Exercise 10-1: Creating a Class in Java | |
| |
| |
Lab 10-1: Creating a Class in Java | |
| |
| |
Creating a Graphical User Interface (GUI) | |
| |
| |
Writing a Constructor | |
| |
| |
Writing the main ( ) Method | |
| |
| |
Exercise 10-2: Creating a Graphical User Interface in Java | |
| |
| |
Lab 10-2: Creating a Graphical User Interface in Java | |
| |
| |
Index | |