Java All-in-One For Dummies

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

A beginning coder’s resource for learning the most popular coding language With Java All-in-One For Dummies, you get 8 books in one, for the most well-rounded Java knowledge on the market. Updated for Java 19, this book includes all the major changes to the programming language, so you won’t fall behind. Start by learning the basics of Java―you can do it, even if you’ve never written a line of code in your life. Then go in-depth, with all the info you need on object-oriented programming, Java FX, Java web development, and beyond. Grab a hot cup of java and settle in to learn some Java, with friendly For Dummies guidance! • Learn the basics of computer programming and get started with the Java language • Master strings, arrays, and collections • Discover the most recent Java updates and the latest in programming techniques • Launch or further your career as a coder with easy-to-follow instruction This is the go-to Dummies guide for future and current coders who need an all-inclusive guide Java to take their knowledge to the next level.

Author(s): Doug Lowe
Series: For Dummies
Edition: 7
Publisher: Wiley
Year: 2023

Language: English
Commentary: Publisher's PDF
Pages: 912
City: Hoboken, NJ
Tags: Algorithms; Data Structures; Java; For Dummies; Object-Oriented Programming; Recursion; Search Algorithms; JavaFX; Sorting Algorithms; Elementary

Title Page
Copyright Page
Table of Contents
Introduction
About This Book
Foolish Assumptions
Icons Used in This Book
Beyond the Book
Where to Go from Here
1 Java Basics
Chapter 1 Welcome to Java
What Is Java, and Why Is It So Great?
Platform independence
Object orientation
The Java API
Important Features of the Java Language
Type checking
Exception handling
Java Version Insanity
What’s in a Name?
Chapter 2 Installing and Using Java Tools
Downloading and Installing the Java Development Kit
Downloading the JDK
Installing the JDK
Perusing the JDK folders
Setting the JAVA_HOME and path variables
Confirming Your Java Version
Using Java’s Command-Line Tools
Compiling a program
Compiling more than one file
Using Java compiler options
Running a Java program
Understanding error messages
Specifying options
Using the javap command
Using Java Documentation
Chapter 3 Working with TextPad
Downloading and Installing TextPad
Editing Source Files
Compiling a Program
Running a Java Program
2 Programming Basics
Chapter 1 Java Programming Basics
Looking at the Venerable Hello, World! Program
Dealing with Keywords
Working with Statements
Types of statements
White space
Working with Blocks
Creating Identifiers
Crafting Comments
End-of-line comments
Traditional comments
JavaDoc comments
Introducing Object-Oriented Programming
Understanding classes and objects
Understanding static methods
Creating an object from a class
Viewing a program that uses an object
The HelloApp2 class
The Greeter class
So what’s the difference?
Importing Java API Classes
Chapter 2 Working with Variables and Data Types
Declaring Variables
Declaring two or more variables in one statement
Declaring class variables
Declaring instance variables
Declaring local variables
Initializing Variables
Initializing variables with assignment statements
Initializing variables with initializers
Using Final Variables (Constants)
Working with Primitive Data Types
Integer types
Floating-point types
The char type
The Boolean type
Using wrapper classes
Using reference types
Using inferred variable types
Working with Strings
Declaring and initializing strings
Combining strings
Converting primitives to strings
Converting strings to primitives
Converting and Casting Numeric Data
Automatic conversions
Type casting
Thinking Inside the Box
Understanding Scope
Shadowing Variables
Printing Data with System.out
Using standard input and output streams
Using System.out and System.err
Getting Input with the Scanner Class
Importing the Scanner class
Declaring and creating a Scanner object
Getting input
Getting Input with the JOptionPane Class
Using enum to Create Your Own Data Types
Chapter 3 Working with Numbers and Expressions
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Using constants of the Math class
Working with mathematical functions
Creating random numbers
Rounding functions
Formatting Numbers
Recognizing Weird Things about Java Math
Integer overflow
Floating-point weirdness
Division by zero
Chapter 4 Making Choices
Using Simple Boolean Expressions
Using if Statements
Simple if statements
if-else statements
Nested if statements
else-if statements
Using Mr. Spock’s Favorite Operators (Logical Ones, of Course)
Using the ! operator
Using the & and && operators
Using the | and || operators
Using the ^ operator
Combining logical operators
Using the Conditional Operator
Comparing Strings
Chapter 5 Going Around in Circles (or, Using Loops)
Using Your Basic while Loop
The while statement
A counting loop
Breaking Out of a Loop
Looping Forever
Letting the user decide when to quit
Letting the user decide in another way
Using the continue Statement
Running do-while Loops
Validating Input from the User
Using the Famous for Loop
Understanding the formal format of the for loop
Scoping out the counter variable
Counting even numbers
Counting backward
Using for loops without bodies
Ganging up your expressions
Omitting expressions
Breaking and continuing your for loops
Nesting Your Loops
A simple nested for loop
A guessing game
Chapter 6 Pulling a Switcheroo
Battling else-if Monstrosities
Viewing an example else-if program
Creating a better version of the example program
Using the switch Statement
Viewing a boring switch example, complete with flowchart
Putting if statements inside switch statements
Creating Character Cases
Matching Two or More Values in a Single Case Group
Intentionally Leaving Out a Break Statement
Switching with Strings
Assigning a Value with a Switch Statement
Chapter 7 Adding Some Methods to Your Madness
The Joy of Methods
The Basics of Making Methods
An example
Another example
Methods That Return Values
Declaring the method’s return type
Using the return statement to return the value
Using a method that returns a type
You gotta have a proper return statement
Trying another version of the guessing-game program
Methods That Take Parameters
Declaring parameters
Scoping out parameters
Understanding pass-by-value
Trying yet another version of the guessing-game program
Chapter 8 Handling Exceptions
Understanding Exceptions
Witnessing an exception
Finding the culprit
Catching Exceptions
A simple example
Another example
Handling Exceptions with a Preemptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Viewing the catch-or-throw compiler error
Catching FileNotFoundException
Throwing the FileNotFoundException
Throwing an exception from main
Swallowing exceptions
Throwing Your Own Exceptions
Using the try-with-resources Statement
3 Object-Oriented Programming
Chapter 1 Understanding Object-Oriented Programming
What Is Object-Oriented Programming?
Understanding Objects
Objects have identity
Objects have type
Objects have state
Objects have behavior
Understanding the Life Cycle of an Object
Working with Related Classes
Inheritance
Interfaces
Designing a Program with Objects
Diagramming Classes with UML
Drawing classes
Drawing arrows
Chapter 2 Making Your Own Classes
Declaring a Class
Picking class names
Knowing what goes in the class body
Seeing where classes live
Working with Members
Understanding fields
Understanding instance methods
Understanding visibility
Using Getters and Setters
Overloading Methods
Creating Constructors
Creating basic constructors
Creating default constructors
Calling other constructors
Finding More Uses for the this Keyword
Using Initializers
Using Records
Chapter 3 Working with Statics
Understanding Static Fields and Methods
Working with Static Fields
Using Static Methods
Counting Instances
Preventing Instances
Using Static Initializers
Chapter 4 Using Subclasses and Inheritance
Introducing Inheritance
Motorcycles, trains, and automobiles
Game play
A businesslike example
Inheritance hierarchies
Creating Subclasses
Overriding Methods
Protecting Your Members
Using the this and super Keywords in Your Subclasses
Understanding Inheritance and Constructors
Using the final Keyword
Final methods
Final classes
Casting Up and Down
Determining an Object’s Type
Poly What?
Creating Custom Exceptions
Tracing the Throwable hierarchy
Creating an exception class
Throwing a custom exception
Chapter 5 Using Abstract Classes and Interfaces
Using Abstract Classes
Using Interfaces
Creating a basic interface
Implementing an interface
Using an interface as a type
More Things You Can Do with Interfaces
Adding fields to an interface
Extending interfaces
Using interfaces for callbacks
Using Additional Interface Method Types
Two Interfaces That Enable Java Language Features
Sealing Your Classes
Chapter 6 Using the Object and Class Classes
The Mother of All Classes: Object
Every object is an Object
Object as a type
Methods of the Object class
Primitives aren’t objects
The toString Method
Using toString
Overriding toString
The equals Method
Using equals
Overriding the equals method
The clone Method
Implementing the clone method
Using clone to create a shallow copy
Creating deep copies
The Class Class
Using the instanceof Operator
Chapter 7 Using Inner Classes and Anonymous Classes
Declaring Inner Classes
Understanding inner classes
Viewing an example
Using Static Inner Classes
Using Anonymous Inner Classes
Creating an anonymous class
Creating a program with an anonymous class
Chapter 8 Working with Packages and the Java Module System
Working with Packages
Importing classes and packages
Creating your own packages
An example
Putting Your Classes in a JAR File
jar command-line options
Archiving a package
Adding a jar to your classpath
Running a program directly from an archive
Using Javadoc to Document Your Classes
Adding Javadoc comments
Using the javadoc command
Viewing Javadoc pages
Using the Java Module System
Understanding modules
The module-info.java file
Setting up folders for a module
Compiling a module
Creating a modular JAR file
Running a modular JAR file
4 Strings and Other Data Types
Chapter 1 Working with Strings
Reviewing Strings
Using the String Class
Finding the length of a string
Making simple string modifications
Extracting characters from a string
Extracting substrings from a string
Splitting a string
Replacing parts of a string
Stripping a string
Determining Whether a String Is Empty
Using the StringBuilder and StringBuffer Classes
Creating a StringBuilder object
Using StringBuilder methods
Viewing a StringBuilder example
Using the CharSequence Interface
Using Text Blocks
Chapter 2 Using Regular Expressions
Creating a Program for Experimenting with Regular Expressions
Performing Basic Character Matching
Matching single characters
Using predefined character classes
Using custom character classes
Using ranges
Using negation
Matching multiple characters
Using escapes
Using parentheses to group characters
Using the pipe symbol
Using Regular Expressions in Java Programs
Understanding the String problem
Using regular expressions with the String class
Using the Pattern and Matcher classes
Chapter 3 Working with Dates and Times
Pondering How Time Is Represented
Picking the Right Date and Time Class for Your Application
Using the now Method to Create a Date-Time Object
Using the parse Method to Create a Date-Time Object
Using the of Method to Create a Date-Time Object
Using the Month enumeration
Using the ZoneId class
Using the ZoneOffset class
Looking Closer at the LocalDate Class
Extracting Information about a Date
Comparing Dates
Calculating with Dates
Formatting Dates
Looking at a Fun Birthday Calculator
Chapter 4 Using the BigDecimal Class
Seeing Why Java Can’t Add
Double trouble
Another example
BigDecimal to the Rescue!
Creating BigDecimal Objects
Doing BigDecimal Arithmetic
Rounding BigDecimal Values
The fundamentals of scale
How to round
Comparing BigDecimal Values
Converting BigDecimals to Strings
Revisiting Sales Tax
5 Data Structures
Chapter 1 Introducing Data Structures
Imagining Models of Computation
Musing about word RAM memory
Considering the CPU in the word RAM model
Defining Data Structures
Quantifying Performance
Analyzing Arrays
Looking at Linked Lists
Doubling Down with Doubly Linked Lists
Surmising Stacks, Queues, and Deques
Musing about Maps
Checking Out Hash Maps
Tackling Trees
Checking Out Binary Trees
Chapter 2 Using Arrays
Understanding Arrays
Creating Arrays
Initializing an Array
Using for Loops with Arrays
Solving Homework Problems with Arrays
Using the Enhanced for Loop
Using Arrays with Methods
Using Varargs
Using Two-Dimensional Arrays
Creating a two-dimensional array
Accessing two-dimensional array elements
Initializing a two-dimensional array
Using jagged arrays
Going beyond two dimensions
Working with a Fun but Complicated Example: A Chessboard
Using the Arrays Class
Filling an array
Copying an array
Sorting an array
Searching an array
Comparing arrays
Converting arrays to strings
Chapter 3 Using the ArrayList Class
Understanding the ArrayList Class
Creating an ArrayList Object
Adding Elements
Accessing Elements
Printing an ArrayList
Using an Iterator
Updating Elements
Deleting Elements
Chapter 4 Using the LinkedList Class
Understanding the LinkedList Class
Creating a LinkedList
Adding Items to a LinkedList
Retrieving Items from a LinkedList
Updating LinkedList Items
Removing LinkedList Items
Chapter 5 Creating Generic Collection Classes
Why Generics?
Creating a Generic Class
A Generic Stack Class
Using Wildcard-Type Parameters
A Generic Queue Class
Chapter 6 Using Maps and Trees
Mastering Maps
Using the HashMap Class
Creating a hash map
Adding elements to a hash map
Retrieving elements from a hash map
Replacing entries from a hash map
Removing Entries from a Hash Map
Treating a hash map as a collection
Using lambda expressions with maps
Using the TreeMap Class
Introducing red-black trees
Looking at TreeMap methods
Creating and using a TreeMap
More ways to play with a TreeMap
6 Algorithms
Chapter 1 Introducing Algorithms
What Is an Algorithm?
Classifying Algorithms
Brute-force algorithms
Divide-and-conquer algorithms
Backtracking algorithms
Dynamic algorithms
Some Fun Algorithm Challenges
Fizz buzz
Roman numerals
Spelling out dollar amounts
Determining if a tic-tac-toe game is over
Scheduling a tournament
Chapter 2 Using Recursion
Calculating the Classic Factorial Example
The nonrecursive solution
The recursive solution
Displaying Directories
Playing the Towers of Hanoi
Chapter 3 Sorting
Looking at the Bubble Sort Algorithm
Introducing the Quicksort Algorithm
Using the sort method
Using the partition method
Putting it all together
Chapter 4 Searching
Creating a Data Structure Worth Searching
Looking at Linear Searching
Using a Binary Search
7 Programming Techniques
Chapter 1 Programming Threads
Understanding Threads
Creating a Thread
Understanding the Thread class
Extending the Thread class
Creating and starting a thread
Implementing the Runnable Interface
Using the Runnable interface
Creating a class that implements Runnable
Using the CountDownApp class
Creating Threads That Work Together
Using an Executor
Synchronizing Methods
Creating a Lock
Coping with Threadus Interruptus
Finding out whether you’ve been interrupted
Aborting the countdown
Chapter 2 Using Functional Programming and Lambda Expressions
Introducing Functional Programming
Introducing Functional Interfaces
Using Lambda Expressions
Passing Parameters via Lambda Expressions
Using Block Lambda Expressions
Using the java.util.function Package
Chapter 3 Consuming Web Services with HttpClient
Introducing Web Services
Understanding HTTP
Diving into HTTP
HTTP clients and servers
Resources
MIME
URIs and URLs
Sessions
Messages
Methods
Looking at a simple HTTP exchange
Getting Started with Java’s HTTP Client Library
HttpClient
HttpRequest
HttpResponse
Using the send method
Putting It All Together
The HTTP Tester Program
8 JavaFX
Chapter 1 Hello, JavaFX!
Perusing the Possibilities of JavaFX
Getting Ready to Run JavaFX
Looking at a Simple JavaFX Program
Importing JavaFX Packages
Extending the Application Class
Launching the Application
Overriding the start Method
Creating a Button
Handling an Action Event
Creating a Layout Pane
Making a Scene
Setting the Stage
Examining the Click Counter Program
Chapter 2 Handling Events
Examining Events
Handling Events
Implementing the EventHandler Interface
Handling Events with Inner Classes
Handling Events with Anonymous Inner Classes
Using Lambda Expressions to Handle Events
Chapter 3 Setting the Stage and Scene Layout
Examining the Stage Class
Examining the Scene Class
Switching Scenes
Creating an Alert Box
Exit, Stage Right
Creating a Close button
Handling the CloseRequest event
Putting it all together
Chapter 4 Using Layout Panes to Arrange Your Scenes
Working with Layout Panes
Introducing five JavaFX layout panes
Creating layout panes
Combining layout panes
Using the HBox Layout
Spacing Things Out
Adding Space with Margins
Adding Space by Growing Nodes
Using the VBox Layout
Aligning Nodes in a Layout Pane
Using the Flow Layout
Using the Border Layout
Using the GridPane Layout
Sketching out a plan
Creating a grid pane
Working with grid pane constraints
Examining a grid pane example
Chapter 5 Getting Input from the User
Using Text Fields
Validating Numeric Data
Using Check Boxes
Using Radio Buttons
Chapter 6 Choosing from a List
Using Choice Boxes
Creating a choice box
Setting a default value
Getting the selected item
Working with Observable Lists
Listening for Selection Changes
Using Combo Boxes
Creating combo boxes
Getting the selected item
Handling combo box events
Using List Views
Creating a list view
Getting the selected items
Using Tree Views
Building a tree
Creating a TreeView control
Getting the selected node
Looking at a complete program that uses a tree view
Index
EULA