Visit www.dummies.com/cheatsheet/java to view this books’ cheat sheet.
Table of Contents
How to Use This Book Conventions Used in This Book What You Don’t Have to Read Foolish Assumptions How This Book Is Organized Part I: Getting Started Part II: Writing Your Own Java Programs Part III: Working with the Big Picture: Object-Oriented Programming Part IV: Savvy Java Techniques Part V: The Part of Tens Icons Used in This Book Where to Go from Here
Part I: Getting Started Part II: Writing Your Own Java Programs Part III: Working with the Big Picture: Object-Oriented Programming Part IV: Savvy Java Techniques Part V: The Part of Tens
Chapter 1: 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? Chapter 2: All about Software Quick-Start Instructions What You Install on Your Computer What is a compiler? What is a Java virtual machine? Developing Software What is an Integrated Development Environment? Chapter 3: 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? Using comments to experiment with your code
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?
Object-oriented languages Objects and their classes What’s so good about an object-oriented language? Refining your understanding of classes and objects
Quick-Start Instructions What You Install on Your Computer What is a compiler? What is a Java virtual machine? Developing Software What is an Integrated Development Environment?
What is a compiler? What is a Java virtual machine? Developing Software What is an Integrated Development Environment?
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? Using comments to experiment with your code
The grammar and the common names The words in a 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
Adding comments to your code What’s Barry’s excuse? Using comments to experiment with your code
Chapter 4: Making the Most of Variables and Their Values Varying a Variable Assignment Statements Understanding the Types of Values That Variables May Have 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 An Import Declaration Creating New Values by Applying Operators Initialize once, assign often The increment and decrement operators Assignment operators Chapter 5: 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 Vive les nuls! (Conditions in parentheses) Building a Nest Choosing among Many Alternatives (Java switch Statements) Your basic switch statement To break or not to break Along comes Java 7 Chapter 6: 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
Varying a Variable Assignment Statements Understanding the Types of Values That Variables May Have 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 An Import Declaration Creating New Values by Applying Operators Initialize once, assign often The increment and decrement operators Assignment operators
The char type The boolean type
Initialize once, assign often The increment and decrement operators Assignment operators
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 Vive les nuls! (Conditions in parentheses) Building a Nest Choosing among Many Alternatives (Java switch Statements) Your basic switch statement To break or not to break Along comes Java 7
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
Comparing numbers; comparing characters Comparing objects Importing everything in one fell swoop Java’s logical operators Vive les nuls! (Conditions in parentheses)
Your basic switch statement To break or not to break Along comes Java 7
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
The anatomy of a for statement The world premiere of “Al’s All Wet”
Reading a single character File handling in Java Variable declarations and blocks
Chapter 7: Thinking in Terms of Classes and Objects Defining a Class (What It Means to Be an Account) A public class Declaring variables and creating objects Initializing a variable Using an object’s fields One program; several classes 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 field inaccessible Enforcing rules with accessor methods Chapter 8: 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 or Part-Time Employee) Creating a subclass Creating subclasses is habit-forming Using Subclasses Making types match The second half of the story Overriding Existing Methods (Changing the Payments for Some of Your Employees) A Java annotation Using methods from classes and subclasses Chapter 9: Constructing New Objects Defining Constructors (What It Means to Be a Temperature) What is a temperature? What is a temperature scale? (Java’s enum type) Okay, so then what is a temperature? What you can do with a temperature Calling new Temperature(32.0): A case study Some things never change More Subclasses (Doing Something about the Weather) Building better temperatures Constructors for subclasses Using all this stuff The default constructor A Constructor That Does More Classes and methods from the Java API The SuppressWarnings annotation
Defining a Class (What It Means to Be an Account) A public class Declaring variables and creating objects Initializing a variable Using an object’s fields One program; several classes 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 field inaccessible Enforcing rules with accessor methods
A public class Declaring variables and creating objects Initializing a variable Using an object’s fields One program; several classes
An account that displays itself The display method’s header
Passing a value to a method Returning a value from the getInterest method
Good programming Public lives and private dreams: Making a field inaccessible Enforcing rules with accessor methods
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 or Part-Time Employee) Creating a subclass Creating subclasses is habit-forming Using Subclasses Making types match The second half of the story Overriding Existing Methods (Changing the Payments for Some of Your Employees) A Java annotation Using methods from classes and subclasses
The last word on employees Putting your class to good use Cutting a check
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
Creating a subclass Creating subclasses is habit-forming
Making types match The second half of the story
A Java annotation Using methods from classes and subclasses
Defining Constructors (What It Means to Be a Temperature) What is a temperature? What is a temperature scale? (Java’s enum type) Okay, so then what is a temperature? What you can do with a temperature Calling new Temperature(32.0): A case study Some things never change More Subclasses (Doing Something about the Weather) Building better temperatures Constructors for subclasses Using all this stuff The default constructor A Constructor That Does More Classes and methods from the Java API The SuppressWarnings annotation
What is a temperature? What is a temperature scale? (Java’s enum type) Okay, so then what is a temperature? What you can do with a temperature Calling new Temperature(32.0): A case study Some things never change
Building better temperatures Constructors for subclasses Using all this stuff The default constructor
Classes and methods from the Java API The SuppressWarnings annotation
Chapter 10: 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? Meet the static initializer 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 Chapter 11: 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 Using Java Collections Collection classes to the rescue Using an ArrayList Using generics (hot stuff!) Testing for the presence of more data Chapter 12: Looking Good When Things Take Unexpected Turns Handling Exceptions The parameter in a catch clause Exception types Who’s going to catch the exception? Java 7 and the multi-catch clause 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 Close Those Files! How to close a file A try statement with resources Chapter 13: Sharing Names among the Parts of a Java Program Access Modifiers Classes, Access, and Multipart Programs Members versus classes Access modifiers for members Putting a drawing on a frame Directory structure Making a frame Sneaking Away from the Original Code Default access Crawling back into the package Protected Access Putting non-subclasses in the same package Access Modifiers for Java Classes Public classes Nonpublic classes Chapter 14: Responding to Keystrokes and Mouse Clicks Go On . . . Click That Button Events and event handling The Java interface Threads of execution The keyword this Inside the actionPerformed method The serialVersionUID Responding to Things Other Than Button Clicks Creating Inner Classes Chapter 15: Writing Java Applets Applets 101 Waiting to be called A public class The Java API (again) Making Things Move The methods in an applet What to put into all these methods Responding to Events in an Applet Chapter 16: Using Java Database Connectivity JDBC and Java DB Creating Data Using SQL commands Connecting and disconnecting Retrieving Data
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? Meet the static initializer 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
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
Why is there so much static? Meet the static initializer Displaying the overall team average Static is old hat Could cause static; handle with care
Putting a variable in its place Telling a variable where to go
Pass by value Returning a result Pass by reference Returning an object from a method Epilogue
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 Using Java Collections Collection classes to the rescue Using an ArrayList Using generics (hot stuff!) Testing for the presence of more data
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
Using the Room class Yet another way to beautify your numbers The conditional operator
Using command line arguments in a Java program Checking for the right number of command line arguments
Collection classes to the rescue Using an ArrayList Using generics (hot stuff!) Testing for the presence of more data
Handling Exceptions The parameter in a catch clause Exception types Who’s going to catch the exception? Java 7 and the multi-catch clause 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 Close Those Files! How to close a file A try statement with resources
The parameter in a catch clause Exception types Who’s going to catch the exception? Java 7 and the multi-catch clause Throwing caution to the wind Doing useful things Our friends, the good exceptions
How to close a file A try statement with resources
Access Modifiers Classes, Access, and Multipart Programs Members versus classes Access modifiers for members Putting a drawing on a frame Directory structure Making a frame Sneaking Away from the Original Code Default access Crawling back into the package Protected Access Putting non-subclasses in the same package Access Modifiers for Java Classes Public classes Nonpublic classes
Members versus classes Access modifiers for members Putting a drawing on a frame Directory structure Making a frame
Default access Crawling back into the package
Putting non-subclasses in the same package
Public classes Nonpublic classes
Go On . . . Click That Button Events and event handling The Java interface Threads of execution The keyword this Inside the actionPerformed method The serialVersionUID Responding to Things Other Than Button Clicks Creating Inner Classes
Events and event handling The Java interface Threads of execution The keyword this Inside the actionPerformed method The serialVersionUID
Applets 101 Waiting to be called A public class The Java API (again) Making Things Move The methods in an applet What to put into all these methods Responding to Events in an Applet
Waiting to be called A public class The Java API (again)
The methods in an applet What to put into all these methods
JDBC and Java DB Creating Data Using SQL commands Connecting and disconnecting Retrieving Data
Using SQL commands Connecting and disconnecting
Chapter 17: 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 Chapter 18: Ten Websites for Java This Book’s Website The Horse’s Mouth Finding News, Reviews, and Sample Code Looking for Java Jobs Everyone’s Favorite Sites
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
This Book’s Website The Horse’s Mouth Finding News, Reviews, and Sample Code Looking for Java Jobs Everyone’s Favorite Sites