for dummies store - a Wiley Brand
  • Print
  • Share
Java All-in-One For Dummies, 5th Edition (1119247799) cover image

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

ISBN: 978-1-119-24779-1
Paperback
960 pages
May 2017
US $39.99 Add to Cart

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

Creating a Layout Pane 574

Making a Scene 576

Setting the Stage 576

Examining the Click Counter Program 577

Chapter 2: Handling Events 583

Examining Events 584

Handling Events 585

Implementing the EventHandler Interface 587

Handling Events with Inner Classes 591

Handling Events with Anonymous Inner Classes 593

Using Lambda Expressions to Handle Events 596

Chapter 3: Setting the Stage and Scene Layout 603

Examining the Stage Class 604

Examining the Scene Class 607

Switching Scenes 609

Creating an Alert Box 613

Exit, Stage Right 618

Chapter 4: Using Layout Panes to Arrange Your Scenes 625

Working with Layout Panes 626

Using the HBox Layout 628

Spacing Things Out 630

Adding Space with Margins 632

Adding Space by Growing Nodes 633

Using the VBox Layout 635

Aligning Nodes in a Layout Pane 637

Making Nodes the Same Width 638

Using the Flow Layout 639

Using the Border Layout 643

Using the GridPane Layout 645

Chapter 5: Getting Input from the User 659

Using Text Fields 660

Validating Numeric Data 667

Using Check Boxes 668

Using Radio Buttons 671

Looking at a Pizza Order Application 673

Chapter 6: Choosing from a List 681

Using Choice Boxes 681

Working with Observable Lists 685

Listening for Selection Changes 688

Using Combo Boxes 690

Using List Views 694

Using Tree Views 696

Book 7: Web Programming 707

Chapter 1: Using Java Web Start 709

Looking at a Simple JavaFX Program 709

Understanding Java Web Start 712

Creating a JNLP File 713

Creating an HTML File to Launch a Java Application 715

Uploading the Java Web Start Files to Your Web Server 716

Launching the ClickMe Application Using Java Web Start 717

Creating an Exception to Allow Java Web Start Applications to Run 718

Chapter 2: Creating Servlets 721

Understanding Servlets 721

Using Tomcat 723

Creating a Simple Servlet 726

Running a Servlet 730

Improving the HelloWorld Servlet 730

Getting Input from the User 732

Using Classes in a Servlet 735

Chapter 3: Using JavaServer Pages 741

Understanding JavaServer Pages 742

Using Page Directives 743

Using Expressions 744

Using Scriptlets 746

Using Declarations 749

Using Classes 751

Chapter 4: Using JavaBeans 757

Getting to Know JavaBeans 757

Looking Over a Sample Bean 759

Using Beans with JSP Pages 761

Scoping Your Beans 767

Book 8: Files and Databases 775

Chapter 1: Working with Files 777

Using the File Class 777

Using Command-Line Parameters 784

Choosing Files in a Swing Application 785

Using Path Objects 792

Using a File Visitor to Walk a File Tree 795

Chapter 2: Working with File Streams 799

Understanding Streams 800

Reading Character Streams 801

Writing Character Streams 807

Reading Binary Streams 813

Writing Binary Streams 820

Chapter 3: Database for $100, Please 827

Defining a Relational Database 828

Understanding (and Pronouncing) SQL 828

Introducing SQL Statements 829

Creating a SQL Database 829

Querying a Database 832

Updating and Deleting Rows 839

Chapter 4: Using JDBC to Connect to a Database 845

Setting Up a Driver 845

Connecting to a Database 846

Querying a Database 848

Updating SQL Data 855

Using an Updatable RowSet Object 856

Chapter 5: Working with XML 861

Defining XML 861

Using a DTD 865

Processing XML in Two Ways: DOM and SAX 868

Reading a DOM Document 869

Reading DOM Nodes 872

Putting It All Together: A Program That Lists Movies 877

Index 881

  • Print
  • Share