Jump to ratings and reviews
Rate this book

Java Generics and Collections: Speed Up the Java Development Process

Rate this book
This comprehensive guide shows you how to master the most important changes to Java since it was first released. Generics and the greatly expanded collection libraries have tremendously increased the power of Java 5 and Java 6. But they have also confused many developers who haven't known how to take advantage of these new features.

Java Generics and Collections covers everything from the most basic uses of generics to the strangest corner cases. It teaches you everything you need to know about the collections libraries, so you'll always know which collection is appropriate for any given task, and how to use it.

Topics covered include:

• Fundamentals of generics: type parameters and generic methods
• Other new features: boxing and unboxing, foreach loops, varargs
• Subtyping and wildcards
• Evolution not revolution: generic libraries with legacy clients and generic clients with legacy libraries
• Generics and reflection
• Design patterns for generics
• Sets, Queues, Lists, Maps, and their implementations
• Concurrent programming and thread safety with collections
• Performance implications of different collections

Generics and the new collection libraries they inspired take Java to a new level. If you want to take your software development practice to a new level, this book is essential reading.

Philip Wadler is Professor of Theoretical Computer Science at the University of Edinburgh, where his research focuses on the design of programming languages. He is a co-designer of GJ, work that became the basis for generics in Sun's Java 5.0.

Maurice Naftalin is Technical Director at Morningside Light Ltd., a software consultancy in the United Kingdom. He has most recently served as an architect and mentor at NSB Retail Systems plc, and as the leader of the client development team of a major UK government social service system.

"A brilliant exposition of generics. By far the best book on the topic, it provides a crystal clear tutorial that starts with the basics and ends leaving the reader with a deep understanding of both the use and design of generics."
Gilad Bracha, Java Generics Lead, Sun Microsystems

273 pages, Paperback

First published October 12, 2006

48 people are currently reading
488 people want to read

About the author

Maurice Naftalin

7 books3 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
83 (30%)
4 stars
119 (43%)
3 stars
58 (21%)
2 stars
10 (3%)
1 star
4 (1%)
Displaying 1 - 30 of 30 reviews
Profile Image for Jeanne Boyarsky.
Author 28 books76 followers
May 15, 2011
My first thought on seeing the title “Java Generics and Collections” was wondering how there could be a whole book's worth of material on the topic. There is!

The first half of the book addresses generics. It includes concepts like reification (I learned a new word) that helps you better understand how generics actually work. It also includes a number of idioms for dealing with generics that you might not know even if you use generics.

The rest of the book covers the Collection API including how each one works and when to each type. This felt somewhat drawn out and repetitive. I would have liked to see the new classes in Java 5 and 6 highlighted more.

The downside: Some of the code examples were on the long side and some of the text required a lot of concentration. I also noticed a typo in the name of a Java class in a diagram which feels worse than in text. I also feel too broad an audience is covered. Parts assume you know nothing (in which case you'd be in over your head.)

Overall I recommend the book to learn about generics on a level of detail that surpasses the tutorials.
99 reviews
March 23, 2018
Very useful. Gives good insight of Collections
Profile Image for Linda.
428 reviews36 followers
March 16, 2010
This is a pretty good description of Java Generics and how they differ from similar implementations in other languages. It also spends half the book going into detail on the Java Collection classes and how they make heavy use of generics to be much more useful.

I didn't expect to learn much from this and I was surprised how much useful info it contained. It's dry reading, particularly the second half of the book, but definitely useful for the Java programmer.
222 reviews5 followers
February 17, 2009
This book was lame - I forgot why, but it definitely was lame.
Profile Image for Amit Sahoo.
6 reviews1 follower
July 17, 2016
Coverage is good.I would have liked application context oriented examples instead of numbers,double etc.Recommended to be read by Beginners.
7 reviews
May 17, 2019
While the book is dated, it is still useful especially with regards to understanding Generics. I found it useful as I was working on a refactoring to extract common code into a generic Superclass when I decided to pick up this book.

The book is divided into 2 parts, one on Generics and the other on the Java Collections Framework. These two parts feel entirely separate and since most would be reading it for Generics, the following is some guidance on which chapters to read if pressed on time:
Basic Generics: Chapter 1, 2, 4
Advance Generics/ Related Concepts: Chapter 3, 6, 7
Examples via Design Patterns: 9

For the other Generics chapters, they are related to dealing with legacy code/ libraries that uses raw types which might not be relevant for all since most of the current Java libraries should already be using Generics instead of raw types.

For the collections chapter, while dated, I still learnt something new (SkipLists, NavigableMap interface, etc.) from the chapters and it is a good review of many of the available implementations of Map, Set, List, etc and when to choose them. If I were less experienced with Java, it would have given a solid introduction to the Collections API, thus I would recommend if you are new to Java or would like a refresher in the Collections Framework. (ArrayDeque, NavigableMap, ConcurrentSkipListMap, etc., if these sound foreign, this part of the book would clear things up.)
Profile Image for Prasanth Mathialagan.
10 reviews1 follower
July 30, 2017
The book dives deep in to the details of Generics and how it is implemented in Java. But it will be bit difficult to comprehend if you don't have some basic understanding of Generics. The second part of the book covers Collections framework which you won't find interesting if you already worked with Java Collections. The author should consider releasing a book that covers only Generics. Overall, it is a decent book to learn about Generics.
Profile Image for Caleb Lee.
1 review
Currently reading
August 28, 2017
Chapter 13 Set
- learn the various type of set and their usage
- General HashSet( constant performance)
- linkedHashSet ( faster iteration and ordering )
- Treeset (Sorting)
- ConcurrentSkiplistset(multi thread + sorting)
- CopyOnWriteArraySet ( small set size, more read than write, thread safe)
- for multi-thread use ConcurrentSkipListSet / Client symchronizing / use Collection.synchronize to get Synchronized implementatiom
This entire review has been hidden because of spoilers.
Profile Image for Umang Bhatt.
21 reviews2 followers
November 4, 2017
Well most of books for beginners do teach little amount of collections. But no one is as detailed as this.
5 reviews
May 3, 2019
Excellent book for advanced understanding of Java Collections Framework and how Generics work. The book is systematic and offers great examples. Maps and Sets part is a bit crammed.
Profile Image for Lucas Nguyen.
7 reviews1 follower
December 19, 2021
It’s not for java beginners. The way author explains the concept requires readers having solid foundation and concentration. I’ve read this multiple times and each time I got something new.
53 reviews
August 8, 2022
Every developer working with a JVM based language should consider reading at least the first half of this books which covers generics.
Profile Image for Edgar Hernandez.
36 reviews1 follower
December 22, 2022
I was interested only in the generics part of the book. This is a complicated concept and sadly this book failed to make clear explanations. Too dense I think.
Profile Image for Matt.
Author 51 books21 followers
October 24, 2007
Okay, I straddle two worlds. In one life, I labor through complex, terse, and often obscure works of philosophy. In the other, I blissfully bang out thousands of lines of code in my happy little IDE -- the famous editor VI (that's pronounced "Six" -- it's roman numerals. No really. I'm not making fun of your ignorance... I swear).

One thing I have noticed is that academic writing often forgoes altogether any concern for the readability of the text. Another is the noted absence of any examples or illustrative material that might actually have any bearing on reality.

(Need an example? Google "Brains in a vat")

But in happy computer land, I rarely find this to be the case. Mainstream books in programming tend to be practical and readable (Sometimes they get nauseatingly so. Example: [title: Head First Java]).

Java Generics and Collections, like me, straddles two worlds. And it does so with moderate success. While it certainly provides the details on generic and collections, it has its "Computer Science 502" moments.

The book is all about the facts. No cute illustrations. No gratuitous coffee jokes. No fanciful business problems that we will magically be able to solve with the help of Java Generics Man. Just the facts.

Wow... how refreshing.

But sometimes the text gets a little too terse. Huge chunks of code get explained in just a line or two (leaving the reader wondering about the details). Sometimes (as is the case in most of Chapter 3), major concepts are explained in self-referential ways, while no clear definitions for key concepts are offered.

Those moments left me frustrated, to be sure. If I wanted to try to figure out what someone else's code did, I'd read Java Puzzlers... or go download the source code to Eclipse.

But aside from those points, I've found this book very helpful in explaining the details of a system that the official Java documentation just doesn't adequately cover.

This book will land on my reference shelf with precious few other computer books -- the five or six (like [title:Applied Cryptography] and the CSS Reference Pocketbook) that have survived my cruel computer bookshelf purges.
Profile Image for Michael Koltsov.
110 reviews69 followers
September 1, 2014
Finally, i've read this book! I have a point that i should finish every book that i've started to read. This book was an exception, because i wasn't able to finish it for a few years. I had all sorts of execuses not to read this book, some of them were a lack of time and a complete disinterest in the subject of this book.

I was wrong, the book is interesting. It's a sort of holy grail for those who want to know how generics work under the hood and where to apply them. As for me i was interested in the second part of it which is "Collections". It's nice and comprehensive guide that describes almost every entity in the Java 6 Collections API.

If i have read this books many years ago i would have avoided many pitfalls =)

My score 5/5
Profile Image for Burak Dede.
25 reviews6 followers
December 15, 2014
We all know that java generics is a hard to swallow topic but this book makes it easy to understand decisions behind the generics and gives some best practices. In order to give sense of generics book follows collections framework and detailed information about collection interfaces and methods. Nicely structured and easy to follow with bonus of being thin book.
Profile Image for Colin Jones.
Author 1 book103 followers
August 21, 2011
Type systems kind of blow my mind, in particular things like bounded types and co-/contravariance Feels like 2 totally separate books, and the collections section was fairly dry. The first half, on generics, helped to make things clearer - will probably need a second read to solidify.
76 reviews1 follower
Read
January 31, 2016
A must read on Generics... with Neil Gafter's blog and Angelika Langer's FAQ (even though they are sometimes hard to find, there are some true gems like the entry on how to instantiate a wildcard parameterized type despite the compiler's best efforts to prevent it).
Profile Image for LOL_BOOKS.
2,817 reviews54 followers
Read
March 2, 2016
WHAT HAVE YOU BEEN READING, MEMERS?

JAVA GENERICS AND COLLECTIONS. AREN'T YOU JEALOUS OF ME? I BET YOU'RE JEALOUS OF ME.

SOUNDS RIVETING! ARE YOU FINDING IT ACTUALFAX HALPFUL?

I'M LEARNING STUFF FROM IT. HOW USEFUL IT'S GONNA BE TO ME IS STILL UP FOR DEBATE.
11 reviews
April 10, 2020
This book explains clearly on the concept of Java Generics. I become significantly more comfortable working with generics after reading this book. However, this book is a reference book and can be quite boring to read.
33 reviews1 follower
April 21, 2011
Strangely boring, given that I've enjoyed Wadler's writings on Haskell. Some very good sections (the first 100 pages); some incredibly boring ones (most of the Collections discussion).
Profile Image for Spencer.
146 reviews
April 26, 2011
I was concerned that this book would be tedious on such a narrow subject. The authors delivered the information directly and clearly. This was enough to keep everything interesting.
40 reviews1 follower
May 15, 2015
An interesting and succinct book which focuses on generics and collections, clearing many things regarding them. Probably a second read would be needed.
Profile Image for Prakash.
165 reviews97 followers
September 2, 2015
I read the collection API part. It is not as good a book and in-depth implementation details of API's is missing.
25 reviews18 followers
December 22, 2016
The most comprehensive book on Generics as well as collection.A must have
32 reviews
Read
March 20, 2013
Reflection, do, weak map
Displaying 1 - 30 of 30 reviews

Can't find what you're looking for?

Get help and learn more about the design.