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

Book description

Java—from first steps to first apps

Knowing Java is a must-have programming skill for any programmer. It’s used in a wide array of programming projects—from enterprise apps and mobile apps to big data, scientific, and financial uses. The language regularly ranks #1 in surveys of the most popular language based on number of developers, lines of code written, and real-world usage. It’s also the language of choice in AP Computer Science classes taught in the U.S. 

This guide provides an easy-to-follow path from understanding the basics of writing Java code to applying those skills to real projects. Split into eight minibooks covering core aspects of Java, the book introduces the basics of the Java language and object-oriented programming before setting you on the path to building web apps and databases.

• Get up to speed on Java basics

• Explore object-oriented programming

• Learn about strings, arrays, and collections

• Find out about files and databases

Step-by-step instructions are provided to ensure that you don't get lost at any point along the way.

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
      6. Enhanced Switch Features with Java 13
    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
  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
      8. Using Records
    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 Additional Interface Method Types
    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 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 Varargs
      9. Using Two-Dimensional Arrays
      10. Working with a Fun but Complicated Example: A Chessboard
      11. 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. 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
    5. Chapter 5: IoT Programming with Raspberry Pi
      1. Introducing the Raspberry Pi
      2. Setting Up a Raspberry Pi
      3. Installing Java on a Raspberry Pi
      4. Installing the Pi4J Library
      5. Configuring the Geany Integrated Development Environment for Java Development
      6. Examining GPIO Ports
      7. Connecting an LED to a GPIO Port
      8. Building a Raspberry Pi LED Circuit
      9. Examining the Pi4J Library
      10. Importing GPIO Types
      11. Instantiating a GpioController
      12. Provisioning GPIO Pins
      13. Controlling the Pin State
      14. The Morse Code Program
      15. The Cylon Eyes Program
      16. Working with Input Pins
      17. Running the Button Switcher Program
      18. Finding a Better Way to Handle Input Events
  8. Book 6: JavaFX
    1. Chapter 1: Hello, JavaFX!
      1. Perusing the Possibilities of JavaFX
      2. Getting Ready to Run JavaFX
      3. Looking at a Simple JavaFX Program
      4. Importing JavaFX Packages
      5. Extending the Application Class
      6. Launching the Application
      7. Overriding the start Method
      8. Creating a Button
      9. Handling an Action Event
      10. Creating a Layout Pane
      11. Making a Scene
      12. Setting the Stage
      13. 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. Using the Flow Layout
      9. Using the Border Layout
      10. 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
    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: 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
    2. Chapter 2: Using JavaServer Pages
      1. Understanding JavaServer Pages
      2. Using UEL Expressions
      3. Looking at Core Tags
      4. Formatting Numbers
      5. Considering the Controller Servlet
      6. The ListMovies Application Meets JSP
    3. Chapter 3: Using JavaBeans
      1. Getting to Know JavaBeans
      2. Looking Over a Sample Bean
      3. Using Beans with JSP Pages
      4. Scoping Your Beans
    4. Chapter 4: Using HttpClient
      1. Understanding HTTP
      2. Getting Started with Java’s HTTP Client Library
      3. Putting It All Together
      4. The HTTP Tester Program
  10. Index
  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, 6th Edition
  • Author(s): Doug Lowe
  • Release date: September 2020
  • Publisher(s): For Dummies
  • ISBN: 9781119680451