You are previewing Java For Dummies, 6th Edition.
O'Reilly logo
Java For Dummies, 6th Edition

Book Description

The top-selling beginning Java book is now fully updated!

As an unstoppably platform-independent, object-oriented programming language, Java is used for developing web and mobile applications. In this up-to-date bestselling book, veteran author Barry Burd shows you how to create basic Java objects and clearly explains when you should simply reuse existing code.

  • Explores how the new version of Java offers more robust functionality and new features such as closures to keep Java competitive with more syntax-friendly languages like Python and Ruby

  • Covers object-oriented programming basics with Java, code reuse, the essentials of creating a Java program using the new JDK 7, creating basic Java objects, and new Eclipse features

  • Features a companion website that offers all code from the book and bonus chapters

  • Java For Dummies, 6th Edition gets you started with creating Java applications quickly and easily.

    Table of Contents

      1. Introduction
        1. How to Use This Book
        2. Conventions Used in This Book
        3. What You Don’t Have to Read
        4. Foolish Assumptions
        5. How This Book Is Organized
          1. Part I: Getting Started with Java
          2. Part II: Writing Your Own Java Program
          3. Part III: Working with the Big Picture: Object-Oriented Programming
          4. Part IV: Savvy Java Techniques
          5. Part V: The Part of Tens
        6. Icons Used in This Book
        7. Beyond the Book
        8. Where to Go from Here
      2. Part I: Getting Started with Java
        1. Chapter 1: All about Java
          1. What You Can Do with Java
          2. Why You Should Use Java
          3. Getting Perspective: Where Java Fits In
          4. Object-Oriented Programming (OOP)
            1. Object-oriented languages
            2. Objects and their classes
            3. What’s so good about an object-oriented language?
            4. Refining your understanding of classes and objects
          5. What’s Next?
        2. Chapter 2: All about Software
          1. Quick-Start Instructions
          2. What You Install on Your Computer
            1. What is a compiler?
            2. What is a Java Virtual Machine?
            3. Developing software
            4. What is an Integrated Development Environment?
        3. Chapter 3: Using the Basic Building Blocks
          1. Speaking the Java Language
            1. The grammar and the common names
            2. The words in a Java program
          2. Checking Out Java Code for the First Time
          3. Understanding a Simple Java Program
            1. The Java class
            2. The Java method
            3. The main method in a program
            4. How you finally tell the computer to do something
            5. Curly braces
          4. And Now, a Few Comments
            1. Adding comments to your code
            2. What’s Barry’s excuse?
            3. Using comments to experiment with your code
      3. Part II: Writing Your Own Java Programs
        1. Chapter 4: Making the Most of Variables and Their Values
          1. Varying a Variable
          2. Assignment Statements
          3. Understanding the Types of Values That Variables May Have
          4. Displaying Text
          5. Numbers without Decimal Points
          6. Combining Declarations and Initializing Variables
          7. The Atoms: Java’s Primitive Types
            1. The char type
            2. The boolean type
          8. The Molecules and Compounds: Reference Types
          9. An Import Declaration
          10. Creating New Values by Applying Operators
            1. Initialize once, assign often
            2. The increment and decrement operators
            3. Assignment operators
        2. Chapter 5: Controlling Program Flow with Decision-Making Statements
          1. Making Decisions (Java if Statements)
            1. Guess the number
            2. She controlled keystrokes from the keyboard
            3. Creating randomness
            4. The if statement
            5. The double equal sign
            6. Brace yourself
            7. Indenting if statements in your code
            8. Elseless in Ifrica
          2. Forming Conditions with Comparisons and Logical Operators
            1. Comparing numbers; comparing characters
            2. Comparing objects
            3. Importing everything in one fell swoop
            4. Java’s logical operators
            5. Vive les nuls!
            6. (Conditions in parentheses)
          3. Building a Nest
          4. Choosing among Many Alternatives (Java switch Statements)
            1. Your basic switch statement
            2. To break or not to break
            3. The new and improved switch
        3. Chapter 6: Controlling Program Flow with Loops
          1. Repeating Instructions Over and Over Again (Java while Statements)
          2. Repeating a Certain Number of Times (Java for Statements)
            1. The anatomy of a for statement
            2. The world premiere of “Al’s All Wet”
          3. Repeating Until You Get What You Want (Java do Statements)
            1. Reading a single character
            2. File handling in Java
            3. Variable declarations and blocks
      4. Part III: Working with the Big Picture: Object-Oriented Programming
        1. Chapter 7: Thinking in Terms of Classes and Objects
          1. Defining a Class (What It Means to Be an Account)
            1. Declaring variables and creating objects
            2. Initializing a variable
            3. Using an object’s fields
            4. One program; several classes
            5. Public classes
          2. Defining a Method within a Class (Displaying an Account)
            1. An account that displays itself
            2. The display method’s header
          3. Sending Values to and from Methods (Calculating Interest)
            1. Passing a value to a method
            2. Returning a value from the getInterest method
          4. Making Numbers Look Good
          5. Hiding Details with Accessor Methods
            1. Good programming
            2. Public lives and private dreams: Making a field inaccessible
            3. Enforcing rules with accessor methods
        2. Chapter 8: Saving Time and Money: Reusing Existing Code
          1. Defining a Class (What It Means to Be an Employee)
            1. The last word on employees
            2. Putting your class to good use
            3. Cutting a check
          2. Working with Disk Files (A Brief Detour)
            1. Storing data in a file
            2. Copying and pasting code
            3. Reading from a file
            4. Who moved my file?
            5. Adding directory names to your filenames
            6. Reading a line at a time
            7. Closing the connection to a disk file
          3. Defining Subclasses (What It Means to Be a Full-Time or Part-Time Employee)
            1. Creating a subclass
            2. Creating subclasses is habit-forming
            3. Using Subclasses
          4. Overriding Existing Methods (Changing the Payments for Some Employees)
            1. A Java annotation
            2. Using methods from classes and subclasses
        3. Chapter 9: Constructing New Objects
          1. Defining Constructors (What It Means to Be a Temperature)
            1. What is a temperature?
            2. What is a temperature scale? (Java's enum type)
            3. Okay, so then what is a temperature?
            4. What you can do with a temperature
            5. Calling new Temperature(32.0): A case study
            6. Some things never change
          2. More Subclasses (Doing Something about the Weather)
            1. Building better temperatures
            2. Constructors for subclasses
            3. Using all this stuff
            4. The default constructor
          3. A Constructor That Does More
          4. Classes and methods from the Java API
          5. The SuppressWarnings annotation
      5. Part IV: Savvy Java Techniques
        1. Chapter 10: Putting Variables and Methods Where They Belong
          1. Defining a Class (What It Means to Be a Baseball Player)
            1. Another way to beautify your numbers
            2. Using the Player class
            3. Nine, count ’em, nine
            4. Don’t get all GUI on me
            5. Tossing an exception from method to method
          2. Making Static (Finding the Team Average)
            1. Why is there so much static?
            2. Meet the static initializer
            3. Displaying the overall team average
            4. Static is old hat
            5. Could cause static; handle with care
          3. Experiments with Variables
            1. Putting a variable in its place
            2. Telling a variable where to go
          4. Passing Parameters
            1. Pass by value
            2. Returning a result
            3. Pass by reference
            4. Returning an object from a method
            5. Epilogue
        2. Chapter 11: Using Arrays to Juggle Values
          1. Getting Your Ducks All in a Row
            1. Creating an array in two easy steps
            2. Storing values
            3. Tab stops and other special things
            4. Using an array initializer
            5. Stepping through an array with the enhanced for loop
            6. Searching
            7. Writing to a file
            8. When to close a file
          2. Arrays of Objects
            1. Using the Room class
            2. Yet another way to beautify your numbers
            3. The conditional operator
          3. Command Line Arguments
            1. Using command line arguments in a Java program
            2. Checking for the right number of command line arguments
        3. Chapter 12: Using Collections and Streams (When Arrays Aren't Good Enough)
          1. Understanding the Limitations of Arrays
          2. Collection Classes to the Rescue
            1. Using an ArrayList
            2. Using generics
            3. Testing for the presence of more data
            4. Using an iterator
            5. Java's many collection classes
          3. New in Java 8: Functional Programming
            1. Solving a problem the old-fashioned way
            2. Streams
            3. Lambda expressions
            4. A taxonomy of lambda expressions
            5. Using streams and lambda expressions
            6. Why bother?
            7. Method references
        4. Chapter 13: Looking Good When Things Take Unexpected Turns
          1. Handling Exceptions
            1. The parameter in a catch clause
            2. Exception types
            3. Who’s going to catch the exception?
            4. The multi-catch clause
            5. Throwing caution to the wind
            6. Doing useful things
            7. Our friends, the good exceptions
          2. Handle an Exception or Pass the Buck
          3. Finishing the Job with a finally Clause
          4. A try Statement with Resources
        5. Chapter 14: Sharing Names among the Parts of a Java Program
          1. Access Modifiers
          2. Classes, Access, and Multipart Programs
            1. Members versus classes
            2. Access modifiers for members
            3. Putting a drawing on a frame
            4. Directory structure
            5. Making a frame
          3. Sneaking Away from the Original Code
            1. Default access
            2. Crawling back into the package
          4. Protected Access
            1. Putting non-subclasses in the same package
          5. Access Modifiers for Java Classes
            1. Public classes
            2. Nonpublic classes
        6. Chapter 15: Responding to Keystrokes and Mouse Clicks
          1. Go On . . . Click That Button
            1. Events and event handling
            2. The Java interface
            3. Threads of execution
            4. The keyword this
            5. Inside the actionPerformed method
            6. The serialVersionUID
          2. Responding to Things Other Than Button Clicks
          3. Creating Inner Classes
        7. Chapter 16: Writing Java Applets
          1. Applets 101
            1. Waiting to be called
            2. A public class
            3. The Java API (again)
          2. Making Things Move
            1. The methods in an applet
            2. What to put into all these methods
          3. Responding to Events in an Applet
        8. Chapter 17: Using Java Database Connectivity
          1. JDBC and Java DB
          2. Creating Data
            1. Using SQL commands
            2. Connecting and disconnecting
          3. Retrieving Data
      6. Part V: The Part of Tens
        1. Chapter 18: Ten Ways to Avoid Mistakes
          1. Putting Capital Letters Where They Belong
          2. Breaking Out of a switch Statement
          3. Comparing Values with a Double Equal Sign
          4. Adding Components to a GUI
          5. Adding Listeners to Handle Events
          6. Defining the Required Constructors
          7. Fixing Non-Static References
          8. Staying within Bounds in an Array
          9. Anticipating Null Pointers
          10. Helping Java Find Its Files
        2. Chapter 19: Ten Websites for Java
          1. This Book’s Website
          2. The Horse’s Mouth
          3. Finding News, Reviews, and Sample Code
          4. Looking for Java Jobs
          5. Everyone’s Favorite Sites
      7. About the Author
      8. Cheat Sheet
      9. More Dummies Products