Java All-in-One For Dummies, 5th Edition

Book description

Your one-stop guide to programming with Java

If you've always wanted to program with Java but didn't know where to start, this will be the java-stained reference you'll turn to again and again. Fully updated for the JDK 9, this deep reference on the world's most popular programming language is the perfect starting point for building things with Java—and an invaluable ongoing reference as you continue to deepen your knowledge.

Clocking in at over 900 pages, Java All-in-One For Dummies takes the intimidation out of learning Java and offers clear, step-by-step guidance on how to download and install Java tools; work with variables, numbers, expressions, statements, loops, methods, and exceptions; create applets, servlets, and JavaServer pages; handle and organize data; and so much more.

  • Focuses on the vital information that enables you to get up and running quickly with Java
  • Provides details on the new features of JDK 9
  • Shows you how to create simple Swing programs
  • Includes design tips on layout, buttons, and labels

Everything you need to know to program with Java is included in this practical, easy-to-use guide!

Table of contents

    1. Cover
    2. Introduction
      1. About This Book
      2. Foolish Assumptions
      3. Icons Used in This Book
      4. Beyond the Book
      5. Where to Go from Here
    3. Book 1: Java Basics
      1. Chapter 1: Welcome to Java
        1. What Is Java, and Why Is It So Great?
        2. Java versus Other Languages
        3. Important Features of the Java Language
        4. On the Downside: Java’s Weaknesses
        5. Java Version Insanity
        6. What’s in a Name?
      2. Chapter 2: Installing and Using Java Tools
        1. Downloading and Installing the Java Development Kit
        2. Using Java’s Command-Line Tools
        3. Using Java Documentation
      3. Chapter 3: Working with TextPad
        1. Downloading and Installing TextPad
        2. Editing Source Files
        3. Compiling a Program
        4. Running a Java Program
    4. Book 2: Programming Basics
      1. Chapter 1: Java Programming Basics
        1. Looking at the Infamous Hello, World! Program
        2. Dealing with Keywords
        3. Working with Statements
        4. Working with Blocks
        5. Creating Identifiers
        6. Crafting Comments
        7. Introducing Object-Oriented Programming
        8. Importing Java API Classes
      2. Chapter 2: Working with Variables and Data Types
        1. Declaring Variables
        2. Initializing Variables
        3. Using Final Variables (Constants)
        4. Working with Primitive Data Types
        5. Working with Strings
        6. Converting and Casting Numeric Data
        7. Thinking Inside the Box
        8. Understanding Scope
        9. Shadowing Variables
        10. Printing Data with System.out
        11. Getting Input with the Scanner Class
        12. Getting Input with the JOptionPane Class
        13. Using enum to Create Your Own Data Types
      3. Chapter 3: Working with Numbers and Expressions
        1. Working with Arithmetic Operators
        2. Dividing Integers
        3. Combining Operators
        4. Using the Unary Plus and Minus Operators
        5. Using Increment and Decrement Operators
        6. Using the Assignment Operator
        7. Using Compound Assignment Operators
        8. Using the Math Class
        9. Formatting Numbers
        10. Recognizing Weird Things about Java Math
      4. Chapter 4: Making Choices
        1. Using Simple Boolean Expressions
        2. Using if Statements
        3. Using Mr. Spock’s Favorite Operators (Logical Ones, of Course)
        4. Using the Conditional Operator
        5. Comparing Strings
      5. Chapter 5: Going Around in Circles (Or, Using Loops)
        1. Using Your Basic while Loop
        2. Breaking Out of a Loop
        3. Looping Forever
        4. Using the continue Statement
        5. Running do-while Loops
        6. Validating Input from the User
        7. Using the Famous for Loop
        8. Nesting Your Loops
      6. Chapter 6: Pulling a Switcheroo
        1. Battling else-if Monstrosities
        2. Using the switch Statement
        3. Creating Character Cases
        4. Intentionally Leaving Out a Break Statement
        5. Switching with Strings
      7. Chapter 7: Adding Some Methods to Your Madness
        1. The Joy of Methods
        2. The Basics of Making Methods
        3. Methods That Return Values
        4. Methods That Take Parameters
      8. Chapter 8: Handling Exceptions
        1. Understanding Exceptions
        2. Catching Exceptions
        3. Handling Exceptions with a Preemptive Strike
        4. Catching All Exceptions at Once
        5. Displaying the Exception Message
        6. Using a finally Block
        7. Handling Checked Exceptions
        8. Throwing Your Own Exceptions
        9. Catching Multiple Exceptions
    5. Book 3: Object-Oriented Programming
      1. Chapter 1: Understanding Object-Oriented Programming
        1. What Is Object-Oriented Programming?
        2. Understanding Objects
        3. Understanding the Life Cycle of an Object
        4. Working with Related Classes
        5. Designing a Program with Objects
        6. Diagramming Classes with UML
      2. Chapter 2: Making Your Own Classes
        1. Declaring a Class
        2. Working with Members
        3. Using Getters and Setters
        4. Overloading Methods
        5. Creating Constructors
        6. Finding More Uses for the this Keyword
        7. Using Initializers
      3. Chapter 3: Working with Statics
        1. Understanding Static Fields and Methods
        2. Working with Static Fields
        3. Using Static Methods
        4. Counting Instances
        5. Preventing Instances
        6. Using Static Initializers
      4. Chapter 4: Using Subclasses and Inheritance
        1. Introducing Inheritance
        2. Creating Subclasses
        3. Overriding Methods
        4. Protecting Your Members
        5. Using this and super in Your Subclasses
        6. Understanding Inheritance and Constructors
        7. Using final
        8. Casting Up and Down
        9. Determining an Object’s Type
        10. Poly What?
        11. Creating Custom Exceptions
      5. Chapter 5: Using Abstract Classes and Interfaces
        1. Using Abstract Classes
        2. Using Interfaces
        3. More Things You Can Do with Interfaces
        4. Using Default Methods
      6. Chapter 6: Using the Object and Class Classes
        1. The Mother of All Classes: Object
        2. The toString Method
        3. The equals Method
        4. The clone Method
        5. The Class Class
      7. Chapter 7: Using Inner Classes, Anonymous Classes, and Lambda Expressions
        1. Declaring Inner Classes
        2. Using Static Inner Classes
        3. Using Anonymous Inner Classes
        4. Using Lambda Expressions
      8. Chapter 8: Working with Packages and the New Java Module System
        1. Working with Packages
        2. Putting Your Classes in a JAR File
        3. Using JavaDoc to Document Your Classes
        4. Using the Java Module System
    6. Book 4: Strings, Arrays, and Collections
      1. Chapter 1: Working with Strings
        1. Reviewing Strings
        2. Using the String Class
        3. Using the StringBuilder and StringBuffer Classes
        4. Using the CharSequence Interface
      2. Chapter 2: Using Arrays
        1. Understanding Arrays
        2. Creating Arrays
        3. Initializing an Array
        4. Using for Loops with Arrays
        5. Solving Homework Problems with Arrays
        6. Using the Enhanced for Loop
        7. Using Arrays with Methods
        8. Using Two-Dimensional Arrays
        9. Working with a Fun but Complicated Example: A Chessboard
        10. Using the Arrays Class
      3. Chapter 3: Using the ArrayList Class
        1. Understanding the ArrayList Class
        2. Creating an ArrayList Object
        3. Adding Elements
        4. Accessing Elements
        5. Printing an ArrayList
        6. Using an Iterator
        7. Updating Elements
        8. Deleting Elements
      4. Chapter 4: Using the LinkedList Class
        1. Understanding the LinkedList Class
        2. Creating a LinkedList
        3. Adding Items to a LinkedList
        4. Retrieving Items from a LinkedList
        5. Updating LinkedList Items
        6. Removing LinkedList Items
      5. Chapter 5: Creating Generic Collection Classes
        1. Why Generics?
        2. Creating a Generic Class
        3. A Generic Stack Class
        4. Using Wildcard-Type Parameters
        5. A Generic Queue Class
        6. Using the Diamond Operator
      6. Chapter 6: Using Bulk Data Operations with Collections
        1. Looking At a Basic Bulk Data Operation
        2. Looking Closer at the Stream Interface
        3. Using Parallel Streams
    7. Book 5: Programming Techniques
      1. Chapter 1: Programming Threads
        1. Understanding Threads
        2. Creating a Thread
        3. Implementing the Runnable Interface
        4. Creating Threads That Work Together
        5. Using an Executor
        6. Synchronizing Methods
        7. Creating a Lock
        8. Coping with Threadus Interruptus
      2. Chapter 2: Using Regular Expressions
        1. Creating a Program for Experimenting with Regular Expressions
        2. Performing Basic Character Matching
        3. Using Regular Expressions in Java Programs
      3. Chapter 3: Using Recursion
        1. Calculating the Classic Factorial Example
        2. Displaying Directories
        3. Writing Your Own Sorting Routine
      4. Chapter 4: Working with Dates and Times
        1. Pondering How Time is Represented
        2. Picking the Right Date and Time Class for Your Application
        3. Using the now Method to Create a Date-Time Object
        4. Using the parse Method to Create a Date-Time Object
        5. Using the of Method to Create a Date-Time Object
        6. Looking Closer at the LocalDate Class
        7. Extracting Information About a Date
        8. Comparing Dates
        9. Calculating with Dates
        10. Formatting Dates
        11. Looking at a Fun Birthday Calculator
    8. Book 6: JavaFX
      1. Chapter 1: Hello, JavaFX!
        1. Perusing the Possibilities of JavaFX
        2. Looking at a Simple JavaFX Program
        3. Importing JavaFX Packages
        4. Extending the Application Class
        5. Launching the Application
        6. Overriding the start Method
        7. Creating a Button
        8. Handling an Action Event
        9. Creating a Layout Pane
        10. Making a Scene
        11. Setting the Stage
        12. Examining the Click Counter Program
      2. Chapter 2: Handling Events
        1. Examining Events
        2. Handling Events
        3. Implementing the EventHandler Interface
        4. Handling Events with Inner Classes
        5. Handling Events with Anonymous Inner Classes
        6. Using Lambda Expressions to Handle Events
      3. Chapter 3: Setting the Stage and Scene Layout
        1. Examining the Stage Class
        2. Examining the Scene Class
        3. Switching Scenes
        4. Creating an Alert Box
        5. Exit, Stage Right
      4. Chapter 4: Using Layout Panes to Arrange Your Scenes
        1. Working with Layout Panes
        2. Using the HBox Layout
        3. Spacing Things Out
        4. Adding Space with Margins
        5. Adding Space by Growing Nodes
        6. Using the VBox Layout
        7. Aligning Nodes in a Layout Pane
        8. Making Nodes the Same Width
        9. Using the Flow Layout
        10. Using the Border Layout
        11. Using the GridPane Layout
      5. Chapter 5: Getting Input from the User
        1. Using Text Fields
        2. Validating Numeric Data
        3. Using Check Boxes
        4. Using Radio Buttons
        5. Looking at a Pizza Order Application
      6. Chapter 6: Choosing from a List
        1. Using Choice Boxes
        2. Working with Observable Lists
        3. Listening for Selection Changes
        4. Using Combo Boxes
        5. Using List Views
        6. Using Tree Views
    9. Book 7: Web Programming
      1. Chapter 1: Using Java Web Start
        1. Looking at a Simple JavaFX Program
        2. Understanding Java Web Start
        3. Creating a JNLP File
        4. Creating an HTML File to Launch a Java Application
        5. Uploading the Java Web Start Files to Your Web Server
        6. Launching the ClickMe Application Using Java Web Start
        7. Creating an Exception to Allow Java Web Start Applications to Run
      2. Chapter 2: Creating Servlets
        1. Understanding Servlets
        2. Using Tomcat
        3. Creating a Simple Servlet
        4. Running a Servlet
        5. Improving the HelloWorld Servlet
        6. Getting Input from the User
        7. Using Classes in a Servlet
      3. Chapter 3: Using JavaServer Pages
        1. Understanding JavaServer Pages
        2. Using Page Directives
        3. Using Expressions
        4. Using Scriptlets
        5. Using Declarations
        6. Using Classes
      4. Chapter 4: Using JavaBeans
        1. Getting to Know JavaBeans
        2. Looking Over a Sample Bean
        3. Using Beans with JSP Pages
        4. Scoping Your Beans
    10. Book 8: Files and Databases
      1. Chapter 1: Working with Files
        1. Using the File Class
        2. Using Command-Line Parameters
        3. Choosing Files in a Swing Application
        4. Using Path Objects
        5. Using a File Visitor to Walk a File Tree
      2. Chapter 2: Working with File Streams
        1. Understanding Streams
        2. Reading Character Streams
        3. Writing Character Streams
        4. Reading Binary Streams
        5. Writing Binary Streams
      3. Chapter 3: Database for $100, Please
        1. Defining a Relational Database
        2. Understanding (and Pronouncing) SQL
        3. Introducing SQL Statements
        4. Creating a SQL Database
        5. Querying a Database
        6. Updating and Deleting Rows
      4. Chapter 4: Using JDBC to Connect to a Database
        1. Setting Up a Driver
        2. Connecting to a Database
        3. Querying a Database
        4. Updating SQL Data
        5. Using an Updatable RowSet Object
      5. Chapter 5: Working with XML
        1. Defining XML
        2. Using a DTD
        3. Processing XML in Two Ways: DOM and SAX
        4. Reading a DOM Document
        5. Reading DOM Nodes
        6. Putting It All Together: A Program That Lists Movies
    11. About the Author
    12. Advertisement Page
    13. Connect with Dummies
    14. End User License Agreement

Product information

  • Title: Java All-in-One For Dummies, 5th Edition
  • Author(s): Doug Lowe
  • Release date: May 2017
  • Publisher(s): For Dummies
  • ISBN: 9781119247791