| |
| |
Introduction | |
| |
| |
How to Use This Book | |
| |
| |
Conventions Used in This Book | |
| |
| |
What You Don't Have to Read | |
| |
| |
Foolish Assumptions | |
| |
| |
How This Book Is Organized | |
| |
| |
Getting Started | |
| |
| |
Writing Your Own Java Programs | |
| |
| |
Working with the Big Picture: Object-Oriented Programming | |
| |
| |
Savvy Java Techniques | |
| |
| |
The Part of Tens | |
| |
| |
Appendices | |
| |
| |
Bonus Chapters on the CD-ROM! | |
| |
| |
Icons Used in This Book | |
| |
| |
Where to Go from Here | |
| |
| |
Getting Started | |
| |
| |
All about Java | |
| |
| |
What You Can Do with Java | |
| |
| |
Why You Should Use Java | |
| |
| |
Getting Perspective: Where Java Fits In | |
| |
| |
Object-Oriented Programming (OOP) | |
| |
| |
Object-oriented languages | |
| |
| |
Objects and their classes | |
| |
| |
What's so good about an object-oriented language? | |
| |
| |
Refining your understanding of classes and objects | |
| |
| |
What's Next? | |
| |
| |
Running Canned Java Programs | |
| |
| |
Downloading and Installing the Java Development Kit (JDK) | |
| |
| |
Downloading Java | |
| |
| |
Installing Java on your computer | |
| |
| |
Preparing to Use an Integrated Development Environment | |
| |
| |
JCreator | |
| |
| |
Running JCreator for the first time | |
| |
| |
Running Java Programs | |
| |
| |
Running a text-based program | |
| |
| |
Running a GUI on its own | |
| |
| |
Running a GUI on a Web page (a Java applet) | |
| |
| |
Using the Basic Building Blocks | |
| |
| |
Speaking the Java Language | |
| |
| |
The grammar and the common names | |
| |
| |
The words in a Java program | |
| |
| |
Checking Out Java Code for the First Time | |
| |
| |
Understanding a Simple Java Program | |
| |
| |
The Java class | |
| |
| |
The Java method | |
| |
| |
The main method in a program | |
| |
| |
How you finally tell the computer to do something | |
| |
| |
Curly braces | |
| |
| |
And Now, a Few Comments | |
| |
| |
Adding comments to your code | |
| |
| |
What's Barry's excuse? | |
| |
| |
Finding javadoc pages | |
| |
| |
Using comments to experiment with your code | |
| |
| |
Typing Your Own Code | |
| |
| |
Writing Your Own Java Programs | |
| |
| |
Making the Most of Variables and Their Values | |
| |
| |
Varying a Variable | |
| |
| |
Assignment Statements | |
| |
| |
Understanding the Types of Values That Variables May Have | |
| |
| |
An Import Declaration | |
| |
| |
Displaying Text | |
| |
| |
Numbers without Decimal Points | |
| |
| |
Combining Declarations and Initializing Variables | |
| |
| |
The Atoms: Java's Primitive Types | |
| |
| |
The char type | |
| |
| |
The boolean type | |
| |
| |
The Molecules and Compounds: Reference Types | |
| |
| |
Creating New Values by Applying Operators | |
| |
| |
Initialize once, assign often | |
| |
| |
The increment and decrement operators | |
| |
| |
Assignment operators | |
| |
| |
Controlling Program Flow with Decision-Making Statements | |
| |
| |
Making Decisions (Java if Statements) | |
| |
| |
Guess the number | |
| |
| |
She controlled keystrokes from the keyboard | |
| |
| |
Creating randomness | |
| |
| |
The if statement | |
| |
| |
The double equal sign | |
| |
| |
Brace yourself | |
| |
| |
Indenting if statements in your code | |
| |
| |
Elseless in Ifrica | |
| |
| |
Forming Conditions with Comparisons and Logical Operators | |
| |
| |
Comparing numbers; comparing characters | |
| |
| |
Comparing objects | |
| |
| |
Importing everything in one fell swoop | |
| |
| |
Java's logical operators | |
| |
| |
Building a Nest | |
| |
| |
Choosing among Many Alternatives (Java switch Statements) | |
| |
| |
Your basic switch statement | |
| |
| |
To break or not to break | |
| |
| |
Controlling Program Flow with Loops | |
| |
| |
Repeating Instructions Over and Over Again (Java while Statements) | |
| |
| |
Repeating a Certain Number of Times (Java for Statements) | |
| |
| |
The anatomy of a for statement | |
| |
| |
The world premiere of "Al's All Wet" | |
| |
| |
Repeating Until You Get What You Want (Java do Statements) | |
| |
| |
Reading a single character | |
| |
| |
File handling in Java | |
| |
| |
Variable declarations and blocks | |
| |
| |
Loops Made Painless | |
| |
| |
Don't need no stinking counters | |
| |
| |
Grouping things together | |
| |
| |
Anatomy of an enhanced for loop | |
| |
| |
Working with the Big Picture: Object-Oriented Programming | |
| |
| |
Thinking in Terms of Classes and Objects | |
| |
| |
Defining a Class (What It Means to Be an Account) | |
| |
| |
Declaring variables and creating objects | |
| |
| |
Initializing a variable | |
| |
| |
Using variables | |
| |
| |
Compiling and Running More Than One Class | |
| |
| |
Defining a Method within a Class (Displaying an Account) | |
| |
| |
An account that displays itself | |
| |
| |
The display method's header | |
| |
| |
Sending Values to and from Methods (Calculating Interest) | |
| |
| |
Passing a value to a method | |
| |
| |
Returning a value from the getInterest method | |
| |
| |
Making numbers look good | |
| |
| |
Hiding Details with Accessor Methods (Why You Shouldn't Micromanage a Bank Teller) | |
| |
| |
Good programming | |
| |
| |
Public lives and private dreams: Making a variable name inaccessible | |
| |
| |
Enforcing rules with accessor methods | |
| |
| |
Saving Time and Money: Reusing Existing Code | |
| |
| |
Defining a Class (What It Means to Be an Employee) | |
| |
| |
The last word on employees | |
| |
| |
Putting your class to good use | |
| |
| |
Cutting a check | |
| |
| |
Working with Disk Files (A Brief Detour) | |
| |
| |
Storing data in a file | |
| |
| |
Copying and pasting code | |
| |
| |
Reading from a file | |
| |
| |
Who moved my file? | |
| |
| |
Adding directory names to your filenames | |
| |
| |
Reading a line at a time | |
| |
| |
Defining Subclasses (What It Means to Be a Full-Time Employee or a Part-Time Employee) | |
| |
| |
Creating a subclass | |
| |
| |
Creating subclasses is habit-forming | |
| |
| |
Using Subclasses | |
| |
| |
A program for the minimalist | |
| |
| |
A program for the maximalist | |
| |
| |
Overriding Existing Methods (Changing the Payments for Some of Your Employees) | |
| |
| |
Constructing New Objects | |
| |
| |
Defining Constructors (What It Means to Be a Temperature) | |
| |
| |
What is a temperature? | |
| |
| |
What you can do with a temperature | |
| |
| |
Calling new Temperature (32.0): A case study | |
| |
| |
Enum types as first-class citizens | |
| |
| |
Some things never change | |
| |
| |
More Subclasses (Doing Something about the Weather) | |
| |
| |
Building better temperatures | |
| |
| |
Constructors for subclasses | |
| |
| |
Using all this stuff | |
| |
| |
The default constructor | |
| |
| |
An invisible constructor call | |
| |
| |
A Constructor That Does More | |
| |
| |
Savvy Java Techniques | |
| |
| |
Putting Variables and Methods Where They Belong | |
| |
| |
Defining a Class (What It Means to Be a Baseball Player) | |
| |
| |
Another way to beautify your numbers | |
| |
| |
Using the Player class | |
| |
| |
Nine, count 'em, nine | |
| |
| |
Don't get all GUI on me | |
| |
| |
Tossing an exception from method to method | |
| |
| |
Making Static (Finding the Team Average) | |
| |
| |
Why is there so much static? | |
| |
| |
Displaying the overall team average | |
| |
| |
Static is old hat | |
| |
| |
Could cause static; handle with care | |
| |
| |
Experiments with Variables | |
| |
| |
Putting a variable in its place | |
| |
| |
Telling a variable where to go | |
| |
| |
Passing Parameters | |
| |
| |
Pass by value | |
| |
| |
Returning a result | |
| |
| |
Pass by reference | |
| |
| |
Returning an object from a method | |
| |
| |
Epilogue | |
| |
| |
Using Arrays and Collections to Juggle Values | |
| |
| |
Getting Your Ducks All in a Row | |
| |
| |
Creating an array in two easy steps | |
| |
| |
Storing values | |
| |
| |
Tab stops and other special things | |
| |
| |
Using an array initializer | |
| |
| |
Stepping through an array with the enhanced for loop | |
| |
| |
Searching | |
| |
| |
Arrays of Objects | |
| |
| |
Using the Room class | |
| |
| |
Yet another way to beautify your numbers | |
| |
| |
The conditional operator | |
| |
| |
Command Line Arguments | |
| |
| |
Using command line arguments in a Java program | |
| |
| |
Checking for the right number of command line arguments | |
| |
| |
Setting up JCreator for command line arguments | |
| |
| |
Using Java Collections | |
| |
| |
Collection classes to the rescue | |
| |
| |
Using an ArrayList | |
| |
| |
Using generics (hot stuff!) | |
| |
| |
Testing for the presence of more data | |
| |
| |
Looking Good When Things Take Unexpected Turns | |
| |
| |
Handling Exceptions | |
| |
| |
The parameter in a catch clause | |
| |
| |
Exception types | |
| |
| |
Who's going to catch the exception? | |
| |
| |
Throwing caution to the wind | |
| |
| |
Doing useful things | |
| |
| |
Our friends, the good exceptions | |
| |
| |
Handle an Exception or Pass the Buck | |
| |
| |
Finishing the Job with a finally Clause | |
| |
| |
The Part of Tens | |
| |
| |
Ten Ways to Avoid Mistakes | |
| |
| |
Putting Capital Letters Where They Belong | |
| |
| |
Breaking Out of a switch Statement | |
| |
| |
Comparing Values with a Double Equal Sign | |
| |
| |
Adding Components to a GUI | |
| |
| |
Adding Listeners to Handle Events | |
| |
| |
Defining the Required Constructors | |
| |
| |
Fixing Non-Static References | |
| |
| |
Staying within Bounds in an Array | |
| |
| |
Anticipating Null Pointers | |
| |
| |
Helping Java Find Its Files | |
| |
| |
Ten Sets of Web Resources for Java | |
| |
| |
The Horse's Mouth | |
| |
| |
Finding News, Reviews, and Sample Code | |
| |
| |
Improving Your Code with Tutorials | |
| |
| |
Finding Help on Newsgroups | |
| |
| |
Checking the FAQs for Useful Info | |
| |
| |
Reading Documentation with Additional Commentary | |
| |
| |
Opinions and Advocacy | |
| |
| |
Looking for Java Jobs | |
| |
| |
Becoming Certified in Java | |
| |
| |
Everyone's Favorite Sites | |
| |
| |
Using the CD-ROM | |
| |
| |
What You Can Expect to Find on the CD-ROM | |
| |
| |
System Requirements | |
| |
| |
Using the CD with Microsoft Windows | |
| |
| |
Using the CD with Mac OS | |
| |
| |
Running the Java Code That's in This Book | |
| |
| |
Freeware, Shareware, and Just Plain Ware | |
| |
| |
JCreator | |
| |
| |
Adobe Acrobat Reader | |
| |
| |
Jindent | |
| |
| |
NetCaptor | |
| |
| |
WinOne | |
| |
| |
And, If You Run into Any Trouble | |
| |
| |
Index | |
| |
| |
End-User License Agreement | |