Introduction 1 About This Book 2 Foolish Assumptions 2 Icons Used in This Book 3 Beyond the Book 4 Where to Go from Here 4 Book 1: Java Basics 5 Chapter 1: Welcome to Java 7 What Is Java, and Why Is It So Great? 8 Java versus Other Languages 12 Important Features of the Java Language 13 On the Downside: Java''s Weaknesses 16 Java Version Insanity 17 What''s in a Name? 19 Chapter 2: Installing and Using Java Tools 21 Downloading and Installing the Java Development Kit 22 Using Java''s Command-Line Tools 26 Using Java Documentation 32 Chapter 3: Working with TextPad 35 Downloading and Installing TextPad 35 Editing Source Files 36 Compiling a Program 39 Running a Java Program 40 Book 2: Programming Basics 43 Chapter 1: Java Programming Basics 45 Looking at the Infamous Hello, World! Program 46 Dealing with Keywords 49 Working with Statements 51 Working with Blocks 53 Creating Identifiers 55 Crafting Comments 55 Introducing Object-Oriented Programming 57 Importing Java API Classes 63 Chapter 2: Working with Variables and Data Types 65 Declaring Variables 66 Initializing Variables 70 Using Final Variables (Constants) 72 Working with Primitive Data Types 73 Working with Strings 82 Converting and Casting Numeric Data 85 Thinking Inside the Box 87 Understanding Scope 87 Shadowing Variables 89 Printing Data with System.out 90 Getting Input with the Scanner Class 92 Getting Input with the JOptionPane Class 96 Using enum to Create Your Own Data Types 97 Chapter 3: Working with Numbers and Expressions 99 Working with Arithmetic Operators 99 Dividing Integers 102 Combining Operators 104 Using the Unary Plus and Minus Operators 105 Using Increment and Decrement Operators 106 Using the Assignment Operator 108 Using Compound Assignment Operators 110 Using the Math Class 111 Formatting Numbers 121 Recognizing Weird Things about Java Math 124 Chapter 4: Making Choices 129 Using Simple Boolean Expressions 130 Using if Statements 132 Using Mr Spock''s Favorite Operators (Logical Ones, of Course) 141 Using the Conditional Operator 148 Comparing Strings 149 Chapter 5: Going Around in Circles (Or, Using Loops) 151 Using Your Basic while Loop 152 Breaking Out of a Loop 154 Looping Forever 154 Using the continue Statement 157 Running do-while Loops 159 Validating Input from the User 161 Using the Famous for Loop 163 Nesting Your Loops 173 Chapter 6: Pulling a Switcheroo 179 Battling else-if Monstrosities 179 Using the switch Statement 183 Creating Character Cases 186 Intentionally Leaving Out a Break Statement 188 Switching with Strings 191 Chapter 7: Adding Some Methods to Your Madness 193 The Joy of Methods 194 The Basics of Making Methods 195 Methods That Return Values 199 Methods That Take Parameters 206 Chapter 8: Handling Exceptions 213 Understanding Exceptions 214 Catching Exceptions 216 Handling Exceptions with a Preemptive Strike 220 Catching All Exceptions at Once 221 Displaying the Exception Message 223 Using a finally Block 223 Handling Checked Exceptions 226 Throwing Your Own Exceptions 231 Catching Multiple Exceptions 232 Book 3: Object-Oriented Programming 233 Chapter 1: Understanding Object-Oriented Programming 235 What Is Object-Oriented Programming? 235 Understanding Objects 237 Understanding the Life Cycle of an Object 240 Working with Related Classes 241 Designing a Program with Objects 243 Diagramming Classes with UML 244 Chapter 2: Making Your Own Classes 249 Declaring a Class 249 Working with Members 253 Using Getters and Setters 255 Overloading Methods 257 Creating Constructors 259 Finding More Uses for the this Keyword 263 Using Initializers 265 Chapter 3: Working with Statics 267 Understanding Static Fields and Methods 267 Working with Static Fields 269 Using Static Methods 269 Counting Instances 270 Preventing Instances 273 Using Static Initializers 274 Chapter 4: Using Subclasses and Inheritance 277 Introducing Inheritance 277 Creating Subclasses 281 Overriding Methods 283 Protecting Your Members 284 Using this and super in Your Subclasses 284 Understanding Inheritance and Constructors 286 Using final 287 Casting Up and Down 289 Determining an Object''s Type 290 Poly What? 292 Creating Custom Exceptions 294 Chapter 5: Using Abstract Classes and Interfaces 299 Using Abstract Classes 299 Using Interfaces 302 More Things You Can Do with Interfaces 306 Using Default Methods 311 Chapter 6: Using the Object and Class Classes 315 The Mother of All Classes: Object 316 The toString Method 319 The equals Method 322 The clone Method 328 The Class Class 338 Chapter 7: Using Inner Classes, Anonymous Classes, and Lambda Expressions 341 Declaring Inner Classes 342 Using Static Inner Classes 345 Using Anonymous Inner Classes 347 Using Lambda Expressions 351 Chapter 8: Working with Packages and the New Java Module System 353 Working with Packages 354 Putting Your Classes in a JAR File 358 Using JavaDoc to Document Your Classes 363 Using the Java Module System 368 Book 4: Strings, Arrays, and Collections 373 Chapter 1: Working with Strings 375 Reviewing Strings 376 Using the String Class 378 Using the StringBuilder and StringBuffer Classes 387 Using the CharSequence Interface 391 Chapter 2: Using Arrays 393 Understanding Arrays 393 Creating Arrays 394 Initializing an Array 395 Using for Loops with Arrays 396 Solving Homework Problems with Arrays 397 Using the Enhanced for Loop 400 Using Arrays with Methods 401 Using Two-Dimensional Arrays 401 Working with a Fun but Complicated Example: A Chessboard 408 Using the Arrays Class 416 Chapter 3: Using the ArrayList Class 423 Understanding the ArrayList Class 424 Creating an ArrayList Object 427 Adding Elements 428 Accessing Elements 429 Printing an ArrayList 430 Using an Iterator 430 Updating Elements 432 Deleting Elements 434 Chapter 4: Using the LinkedList Class 437 Understanding the LinkedList Class 438 Creating a LinkedList 442 Adding Items to a LinkedList 443 Retrieving Items from a LinkedList 445 Updating LinkedList Items 446 Removing LinkedList Items 447 Chapter 5: Creating Generic Collection Classes 449 Why Generics? 450 Creating a Generic Class 451 A Generic Stack Class 453 Using Wildcard-Type Parameters 457 A Generic Queue Class 458 Using the Diamond Operator 462 Chapter 6: Using Bulk Data Operations with Collections 463 Looking At a Basic Bulk Data Operation 464 Looking Closer at the Stream Interface 467 Using Parallel Streams 470 Book 5: Programming Techniques 473 Chapter 1: Programming Threads 475 Understanding Threads 476 Creating a Thread 477 Implementing the Runnable Interface 480 Creating Threads That Work Together 485 Using an Executor 489 Synchronizing Methods 491 Creating a Lock 496 Coping with Threadus Interruptus 497 Chapter 2: Using Regular Expressions 505 Creating a Program for Experimenting with Regular Expressions 506 Performing Basic Character Matching 509 Using Regular Expressions in Java Programs 519 Chapter 3: Using Recursion 523 Calculating the Classic Factorial Example 523 Displaying Directories 526 Writing Your Own Sorting Routine 530 Chapter 4: Working with Dates and Times 539 Pondering How Time is Represented 540 Picking the Right Date and Time Class for Your Application 541 Using the now Method to Create a Date-Time Object 542 Using the parse Method to Create a Date-Time Object 544 Using the of Method to Create a Date-Time Object 545 Looking Closer at the LocalDate Class 548 Extracting Information About a Date 550 Comparing Dates 551 Calculating with Dates 552 Formatting Dates 554 Looking at a Fun Birthday Calculator 556 Book 6: JavaFX 561 Chapter 1: Hello, JavaFX! 563 Perusing the Possibilities of JavaFX 564 Looking at a Simple JavaFX Program 566 Importing JavaFX Packages 567 Extending the Application Class 568 Launching the Application 569 Overriding the start Method 570 Creating a Button 572 Handling an Action Event 573 Cre.
Java All-In-One for Dummies