Leanpub Header

Skip to main content

On Java 8

By the author of "Thinking in Java," covering version 8 of the Java programming language (with updates to Java 17). Intended for “dedicated beginners,” it doesn’t assume you know anything about programming and takes you through the material step-by-step. However, I assume you are able to figure things out. It’s not a “dummies” or “idiot’s” guide.

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
1,820
Pages
About

About

About the Book

This book teaches Java programming using the features in the 8th version of that language. Version 2 of the book (December 2021) adds supplements covering features through Java 17.

My previous Java book, Thinking in Java, 4th Edition (Prentice Hall 2006), is still useful for programming in Java 5, the version of the language used for Android programming. But especially with the advent of Java 8, the language has changed significantly enough that new Java code feels and reads differently. This justified the two-year effort of creating a new book.

Each chapter teaches a concept, or a group of associated concepts, without relying on features that haven't yet been introduced. That way you can digest each piece in the context of your current knowledge before moving on.

My goals in this book are to:

1. Present the material one step at a time so you can easily incorporate each idea before moving on, and to carefully sequence the presentation of features so you're exposed to a topic before you see it in use. This isn't always possible; in those situations, a brief introductory description is given.

2. Use examples that are as simple and short as possible. This sometimes prevents me from tackling "real world" problems, but I've found that beginners are usually happier when they can understand every detail of an example rather than being impressed by the scope of the problem it solves. For this I might receive criticism for using "toy examples," but I'm willing to accept that in favor of producing something pedagogically useful.

3. Give you what I think is important for you to understand about the language, rather than everything I know. I believe there is an information importance hierarchy, and there are some facts that 95 percent of programmers will never need to know---details that just confuse people and increase their perception of the complexity of the language. If you must think about it, it will also confuse the reader/maintainer of that code, so I advocate choosing a simpler approach.

4. Provide you with a solid foundation so you understand the issues well enough to move on to more difficult coursework and books.

Price

Pick Your Price...

Minimum price

$37.00

$47.00

You pay

$47.00

Author earns

$37.60
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 3)

3
The author will earn $36.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Bruce Eckel

Bruce Eckel is the author of the multi-award-winning Thinking in Java and Thinking in C++, and a number of other books on computer programming including Atomic Scala. He's given hundreds of presentations throughout the world and puts on alternative conferences and events like the www.WinterTechForum.com and developer retreats. He lives in Crested Butte, Colorado. Bruce has a BS in applied physics and an MS in computer engineering. His blog is at www.BruceEckel.com and his consulting, training and conference business is www.MindviewLLC.com.

Leanpub Podcast

Episode 192

An Interview with Bruce Eckel

Contents

Table of Contents

Copyright

Preface

  1. Post-Java-8 Features in this Book
  2. This is Only an eBook
  3. Colophon
  4. Acknowledgements
  5. Dedication

Introduction

  1. Goals
  2. Language Design Errors
  3. Popularity
  4. Android Programmers
  5. Book Updates
  6. The New Java “Release Cadence”
  7. What About User Interfaces?
  8. JDK HTML Documentation
  9. Tested Examples
  10. Coding Standards
  11. Bug Reports
  12. Source Code

What is an Object?

  1. The Progress of Abstraction
  2. An Object Has an Interface
  3. Objects Provide Services
  4. The Hidden Implementation
  5. Reusing the Implementation
  6. Inheritance
  7. Interchangeable Objects with Polymorphism
  8. The Singly-Rooted Hierarchy
  9. Collections
  10. Object Creation & Lifetime
  11. Exception Handling: Dealing with Errors
  12. Summary

Installing Java and the Book Examples

  1. Editors
  2. The Shell
  3. Installing Java
  4. Verify Your Installation
  5. Installing and Running the Book Examples

Objects Everywhere

  1. You Manipulate Objects with References
  2. You Must Create All the Objects
  3. Comments
  4. You Never Need to Destroy an Object
  5. Creating New Data Types: class
  6. Methods, Arguments, and Return Values
  7. Writing a Java Program
  8. Your First Java Program
  9. Coding Style
  10. Summary

Operators

  1. Using Java Operators
  2. Precedence
  3. Assignment
  4. Mathematical Operators
  5. Auto Increment and Decrement
  6. Relational Operators
  7. Logical Operators
  8. Literals
  9. Bitwise Operators
  10. Shift Operators
  11. Ternary if-else Operator
  12. String Operator + and +=
  13. Common Pitfalls When Using Operators
  14. Casting Operators
  15. Java Has No “sizeof”
  16. A Compendium of Operators
  17. Summary

Control Flow

  1. true and false
  2. if-else
  3. Iteration Statements
  4. For-in Syntax
  5. return
  6. break and continue
  7. The Infamous “Goto”
  8. switch
  9. Switching on Strings
  10. Summary

Housekeeping

  1. Guaranteed Initialization with the Constructor
  2. Method Overloading
  3. Zero-Argument Constructors
  4. The this Keyword
  5. Cleanup: Finalization and Garbage Collection
  6. Member Initialization
  7. Constructor Initialization
  8. Array Initialization
  9. Enumerated Types
  10. New Feature: Local Variable Type Inference
  11. Summary

Implementation Hiding

  1. package: the Library Unit
  2. Java Access Specifiers
  3. Interface and Implementation
  4. Class Access
  5. New Feature: Modules
  6. Summary

Reuse

  1. Composition Syntax
  2. Inheritance Syntax
  3. Delegation
  4. Combining Composition and Inheritance
  5. Choosing Composition vs. Inheritance
  6. protected
  7. Upcasting
  8. The final Keyword
  9. Initialization and Class Loading
  10. Summary

Polymorphism

  1. Upcasting Revisited
  2. The Twist
  3. Constructors and Polymorphism
  4. Covariant Return Types
  5. Designing with Inheritance
  6. Summary

Interfaces

  1. Abstract Classes and Methods
  2. Defining Interfaces
  3. Abstract Classes vs. Interfaces
  4. Complete Decoupling
  5. Combining Multiple Interfaces
  6. Extending an Interface with Inheritance
  7. Adapting to an Interface
  8. Fields in Interfaces
  9. Nesting Interfaces
  10. Interfaces and Factories
  11. New Feature: private Methods in Interfaces
  12. New Feature: Sealed Classes and Interfaces
  13. Summary

Inner Classes

  1. Creating Inner Classes
  2. The Link to the Outer Class
  3. Using .this and .new
  4. Inner Classes and Upcasting
  5. Inner Classes in Methods and Scopes
  6. Anonymous Inner Classes
  7. Nested Classes
  8. Why Inner Classes?
  9. Inheriting from Inner Classes
  10. Can Inner Classes Be Overridden?
  11. Local Inner Classes
  12. Inner-Class Identifiers
  13. Summary

Collections

  1. Generics and Type-Safe Collections
  2. Basic Concepts
  3. Adding Groups of Elements
  4. Printing Collections
  5. List
  6. Iterators
  7. LinkedList
  8. Stack
  9. Set
  10. Map
  11. New Feature: Records
  12. Queue
  13. Collection vs. Iterator
  14. for-in and Iterators
  15. Summary

Functional Programming

  1. Old vs. New
  2. Lambda Expressions
  3. Method References
  4. Functional Interfaces
  5. Higher-Order Functions
  6. Closures
  7. Function Composition
  8. Currying and Partial Evaluation
  9. Pure Functional Programming
  10. Summary

Streams

  1. Java 8 Stream Support
  2. Stream Creation
  3. Intermediate Operations
  4. Optional
  5. Terminal Operations
  6. Summary

Exceptions

  1. Concepts
  2. Basic Exceptions
  3. Catching an Exception
  4. Creating Your Own Exceptions
  5. The Exception Specification
  6. Catching Any Exception
  7. Standard Java Exceptions
  8. New Feature: Better NullPointerException Reporting
  9. Performing Cleanup with finally
  10. Exception Restrictions
  11. Constructors
  12. Try-With-Resources
  13. Exception Matching
  14. Alternative Approaches
  15. Exception Guidelines
  16. Summary

Validating Your Code

  1. Testing
  2. Preconditions
  3. Test-Driven Development
  4. Logging
  5. Debugging
  6. Benchmarking
  7. Profiling and Optimizing
  8. Style Checking
  9. Static Error Analysis
  10. Code Reviews
  11. Pair Programming
  12. Refactoring
  13. Continuous Integration
  14. Summary

Files

  1. File and Directory Paths
  2. Directories
  3. File Systems
  4. Watching a Path
  5. Finding Files
  6. Reading & Writing Files
  7. Summary

Strings

  1. Immutable Strings
  2. Overloading + vs. StringBuilder
  3. Unintended Recursion
  4. Operations on Strings
  5. Formatting Output
  6. New Feature: Text Blocks
  7. Regular Expressions
  8. Scanning Input
  9. StringTokenizer
  10. Summary

Reflection

  1. The Need for Reflection
  2. The Class Object
  3. Checking Before a Cast
  4. Registered Factories
  5. Instanceof vs. Class Equivalence
  6. Runtime Class Information
  7. Dynamic Proxies
  8. Using Optional
  9. Interfaces and Type Information
  10. Summary

Generics

  1. Comparison with C++
  2. Simple Generics
  3. Generic Interfaces
  4. Generic Methods
  5. Building Complex Models
  6. The Mystery of Erasure
  7. Compensating for Erasure
  8. Bounds
  9. Wildcards
  10. Issues
  11. Self-Bounded Types
  12. Dynamic Type Safety
  13. Exceptions
  14. Mixins
  15. Latent Typing
  16. Compensating for the Lack of (Direct) Latent Typing
  17. Assisted Latent Typing in Java 8
  18. Summary: Is Casting Really So Bad?

Arrays

  1. Why Arrays are Special
  2. Arrays are First-Class Objects
  3. Returning an Array
  4. Multidimensional Arrays
  5. Arrays and Generics
  6. Arrays.fill()
  7. Arrays.setAll()
  8. Incremental Generators
  9. Random Generators
  10. Generics and Primitive Arrays
  11. Modifying Existing Array Elements
  12. An Aside On Parallelism
  13. Arrays Utilities
  14. Copying an Array
  15. Comparing Arrays
  16. Streams and Arrays
  17. Sorting Arrays
  18. Searching with Arrays.binarySearch()
  19. Accumulating with parallelPrefix()
  20. Summary

Enumerations

  1. Basic enum Features
  2. Adding Methods to an enum
  3. enums in switch Statements
  4. The Mystery of values()
  5. Implements, not Inherits
  6. Random Selection
  7. Using Interfaces for Organization
  8. Using EnumSet Instead of Flags
  9. Using EnumMap
  10. Constant-Specific Methods
  11. Multiple Dispatching
  12. New Features to Support Pattern Matching
  13. New Feature: Arrow in switch
  14. New Feature: case null in switch
  15. New Feature: switch as an Expression
  16. New Feature: Smart Casts
  17. New Feature: Pattern Matching
  18. Summary

Annotations

  1. Basic Syntax
  2. Writing Annotation Processors
  3. Using javac to Process Annotations
  4. Annotation-Based Unit Testing
  5. Summary

Concurrent Programming

  1. The Terminology Problem
  2. Concurrency Superpowers
  3. Concurrency is for Speed
  4. The Four Maxims of Java Concurrency
  5. The Brutal Truth
  6. The Rest of the Chapter
  7. Parallel Streams
  8. Creating and Running Tasks
  9. Terminating Long-Running Tasks
  10. CompletableFutures
  11. Deadlock
  12. Constructors are not Thread-Safe
  13. Effort, Complexity, Cost
  14. Summary

Patterns

  1. The Pattern Concept
  2. Singleton
  3. Classifying Patterns
  4. Template Method
  5. Fronting for an Implementation
  6. Factories: Encapsulating Object Creation
  7. Function Objects
  8. Changing the Interface
  9. Interpreter: Runtime Flexibility
  10. Callbacks
  11. Multiple Dispatching
  12. Pattern Refactoring
  13. Summary

Appendix: Supplements

  1. On Java 8 Example Code
  2. Hands-On Java eSeminar

Appendix: Programming Guidelines

  1. Design
  2. Implementation

Appendix: Javadoc

  1. Syntax
  2. Embedded HTML
  3. Some Example Tags
  4. Documentation Example

Appendix: Passing and Returning Objects

  1. Passing References
  2. Making Local Copies
  3. Controlling Cloneability
  4. Immutable Classes
  5. Summary

Appendix: I/O Streams

  1. Types of InputStream
  2. Types of OutputStream
  3. Adding Attributes and Useful Interfaces
  4. Readers & Writers
  5. Off By Itself: RandomAccessFile
  6. Typical Uses of I/O Streams
  7. Summary

Appendix: Standard I/O

  1. Reading from Standard Input
  2. Changing System.out to a PrintWriter
  3. Redirecting Standard I/O
  4. Process Control

Appendix: New I/O

  1. ByteBuffers
  2. Converting Data
  3. Fetching Primitives
  4. View Buffers
  5. Data Manipulation with Buffers
  6. Memory-Mapped Files
  7. File Locking

Appendix: Understanding equals() and hashCode()

  1. A Canonical equals()
  2. Hashing and Hash Codes
  3. Tuning a HashMap

Appendix: Collection Topics

  1. Sample Data
  2. List Behavior
  3. Set Behavior
  4. Using Functional Operations with any Map
  5. Selecting Parts of a Map
  6. Filling Collections
  7. Custom Collection and Map using Flyweight
  8. Collection Functionality
  9. Optional Operations
  10. Sets and Storage Order
  11. Queues
  12. Understanding Maps
  13. Utilities
  14. Holding References
  15. Java 1.0/1.1 Collections
  16. Summary

Appendix: Low-Level Concurrency

  1. What is a Thread?
  2. Catching Exceptions
  3. Sharing Resources
  4. The volatile Keyword
  5. Atomicity
  6. Critical Sections
  7. Library Components
  8. Summary

Appendix: Data Compression

  1. Simple Compression with GZIP
  2. Multifile Storage with Zip
  3. Java Archives (Jars)

Appendix: Object Serialization

  1. Overview
  2. Finding the Class
  3. Controlling Serialization
  4. Using Persistence

Appendix: Benefits and Costs of Static Type Checking

  1. Foreword to the 2021 Edition
  2. Foreword to the Original Edition
  3. Static Type Checking vs. Testing
  4. How to Argue about Typing
  5. The Cost of Productivity
  6. Static vs. Dynamic

Appendix: The Positive Legacy of C++ and Java

Appendix: Becoming a Programmer

  1. How I Got Started in Programming
  2. A Career in Computing
  3. The Mythical 5%
  4. Writing Software Is Like … Writing
  5. Programming as Typing
  6. Do What You Love

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub