Getting Started with Google Guava


Getting Started with Google Guava
eBook: $14.99
Formats: PDF, PacktLib, ePub and Mobi formats
$12.74
save 15%!
Print + free eBook + free PacktLib access to the book: $39.98    Print cover: $24.99
$24.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • Write more robust code that is easier to read and maintain
  • Learn how to use Preconditions to prevent and find errors faster
  • Shows how Guava Collections can make working with Java Collections a breeze

Book Details

Language : English
Paperback : 142 pages [ 235mm x 191mm ]
Release Date : August 2013
ISBN : 1783280158
ISBN 13 : 9781783280155
Author(s) : Bill Bejeck
Topics and Technologies : All Books, Application Development, Java, Open Source


Table of Contents

Preface
Chapter 1: Getting Started
Chapter 2: Basic Guava Utilities
Chapter 3: Functional Programming with Guava
Chapter 4: Working with Collections
Chapter 5: Concurrency
Chapter 6: Guava Cache
Chapter 7: The EventBus Class
Chapter 8: Working with Files
Chapter 9: Odds and Ends
Index
  • Chapter 1: Getting Started
    • Introducing Google Guava
    • The case for using Guava
    • What is this book about?
    • Installing Guava
    • Using Guava with Maven or Gradle
      • Getting the source code for the book
    • Summary
  • Chapter 2: Basic Guava Utilities
    • Using the Joiner class
      • Time for a review
    • Using the Splitter class
      • Time for a review
    • Working with strings in Guava
      • Using the Charsets class
      • Using the Strings class
    • Using the CharMatcher class
    • Using the Preconditions class
    • Object utilities
      • Getting help with the toString method
      • Checking for null values
      • Generating hash codes
      • Implementing CompareTo
  • Summary
  • Chapter 3: Functional Programming with Guava
    • Using the Function interface
      • Guidelines for using the Function interface
    • Using the Functions class
      • Using the Functions.forMap method
      • Using the Functions.compose method
    • Using the Predicate interface
      • An example of the Predicate interface
    • Using the Predicates class
      • Using the Predicates.and method
      • Using the Predicates.or method
      • Using the Predicates.not method
      • Using the Predicates.compose method
    • Using the Supplier interface
      • An example of the Supplier interface
    • Using the Suppliers class
      • Using the Suppliers.memoize method
      • Using the Suppliers.memoizeWithExpiration method
    • Summary
  • Chapter 4: Working with Collections
    • The FluentIterable class
      • Using the FluentIterable.filter method
      • Using the FluentIterable.transform method
    • Lists
      • Using the Lists.partition method
    • Sets
      • Using the Sets.difference method
      • Using the Sets.symmetricDifference method
      • Using the Sets.intersection method
      • Using the Sets.union method
    • Maps
      • Using the Maps.uniqueIndex method
      • Using the Maps.asMap method
      • Transforming maps
    • Multimaps
      • ArrayListMultimap
      • HashMultimap
    • BiMap
      • Using the BiMap.forcePut method
      • Using the BiMap.inverse method
    • Table
      • Table operations
      • Table views
    • Range
      • Ranges with arbitrary comparable objects
    • Immutable collections
      • Creating immutable collection instances
    • Ordering
      • Creating an Ordering instance
      • Reverse sorting
      • Accounting for null
      • Secondary sorting
      • Retrieving minimum and maximum values
    • Summary
  • Chapter 5: Concurrency
    • Synchronizing threads
    • Monitor
      • Monitor explained
        • Monitor best practice
        • Different Monitor access methods
    • ListenableFuture
      • Obtaining a ListenableFuture interface
    • FutureCallback
      • Using the FutureCallback
    • SettableFuture
    • AsyncFunction
    • FutureFallback
    • Futures
      • Asynchronous Transforms
      • Applying FutureFallbacks
    • RateLimiter
    • Summary
  • Chapter 6: Guava Cache
    • MapMaker
    • Guava caches
      • Cache
      • LoadingCache
        • Loading values
        • Refreshing values in the cache
    • CacheBuilder
    • CacheBuilderSpec
    • CacheLoader
    • CacheStats
    • RemovalListener
      • RemovalNotification
      • RemovalListeners
    • Summary
  • Chapter 7: The EventBus Class
    • EventBus
      • Creating an EventBus instance
      • Subscribing to events
      • Posting the events
      • Defining handler methods
      • Concurrency
    • Subscribe – An example
    • Event Publishing – An example
    • Finer-grained subscribing
    • Unsubscribing to events
    • AsyncEventBus
      • Creating an AsyncEventBus instance
    • DeadEvents
    • Dependency injection
    • Summary
  • Chapter 8: Working with Files
    • Copying a file
    • Moving/renaming a File
    • Working with files as strings
    • Hashing a file
    • Writing to files
      • Writing and appending
    • InputSupplier and OutputSupplier
      • Sources and Sinks
    • ByteSource
    • ByteSink
    • Copying from a ByteSource class to a ByteSink class
    • ByteStreams and CharStreams
      • Limiting the size of InputStreams
      • Joining CharStreams
    • Closer
    • BaseEncoding
    • Summary
  • Chapter 9: Odds and Ends
    • Creating proper hash functions
      • Checksum hash functions
      • General hash functions
      • Cryptographic hash functions
    • BloomFilter
      • BloomFilter in a nutshell
      • Funnels and PrimitiveSinks
      • Creating a BloomFilter instance
    • Optional
      • Creating an Optional instance
    • Throwables
      • Getting the chain of Throwables
      • Obtaining the Root Cause Throwable
    • Summary

Bill Bejeck

Bill Bejeck is a senior software engineer with 10 years experience across a wide range of projects. Currently he is working on the storage and analysis of financial data using Hadoop. He has a B.A in Economics from the University of Maryland and an M.S in Information Systems from Johns Hopkins University. Bill also enjoys blogging at http://codingjunkie.net.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 2 submitted: last submission 27 Nov 2013

Errata type: Code | Page number: 20 

String lettersAndNumbers = ""foo989yxbar234"";

String expected = ""989234"";

 

The code should be as follows:

String lettersAndNumbers = "foo989yxbar234";

String expected = "989234";

 

Page numbers: 20 

String value = Objects.firstNonNull(someString,""default value"");

 

The code should be as follows:

String value = Objects.firstNonNull(someString,"default value");

 

Errata type: Code | Page number: 99

public class ToListLineProcessor implements 

LineProcessor<List<String>>{

private static final Splitter splitter = Splitter.on(",");

private List<String> bookTitles = Lists.newArrayList();

private static final int TITLE_INDEX = 1;

@Override 

public List<String> getResult() {

return bookTitles;

}

@Override

@Override

 

Correction: Two consecutive "@override" should be replaced with one "@overirde".

 

Errata type: Typo | Page number: 18 

nullToEmpty: This method takes a string as an argument and returns the 

original string if the value is not null or has a length greater than 0, otherwise 

it returns """"

 

The sentence should be as follows:

nullToEmpty: This method takes a string as an argument and returns the 

original string if the value is not null or has a length greater than 0, otherwise 

it returns ""

Errata type: Typo | Page number: 20

 

In this example, we are taking the string ""foo989yxbar234""and retaining all 

digits found in the string.

 

The sentence should be as follows:

In this example, we are taking the string "foo989yxbar234" and retaining all 

digits found in the string.

 

Errata type: Typo | Page number: 20

As before, using preconditions are important for ensuring the behavior of our code and are very useful in debugging.

 

This sentence should be as follows:

As mentioned before, using preconditions are important for ensuring the behavior of our code and are very useful in debugging.

 

Errata type: Typo | Page number: 21

this.label = checkNotNull(label,"Label can''t be null");

 

There is a typo inside the code. and the revised code is as follows:

this.label = checkNotNull(label,"Label can't be null");

 

Errata type: Typo | Page number: 40

2nd heading, 1st line : Predicataes

correction: Predicates

 

 

 

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Getting Started with Google Guava +    Blender 3D Printing Essentials =
50% Off
the second eBook
Price for both: £16.40

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Master String manipulation with ease including creating a HashMap from formatted text
  • Harness the power of functional programming with Functions and Predicates
  • Use the power of Guava’s Collections classes
  • Get to grips with better ways of writing and reading files with less boilerplate
  • Improve synchronization with the Monitor
  • Create and use a self-loading cache for better performance
  • Leverage the power of event-based programming with the EventBus
  • Never get another NullPointerException by using the Optional class

In Detail

Java continues to maintain its popularity and is still one of the main languages used in the software industry today. But there are things in Java that are difficult to do that can be made easier; that’s where Guava comes in. Guava provides developers with a way to write better code, with less effort.

Getting Started with Google Guava will show the reader how to start improving their code from the very first chapter. Packed with examples and loads of source code, this book will have an immediate impact on how you work with Java.

This book starts with using Guava to help with the common tasks that Java developers perform. Then you’ll work your way through more specialized situations and finally some great functionality Guava provides that can add a lot of power to your applications with little effort. You will learn about Guava’s famous Collections classes that add unique features, like the Bi-Map, to Java’s already great Collection classes. We’ll see how to add some functional programming aspects to our code. We will also learn about using a self-loading cache for improved performance in our applications, and how to use the EventBus to create software that takes advantage of event-based programming.

Approach

This is a short, practical guide, with lots of examples to help you learn Google Guava

Who this book is for

There is no minimum level of experience required. There is something for everyone who works with Java, from the beginner to the expert programmer.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software