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.
Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"
Ideal for working programmers new to Java, this best-selling book guides you through the language features and APIs of Java 21. Through fun, compelling, and realistic examples, authors Marc Loy, Patrick Niemeyer, and Dan Leuck introduce you to Java's fundamentals, including its class libraries, programming techniques, and idioms, with an eye toward building real applications.
This updated sixth edition expands the content to continue covering lambdas and streams, and shows you how to use a functional paradigm in Java. You'll learn about the latest Java features introduced since the book's fifth edition, from JDK 15 through 21. You'll also take a deep dive into virtual threads (introduced as Project Loom in Java 19).
This guide helps you:
Learn the structure of the Java language and Java applications
Write, compile, and execute Java applications
Understand the basics of Java threading and concurrent programming
Learn Java I/O basics, including local files and network resources
Create compelling interfaces with an eye toward usability
Learn how functional features have been integrated in Java
Keep up with Java developments as new versions are released
Author(s): Marc Loy, Patrick Niemeyer, Daniel Leuck Edition: 6 Publisher: O'Reilly Media Year: 2023
Language: English Commentary: Revision History for the Sixth Edition: 2023-08-16: First Release Pages: 549 City: Sebastopol, CA Tags: Java; Java Language Programming; Object-Oriented Programming; Multi-threading Programming; Functional Programming; Network Programming; Generics; Meta-programming
Preface
Who Should Read This Book
New Developments
New in This Edition (Java 15, 16, 17, 18, 19, 20, 21)
Using This Book
Online Resources
Conventions Used in This Book
Using Code Examples
O’Reilly Online Learning
How to Contact Us
Acknowledgments
1. A Modern Language
Enter Java
Java’s Origins
Growing Up
A Virtual Machine
Java Compared with Other Languages
Safety of Design
Simplify, Simplify, Simplify…
Type Safety and Method Binding
Incremental Development
Dynamic Memory Management
Error Handling
Threads
Scalability
Safety of Implementation
The Verifier
Class Loaders
Application and User-Level Security
A Java Road Map
The Past: Java 1.0–Java 20
The Present: Java 21
The Future
Exercises
2. A First Application
Java Tools and Environment
Installing the JDK
Installing IntelliJ IDEA and Creating a Project
Running the Project
Grabbing the Examples
HelloJava
Classes
The main() Method
Classes and Objects
Variables and Class Types
HelloComponent
Inheritance
The JComponent Class
Relationships and Finger-Pointing
Packages and Imports
The paintComponent() Method
HelloJava2: The Sequel
Instance Variables
Constructors
Events
The repaint() Method
Interfaces
Goodbye and Hello Again
Review Questions
Code Exercises
3. Tools of the Trade
JDK Environment
The Java VM
Running Java Applications
System Properties
The Classpath
CLASSPATH on Unix and macOS
CLASSPATH on Windows
CLASSPATH Wildcards
Modules
The Java Compiler
Trying Java
JAR Files
The jar Utility
Tool Wrap-Up
Review Questions
Code Exercises
Advanced Code Exercises
4. The Java Language
Text Encoding
Comments
Javadoc Comments
Annotations
Variables and Constants
Types
Primitive Types
Reference Types
A Word About Strings
Statements and Expressions
Statements
Expressions
Arrays
Array Types
Array Creation and Initialization
Using Arrays
Anonymous Arrays
Multidimensional Arrays
Types and Classes and Arrays, Oh My!
Review Questions
Code Exercises
Advanced Exercises
5. Objects in Java
Classes
Declaring and Instantiating Classes
Accessing Fields and Methods
Static Members
Methods
Local Variables
Shadowing
Static Methods
Initializing Local Variables
Argument Passing and References
Wrappers for Primitive Types
Method Overloading
Object Creation
Constructors
Working with Overloaded Constructors
Object Destruction
Garbage Collection
Packages
Importing Classes
Custom Packages
Member Visibility and Access
Compiling with Packages
Advanced Class Design
Subclassing and Inheritance
Abstract Classes and Methods
Interfaces
Inner Classes
Anonymous Inner Classes
Organizing Content and Planning for Failure
Review Questions
Code Exercises
Advanced Exercises
6. Error Handling
Exceptions
Exceptions and Error Classes
Exception Handling
Bubbling Up
Stack Traces
Checked and Unchecked Exceptions
Throwing Exceptions
try Creep
The finally Clause
try with Resources
Performance Issues
Assertions
Enabling and Disabling Assertions
Using Assertions
Real-World Exceptions
Review Questions
Code Exercises
Advanced Exercises
7. Collections and Generics
Collections
The Collection Interface
Collection Types
The Map Interface
Type Limitations
Containers: Building a Better Mousetrap
Can Containers Be Fixed?
Enter Generics
Talking About Types
“There Is No Spoon”
Erasure
Raw Types
Parameterized Type Relationships
Why Isn’t a List a List