Learning Java, 5th Edition

Book Description

If you’re new to Java—or new to programming—this bestselling book will guide you through the language features and APIs of Java 11 and beyond. With fun, compelling, and realistic examples, authors Marc Loy, Patrick Niemeyer, and Daniel Leuck introduce you to Java fundamentals—including its class libraries, programming techniques, and idioms—with an eye toward building real applications.

  • Learn basic syntax, classes and objects, and other components
  • Develop with Java, using the compiler, interpreter, and other tools
  • Explore Java’s built-in thread facilities and concurrency package
  • Write networked or web-based applications and services
  • Build graphical applications using Java component architecture
  • Explore rich new desktop APIs

Table of Contents

  1. Preface
    1. Who Should Read This Book
    2. New Developments
      1. New in This Edition (Java 11, 12, 13, 14)
    3. Using This Book
    4. Online Resources
    5. Conventions Used in This Book
    6. Using Code Examples
    7. O’Reilly Online Learning
    8. How to Contact Us
    9. Acknowledgments
  2. 1. A Modern Language
    1. Enter Java
      1. Java’s Origins
      2. Growing Up
    2. A Virtual Machine
    3. Java Compared with Other Languages
    4. Safety of Design
      1. Simplify, Simplify, Simplify…
      2. Type Safety and Method Binding
      3. Incremental Development
      4. Dynamic Memory Management
      5. Error Handling
      6. Threads
      7. Scalability
    5. Safety of Implementation
      1. The Verifier
      2. Class Loaders
      3. Security Managers
    6. Application and User-Level Security
    7. A Java Road Map
      1. The Past: Java 1.0–Java 11
      2. The Present: Java 14
      3. The Future
      4. Availability
  3. 2. A First Application
    1. Java Tools and Environment
      1. Installing the JDK
      2. Installing OpenJDK on Linux
      3. Installing OpenJDK on Mac
      4. Installing OpenJDK on Windows
      5. Configuring IntelliJ IDEA and Creating a Project
      6. Running the Project
      7. Grabbing the Learning Java Examples
    2. HelloJava
      1. Classes
      2. The main() Method
      3. Classes and Objects
      4. Variables and Class Types
      5. HelloComponent
      6. Inheritance
      7. The JComponent Class
      8. Relationships and Finger Pointing
      9. Package and Imports
      10. The paintComponent() Method
    3. HelloJava2: The Sequel
      1. Instance Variables
      2. Constructors
      3. Events
      4. The repaint() Method
      5. Interfaces
    4. Goodbye and hello again
  4. 3. Tools of the Trade
    1. JDK Environment
    2. The Java VM
    3. Running Java Applications
      1. System Properties
    4. The Classpath
      1. javap
      2. Modules
    5. The Java Compiler
    6. Trying Java
    7. JAR Files
      1. File Compression
      2. The jar Utility
      3. The pack200 Utility
    8. Building up
  5. 4. The Java Language
    1. Text Encoding
    2. Comments
      1. Javadoc Comments
    3. Variables and Constants
    4. Types
      1. Primitive Types
      2. Reference Types
      3. Inferring Types
      4. Passing References
      5. A Word About Strings
    5. Statements and Expressions
      1. Statements
      2. Expressions
    6. Arrays
      1. Array Types
      2. Array Creation and Initialization
      3. Using Arrays
      4. Anonymous Arrays
      5. Multidimensional Arrays
    7. Types and Classes and Arrays, oh my!
  6. 5. Objects in Java
    1. Classes
      1. Declaring and Instantiating Classes
      2. Accessing Fields and Methods
      3. Static Members
    2. Methods
      1. Local Variables
      2. Shadowing
      3. Static Methods
      4. Initializing Local Variables
      5. Argument Passing and References
      6. Wrappers for Primitive Types
      7. Method Overloading
    3. Object Creation
      1. Constructors
      2. Working with Overloaded Constructors
    4. Object Destruction
      1. Garbage Collection
    5. Packages
      1. Importing Classes
      2. Custom Packages
      3. Member Visibility and Access
      4. Compiling With Packages
    6. Advanced Class design
      1. Subclassing and Inheritance
      2. Interfaces
      3. Inner classes
      4. Anonymous inner classes
    7. Organizing content and planning for failure
  7. 6. Error Handling and Logging
    1. Exceptions
      1. Exceptions and Error Classes
      2. Exception Handling
      3. Bubbling Up
      4. Stack Traces
      5. Checked and Unchecked Exceptions
      6. Throwing Exceptions
      7. try Creep
      8. The finally Clause
      9. Try with Resources
      10. Performance Issues
    2. Assertions
      1. Enabling and Disabling Assertions
      2. Using Assertions
    3. The Logging API
      1. Overview
      2. Logging Levels
      3. A Simple Example
      4. Logging Setup Properties
      5. The Logger
      6. Performance
    4. Real-world Exceptions
  8. 7. Collections and Generics
    1. Collections
      1. The Collection Interface
      2. Collection Types
      3. The Map Interface
    2. Type Limitations
      1. Containers: Building a Better Mousetrap
      2. Can Containers Be Fixed?
    3. Enter Generics
      1. Talking About Types
    4. “There Is No Spoon”
      1. Erasure
      2. Raw Types
    5. Parameterized Type Relationships
      1. Why Isn’t a List<Date> a List<Object>?
    6. Casts
      1. Converting between collections and arrays
      2. Iterator
    7. A closer look: The sort() Method
    8. Application: Apples and trees on the field
    9. Conclusion
  9. 8. Text and Core Utilities
    1. Strings
      1. Constructing Strings
      2. Strings from Things
      3. Comparing Strings
      4. Searching
      5. String Method Summary
    2. Things from Strings
      1. Parsing Primitive Numbers
      2. Tokenizing Text
    3. Regular Expressions
      1. Regex Notation
      2. The java.util.regex API
    4. Math Utilities
      1. The java.lang.Math Class
      2. Big/Precise Numbers
    5. Dates and Times
      1. Local Dates and Times
      2. Comparing and Manipulating Dates and Times
      3. Time Zones
      4. Parsing and Formatting Dates and Times
      5. Parsing Errors
      6. Timestamps
    6. Other Useful Utilities
  10. 9. Threads
    1. Introducing Threads
      1. The Thread Class and the Runnable Interface
      2. Controlling Threads
      3. Death of a Thread
    2. Synchronization
      1. Serializing Access to Methods
      2. Accessing class and instance Variables from Multiple Threads
    3. Scheduling and Priority
      1. Thread State
      2. Time-Slicing
      3. Priorities
      4. Yielding
    4. Thread Performance
      1. The Cost of Synchronization
      2. Thread Resource Consumption
    5. Concurrency Utilities
  11. 10. Desktop Applications
    1. Buttons and sliders and text fields, oh my!
      1. Component hierarchies
      2. Model View Controller architecture
      3. Labels and Buttons
      4. Text components
      5. Other components
    2. Containers and layouts
      1. Frames and windows
      2. JPanel
      3. Layout managers
    3. Events
      1. Mouse events
      2. Action events
      3. Change events
      4. Other events
    4. Modals and popups
      1. Message dialogs
      2. Confirmation dialogs
      3. Input dialogs
    5. Threading considerations
      1. SwingUtilities and component updates
      2. Timers
    6. Next steps
      1. Menus
      2. Preferences
      3. Custom components and Java2D
      4. JavaFX
    7. User Interface and User Experience
  12. 11. Networking and I/O
    1. Streams
      1. Basic I/O
      2. Character Streams
      3. Stream Wrappers
      4. The java.io.File Class
      5. File Streams
      6. RandomAccessFile
    2. The NIO File API
      1. FileSystem and Path
      2. NIO File Operations
    3. The NIO Package
      1. Asynchronous I/O
      2. Performance
      3. Mapped and Locked Files
      4. Channels
      5. Buffers
      6. Character Encoders and Decoders
      7. FileChannel
    4. Network Programming
    5. Sockets
      1. Clients and Servers
      2. The DateAtHost Client
      3. A Distributed Game
    6. More to explore
  13. 12. Programming for the Web
    1. Uniform Resource Locators
    2. The URL Class
      1. Stream Data
      2. Getting the Content as an Object
      3. Managing Connections
      4. Handlers in Practice
      5. Useful Handler Frameworks
    3. Talking to Web Applications
      1. Using the GET Method
      2. Using the POST Method
      3. The HttpURLConnection
      4. SSL and Secure Web Communications
    4. Java Web Applications
      1. The Servlet Lifecycle
      2. Servlets
      3. The HelloClient Servlet
      4. The Servlet Response
      5. Servlet Parameters
      6. The ShowParameters Servlet
      7. User Session Management
      8. The ShowSession Servlet
    5. Servlet Containers
      1. Configuration with web.xml and Annotations
      2. URL Pattern Mappings
      3. Deploying HelloClient
    6. The World-Wide Web is, well, wide
  14. 13. Expanding Java
    1. Java Releases
      1. JCP and JSRs
    2. Lambda Expressions
      1. Retrofitting Your Code
    3. Expanding Java beyond the core
    4. Final wrap up and next steps
  15. A. Code Examples and IntelliJ IDEA
    1. Grabbing the Main Code Examples
    2. Installing IntelliJ IDEA
      1. Installing on Linux
      2. Installing on Mac
      3. Installing on Windows
    3. Importing the Examples
    4. Running the Examples
    5. Grabbing the Web Code Examples
    6. Working with Servlets
  16. Glossary
  17. Index

Product Information

  • Title: Learning Java, 5th Edition
  • Author(s): Daniel Leuck, Patrick Niemeyer, Marc Loy
  • Release date: July 2020
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492056263