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
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.
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.
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.)
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.
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.
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.
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.
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.
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.
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 =)
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.
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.
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).
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.
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).
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.
An interesting and succinct book which focuses on generics and collections, clearing many things regarding them. Probably a second read would be needed.